Skip to content

Commit

Permalink
WIP: mariadb-async
Browse files Browse the repository at this point in the history
  • Loading branch information
lpereira committed Sep 5, 2024
1 parent c8cb993 commit 278a624
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/samples/techempower/database.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,33 @@ static bool db_stmt_step_mysql(const struct db_stmt *stmt,
if (stmt_mysql->must_execute_again) {
stmt_mysql->must_execute_again = false;
stmt_mysql->results_are_bound = false;
if (mysql_stmt_execute(stmt_mysql->stmt))
return false;

int status;

mysql_stmt_execute_start(&status, stmt_mysql->stmt);
while (status) {
int wait_status = 0;

switch (status) {
case MYSQL_WAIT_READ:
lwan_request_await_read(stmt_mysql->ctx, stmt_mysql->db_fd);
wait_status = MYSQL_WAIT_READ;
break;
case MYSQL_WAIT_WRITE:
lwan_request_await_write(stmt_mysql->ctx, stmt_mysql->db_fd);
wait_status = MYSQL_WAIT_WRITE;
break;
case MYSQL_WAIT_READ|MYSQL_WAIT_WRITE:
lwan_request_await_read_write(stmt_mysql->ctx, stmt_mysql->db_fd);
wait_status = MYSQL_WAIT_READ|MYSQL_WAIT_WRITE;
break;
case MYSQL_WAIT_TIMEOUT:
case MYSQL_WAIT_EXCEPT:
/* TODO */
}

status = mysql_stmt_execute_cont(&status, stmt_mysql->stmt, wait_status);
}
}

if (!stmt_mysql->results_are_bound) {
Expand Down Expand Up @@ -231,6 +256,11 @@ struct db *db_connect_mysql(const char *host,
if (mysql_set_character_set(db_mysql->con, "utf8"))
goto error;

if (mysql_optionsv(db_mysql->con, MYSQL_OPT_NONBLOCK, 0)) {
lwan_status_error("Could not enable non-blocking mode");
goto error;
}

db_mysql->base.disconnect = db_disconnect_mysql;
db_mysql->base.prepare = db_prepare_mysql;

Expand Down

0 comments on commit 278a624

Please sign in to comment.