Non-blocking API Reference
Here is a list of all functions in the non-blocking client API and their parameters. Apart from operating in a non-blocking way, they all work exactly the same as their blocking counterparts, so their exact semantics can be obtained from the documentation of the normal client API.
The API also contains the following three functions which are used to get the
socket fd and timeout values when waiting for events to occur:
my_socket mysql_get_socket(const MYSQL *mysql)Return the descriptor of the socket used for the connection.
unsigned int STDCALL mysql_get_timeout_value(const MYSQL *mysql)This should only be called when a _start() or _cont() function
returns a value with the MYSQL_WAIT_TIMEOUT flag set. In this case, it
returns the value, in seconds, after which a timeout has occured and the
application should call the appropriate _cont() function passingMYSQL_WAIT_TIMEOUT as the event that occured.
This is used to handle connection and read timeouts.
unsigned int STDCALL mysql_get_timeout_value_ms(const MYSQL *mysql)This function is available starting from MariaDB 5.5.28 and MariaDB 10.0.0.
Like mysql_get_timeout_value(), this should only be called when a _start() or _cont() function returns a value with the MYSQL_WAIT_TIMEOUT flag set. In this case, it returns the value, in millisecondsseconds, after which a timeout has occured and the application should call the appropriate _cont() function passing MYSQL_WAIT_TIMEOUT as the event that occured.
The difference to mysql_get_timeout_value() is that this provides millisecond resolution for timeouts, rather than just whole seconds. In MariaDB 10.0, internal timeouts can now be in milliseconds, while in 5.5 and below it was only whole seconds.
This milliseconds version is provided also in MariaDB 5.5 (from 5.5.28 onwards) to make it easier for applications to work with either library version. However, in 5.5 it always returns a multiple of 1000 milliseconds.
At the end is a list of all functions from the normal API which can be used safely in a non-blocking program, since they never need to block.
int mysql_real_connect_start(MYSQL **ret, MYSQL *mysql, const char *host,
const char *user, const char *passwd, const char *db,
unsigned int port, const char *unix_socket,
unsigned long client_flags)int mysql_real_connect_cont(MYSQL **ret, MYSQL *mysql, int ready_status)mysql_real_connect_start() initiates a non-blocking connection request to
a server.
When mysql_real_connect_start() or mysql_real_connect_cont() returns
zero, a copy of the passed 'mysql' argument is stored in *ret.
Initiate fetch of another row from a SELECT query.
If the MYSQL_RES was obtained from mysql_use_result(), then this
function allows stream processing, where initial rows are returned to the
application while the server is still sending subsequent rows. When no more
data is available on the socket, mysql_fetch_row_start() ormysql_fetch_row_cont() will return MYSQL_WAIT_READ (or possiblyMYSQL_WAIT_WRITE if using TLS and TLS re-negotiation is needed; alsoMYSQL_WAIT_TIMEOUT may be set if read timeout is enabled). When data
becomes available, more rows can be fetched with mysql_fetch_row_cont().
If the MYSQL_RES was obtained from mysql_store_result() /mysql_store_result_start() / mysql_store_result_cont(), then this
function cannot block — mysql_fetch_row_start()
will always return 0 (and if desired, plain mysql_fetch_row() may be used
instead with equivalent effect).
This function can need to wait if not all rows were fetched before it was called (then it needs to consume any pending rows sent from the server so they do not interfere with any subsequent queries sent).
If all rows were already fetched, then this function will not need to wait.mysql_free_result_start() will return zero (or if so desired, plainmysql_free_result() may be used instead).
Note that mysql_free_result() returns no value, so there is no extra
'ret' parameter for mysql_free_result_start() ormysql_free_result_cont().
mysql_close() sends a COM_QUIT request to the server, though it does
not wait for any reply.
Thus teoretically it can block (if the socket buffer is full), though in practise it is probably unlikely to occur frequently.
The non-blocking version of mysql_close() is provided for completeness;
for many applications using the normal mysql_close() is probably
sufficient (and may be simpler).
Note that mysql_close() returns no value, so there is no extra 'ret'
parameter for mysql_close_start() or mysql_close_cont().
Client API functions which never block
The following client API functions never need to do I/O and thus can never
block. Therefore, they can be used as normal in programs using non-blocking
operations; no need to call any special _start() variant. (Even if a_start() variant was available, it would always return zero, so no_cont() call would ever be needed).
mysql_eof()``
mysql_set_local_infile_handler()
mysql_set_local_infile_default()
mysql_get_server_name()
myodbc_remove_escape()
mysql_thread_safe()
mysql_embedded()
mariadb_connection()
mysql_get_socket()
mysql_get_timeout_value
mysql_get_timeout_value_ms
This page is licensed: CC BY-SA / Gnu FDL
Last updated
Was this helpful?

