Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Experiments with using C-level co-routines for implementing a non-blocking API on top of libmysqlclient
C
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
.gitignore
COPYING
Makefile
README
async-example1.c
my_context.c
my_context.h
my_context_amd64_gcc.c
mysql_async.c
swapcontext-example.c
sync-example1.c

README

Experiments with using C-level co-routines (like Posix swapcontext()) to get
non-blocking operation from libmysqlclient.

-----------------------------------------------------------------------

Here is a small example of suggested non-blocking API:


    static void
    wait_for_mysql(MYSQL *mysql, int status)
    {
      struct pollfd pfd;
      p.fd= mysql_get_socket_fd(&mysql);
      p.events=
	(status & MYSQL_WAIT_READ ? POLLIN : 0) |
	(status & MYSQL_WAIT_WRITE ? POLLOUT : 0);
      poll(&pfd, 1, 0);
    }


    status= mysql_real_connect_start(&ret, &mysql, "localhost", "test", "testpass", "test",
				     0, NULL, 0);
    while (status)
    {
      wait_for_mysql(&mysql, status);
      status= mysql_real_connect_cont(&ret, &mysql);
    }


    status= mysql_real_query_start(&err, &mysql, SL("SHOW STATUS"));
    while (status)
    {
      wait_for_mysql(&mysql, status);
      status= mysql_real_query_cont(&err, &mysql);
    }


    status= mysql_fetch_row_start(&row, res);
    while (status)
    {
      wait_for_mysql(&mysql, status);
      status= mysql_fetch_row_cont(&row, res);
    }


Idea is that if a call R=foo(...) can block, we introduce two more calls

    S=foo_start(&R, ...)
    S=foo_cont(&R, ...)


S (status) returns 0 is the call is done; then R is set to the return value
from the non-blocking call. When S returns non-zero, then the call is blocking
on some condition; individual bits in S say what we are waiting for,
eg. MYSQL_WAIT_READ or MYSQL_WAIT_WRITE.
Something went wrong with that request. Please try again.