summaryrefslogtreecommitdiff
path: root/client/async_example.c
diff options
context:
space:
mode:
authorunknown <knielsen@knielsen-hq.org>2012-01-06 12:43:18 +0100
committerunknown <knielsen@knielsen-hq.org>2012-01-06 12:43:18 +0100
commit17940b652d0a078f5a28b089aa0f5362756d438e (patch)
tree0c198251f33fd1b19ae2bb443a732496a3bf5ee3 /client/async_example.c
parenta5b881594da4258257b18cc42f5ce7be3524e02c (diff)
downloadmariadb-git-17940b652d0a078f5a28b089aa0f5362756d438e.tar.gz
MWL#192: non-blocking client API, after-review fixes.
Main change is that non-blocking operation is now an option that must be explicitly enabled with mysql_option(mysql, MYSQL_OPT_NONBLOCK, ...) before any non-blocing operation can be used. Also the CLIENT_REMEMBER_OPTIONS flag is now always enabled and thus effectively ignored (it was not really useful anyway, and this simplifies things when non-blocking mysql_real_connect() fails).
Diffstat (limited to 'client/async_example.c')
-rw-r--r--client/async_example.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/client/async_example.c b/client/async_example.c
index de9d455171c..ccb60950904 100644
--- a/client/async_example.c
+++ b/client/async_example.c
@@ -1,17 +1,15 @@
/*
Copyright 2011 Kristian Nielsen and Monty Program Ab.
- Experiments with non-blocking libmysql.
+ This file is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
- This is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 2 of the License, or
- (at your option) any later version.
-
- This is distributed in the hope that it will be useful,
+ This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
You should have received a copy of the GNU General Public License
along with this. If not, see <http://www.gnu.org/licenses/>.
@@ -133,6 +131,7 @@ doit(const char *host, const char *user, const char *password)
int status;
mysql_init(&mysql);
+ mysql_options(&mysql, MYSQL_OPT_NONBLOCK, 0);
mysql_options(&mysql, MYSQL_READ_DEFAULT_GROUP, "myapp");
/* Returns 0 when done, else flag for what to wait for when need to block. */
@@ -177,8 +176,18 @@ doit(const char *host, const char *user, const char *password)
fatal(&mysql, "Got error while retrieving rows");
mysql_free_result(res);
- /* I suppose this must be non-blocking too. */
- mysql_close(&mysql);
+ /*
+ mysql_close() sends a COM_QUIT packet, and so in principle could block
+ waiting for the socket to accept the data.
+ In practise, for many applications it will probably be fine to use the
+ blocking mysql_close().
+ */
+ status= mysql_close_start(&mysql);
+ while (status)
+ {
+ status= wait_for_mysql(&mysql, status);
+ status= mysql_close_cont(&mysql, status);
+ }
}
int