summaryrefslogtreecommitdiff
path: root/tests
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 /tests
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 'tests')
-rw-r--r--tests/async_queries.c29
-rw-r--r--tests/mysql_client_test.c2
-rw-r--r--tests/nonblock-wrappers.h24
3 files changed, 29 insertions, 26 deletions
diff --git a/tests/async_queries.c b/tests/async_queries.c
index 677208f11f5..0f9b39e1938 100644
--- a/tests/async_queries.c
+++ b/tests/async_queries.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/>.
@@ -93,7 +91,7 @@ static struct my_option options[] =
&opt_user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"connections", 'n', "Number of simultaneous connections/queries.",
&opt_connections, &opt_connections, 0, GET_UINT, REQUIRED_ARG,
- 0, 0, 0, 0, 0, 0},
+ 5, 0, 0, 0, 0, 0},
{"queryfile", 'q', "Name of file containing extra queries to run",
&opt_query_file, &opt_query_file, 0, GET_STR, REQUIRED_ARG,
0, 0, 0, 0, 0, 0},
@@ -219,8 +217,8 @@ again:
break;
case 20:
- free(sd->query_element->query);
- free(sd->query_element);
+ my_free(sd->query_element->query, MYF(0));
+ my_free(sd->query_element, MYF(0));
if (sd->err)
{
printf("%d | Error: %s\n", sd->index, mysql_error(&sd->mysql));
@@ -315,8 +313,8 @@ add_query(const char *q)
char *q2;
size_t len;
- e= malloc(sizeof(*e));
- q2= strdup(q);
+ e= my_malloc(sizeof(*e), MYF(0));
+ q2= my_strdup(q, MYF(0));
if (!e || !q2)
fatal(NULL, "Out of memory");
@@ -395,7 +393,7 @@ main(int argc, char *argv[])
add_query(*argv++);
}
- sds= malloc(opt_connections * sizeof(*sds));
+ sds= my_malloc(opt_connections * sizeof(*sds), MYF(0));
if (!sds)
fatal(NULL, "Out of memory");
@@ -412,6 +410,7 @@ main(int argc, char *argv[])
for (i= 0; i < opt_connections; i++)
{
mysql_init(&sds[i].mysql);
+ mysql_options(&sds[i].mysql, MYSQL_OPT_NONBLOCK, 0);
mysql_options(&sds[i].mysql, MYSQL_READ_DEFAULT_GROUP, "async_queries");
/*
diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c
index 1ca70fd972a..8ceeaf57399 100644
--- a/tests/mysql_client_test.c
+++ b/tests/mysql_client_test.c
@@ -260,6 +260,8 @@ static MYSQL *mysql_client_init(MYSQL* con)
if (res && shared_memory_base_name)
mysql_options(res, MYSQL_SHARED_MEMORY_BASE_NAME, shared_memory_base_name);
#endif
+ if (res && non_blocking_api_enabled)
+ mysql_options(res, MYSQL_OPT_NONBLOCK, 0);
return res;
}
diff --git a/tests/nonblock-wrappers.h b/tests/nonblock-wrappers.h
index a7346ba641c..3ed470b3400 100644
--- a/tests/nonblock-wrappers.h
+++ b/tests/nonblock-wrappers.h
@@ -1,17 +1,19 @@
-/* Copyright (c) 2011 Monty Program Ab
+/*
+ Copyright 2011 Kristian Nielsen and Monty Program Ab
- This program 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; version 2 of the License.
+ 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 program 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.
+ 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
+ Lesser General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+ You should have received a copy of the GNU General Public License
+ along with this. If not, see <http://www.gnu.org/licenses/>.
+*/
/*
Wrappers that re-implement the normal blocking libmysql API calls in terms