Answer the question
In order to leave comments, you need to log in
How to properly build an Event-driven architecture on Libev to execute SQL queries (libmysqllient)?
According to the results of the topic habrahabr.ru/post/144918/ , which is a translation of "Async MySQL Queries with C-API" September 09, 2008 jan.kneschke.de/2008/9/9/async-mysql-queries-with-c- api/,
Actually, that post is a spherical horse in a vacuum ... since in real life, we do not need to immediately run several SQL queries in parallel from one point of the program.
Reality dictates to us that we need to use the possibility of asynchronous execution of them from different event handler loops, for example, when writing demons on libevent / libev.
So, closer to the body of the matter: there is a code for asynchronous execution of SQL queries on libev pastebin.ru/nzhiAsEw (working code, execution results habrahabr.ru/post/144918/#comment_5808481)
everything is simple and clear when executing a single request handler in the function:
- in the main event (in the example when the timer fires, in real life - processing an incoming connection) the sql_read_cb() handler function is defined
- When a certain event occurs, it is defined
- SQL processing callback sql_read_cb ( EV_P_ ev_io *w, int revents)
- the file descriptor on which the request will be made (in real life it will be taken from the descriptor queue pool)
- the request is executed on this file descriptor mysql_send_query();
— When a response is received from the MySQL server (EV_READ event), callback sql_read_cb() is executed, in which the SQL query handler sql_p1_cb (....) is defined, where the response is processed ... If this is a network connection, then the result may be sending data to the connection socket. In this example, just printf().
However, how to properly organize the architecture if we have to execute several sequential SQL queries in the event handler loop, and each subsequent query depends on the results of the previous one (or, for example, there may not be a query, since the data has already been received earlier) ...
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question