Commit 17940b65 authored by unknown's avatar unknown

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).
parent a5b88159
This diff is collapsed.
......@@ -21,7 +21,7 @@ AUTOMAKE_OPTIONS = foreign
# These are built from source in the Docs directory
EXTRA_DIST = INSTALL-SOURCE INSTALL-WIN-SOURCE \
README COPYING EXCEPTIONS-CLIENT \
CMakeLists.txt \
CMakeLists.txt COPYING.LESSER \
config/ac-macros/libevent_configure.m4
SUBDIRS = . include @docs_dirs@ @zlib_dir@ \
@readline_topdir@ sql-common scripts \
......
/*
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
......
......@@ -5368,6 +5368,7 @@ void do_connect(struct st_command *command)
#endif
if (!(con_slot->mysql= mysql_init(0)))
die("Failed on mysql_init()");
mysql_options(con_slot->mysql, MYSQL_OPT_NONBLOCK, 0);
if (opt_compress || con_compress)
mysql_options(con_slot->mysql, MYSQL_OPT_COMPRESS, NullS);
mysql_options(con_slot->mysql, MYSQL_OPT_LOCAL_INFILE, 0);
......@@ -7491,6 +7492,7 @@ int util_query(MYSQL* org_mysql, const char* query){
/* enable local infile, in non-binary builds often disabled by default */
mysql_options(mysql, MYSQL_OPT_LOCAL_INFILE, 0);
mysql_options(mysql, MYSQL_OPT_NONBLOCK, 0);
safe_connect(mysql, "util", org_mysql->host, org_mysql->user,
org_mysql->passwd, org_mysql->db, org_mysql->port,
org_mysql->unix_socket);
......@@ -8226,6 +8228,7 @@ int main(int argc, char **argv)
if (!(con->name = my_strdup("default", MYF(MY_WME))))
die("Out of memory");
mysql_options(con->mysql, MYSQL_OPT_NONBLOCK, 0);
safe_connect(con->mysql, con->name, opt_host, opt_user, opt_pass,
opt_db, opt_port, unix_sock);
......
......@@ -46,7 +46,7 @@ noinst_HEADERS = config-win.h config-netware.h lf.h my_bit.h \
atomic/rwlock.h atomic/x86-gcc.h \
atomic/generic-msvc.h \
atomic/gcc_builtins.h my_libwrap.h my_stacktrace.h \
wqueue.h waiting_threads.h my_context.h
wqueue.h waiting_threads.h my_context.h mysql_async.h
EXTRA_DIST = mysql.h.pp mysql/plugin_auth.h.pp mysql/client_plugin.h.pp CMakeLists.txt
......
/*
Copyright 2011 Kristian Nielsen
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/>.
......@@ -164,11 +162,14 @@ struct mysql_async_context {
/*
This is set to the value that should be returned from foo_start() or
foo_cont() when a call is suspended.
*/
unsigned int events_to_wait_for;
/*
It is also set to the event(s) that triggered when a suspended call is
resumed, eg. whether we woke up due to connection completed or timeout
in mysql_real_connect_cont().
*/
unsigned int ret_status;
unsigned int events_occured;
/*
This is set to the result of the whole asynchronous operation when it
completes. It uses a union, as different calls have different return
......
......@@ -134,6 +134,8 @@ extern void dbug_free_code_state(void **code_state_store);
#define DEBUGGER_OFF do { _dbug_on_= 0; } while(0)
#define DEBUGGER_ON do { _dbug_on_= 1; } while(0)
#define IF_DBUG(A) A
#define DBUG_SWAP_CODE_STATE(arg) dbug_swap_code_state(arg)
#define DBUG_FREE_CODE_STATE(arg) dbug_free_code_state(arg)
#ifndef __WIN__
#define DBUG_ABORT() (_db_flush_(), abort())
#else
......@@ -193,6 +195,8 @@ extern void _db_suicide_();
#define DEBUGGER_OFF do { } while(0)
#define DEBUGGER_ON do { } while(0)
#define IF_DBUG(A)
#define DBUG_SWAP_CODE_STATE(arg) do { } while(0)
#define DBUG_FREE_CODE_STATE(arg) do { } while(0)
#define DBUG_ABORT() do { } while(0)
#define DBUG_SUICIDE() do { } while(0)
......
......@@ -169,7 +169,9 @@ enum mysql_option
MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION,
MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH,
MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT,
MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH
MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH,
/* MariaDB options */
MYSQL_OPT_NONBLOCK=6000
};
/**
......@@ -264,8 +266,6 @@ typedef struct character_set
struct st_mysql_methods;
struct st_mysql_stmt;
struct st_mysql_extension;
typedef struct st_mysql
{
NET net; /* Communication parameters */
......@@ -320,7 +320,7 @@ typedef struct st_mysql
my_bool *unbuffered_fetch_owner;
/* needed for embedded server - no net buffer to store the 'info' */
char *info_buffer;
struct st_mysql_extension *extension;
void *extension;
} MYSQL;
......@@ -382,14 +382,21 @@ typedef struct st_mysql_parameters
Flag bits, the asynchronous methods return a combination of these ORed
together to let the application know when to resume the suspended operation.
*/
typedef enum {
MYSQL_WAIT_READ= 1, /* Wait for data to be available on socket to read */
/* mysql_get_socket_fd() will return socket descriptor*/
MYSQL_WAIT_WRITE= 2, /* Wait for socket to be ready to write data */
MYSQL_WAIT_EXCEPT= 4, /* Wait for select() to mark exception on socket */
MYSQL_WAIT_TIMEOUT= 8 /* Wait until timeout occurs. Value of timeout can be */
/* obtained from mysql_get_timeout_value() */
} MYSQL_ASYNC_STATUS;
/*
Wait for data to be available on socket to read.
mysql_get_socket_fd() will return socket descriptor.
*/
#define MYSQL_WAIT_READ 1
/* Wait for socket to be ready to write data. */
#define MYSQL_WAIT_WRITE 2
/* Wait for select() to mark exception on socket. */
#define MYSQL_WAIT_EXCEPT 4
/*
Wait until timeout occurs. Value of timeout can be obtained from
mysql_get_timeout_value().
*/
#define MYSQL_WAIT_TIMEOUT 8
#if !defined(MYSQL_SERVER) && !defined(EMBEDDED_LIBRARY)
#define max_allowed_packet (*mysql_get_parameters()->p_max_allowed_packet)
......@@ -943,6 +950,7 @@ my_bool STDCALL mysql_more_results(MYSQL *mysql);
int STDCALL mysql_next_result(MYSQL *mysql);
int STDCALL mysql_next_result_start(int *ret, MYSQL *mysql);
int STDCALL mysql_next_result_cont(int *ret, MYSQL *mysql, int status);
void STDCALL mysql_close_slow_part(MYSQL *mysql);
void STDCALL mysql_close(MYSQL *sock);
int STDCALL mysql_close_start(MYSQL *sock);
int STDCALL mysql_close_cont(MYSQL *sock, int status);
......@@ -958,20 +966,7 @@ unsigned int STDCALL mysql_get_timeout_value(const MYSQL *mysql);
#ifdef USE_OLD_FUNCTIONS
MYSQL * STDCALL mysql_connect(MYSQL *mysql, const char *host,
const char *user, const char *passwd);
int STDCALL mysql_connect_start(MYSQL **ret, MYSQL *mysql,
const char *host, const char *user,
const char *passwd);
int STDCALL mysql_connect_cont(MYSQL **ret, MYSQL *mysql,
int status);
int STDCALL mysql_create_db(MYSQL *mysql, const char *DB);
int STDCALL mysql_create_db_start(int *ret, MYSQL *mysql,
const char *DB);
int STDCALL mysql_create_db_cont(int *ret, MYSQL *mysql,
int status);
int STDCALL mysql_drop_db(MYSQL *mysql, const char *DB);
int STDCALL mysql_drop_db_start(int *ret, MYSQL *mysql,
const char *DB);
int STDCALL mysql_drop_db_cont(int *ret, MYSQL *mysql, int status);
int STDCALL mysql_drop_db(MYSQL *mysql, const char *DB);
#define mysql_reload(mysql) mysql_refresh((mysql),REFRESH_GRANT)
#endif
......
......@@ -257,7 +257,8 @@ enum mysql_option
MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION,
MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH,
MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT,
MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH
MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH,
MYSQL_OPT_NONBLOCK=6000
};
struct st_mysql_options_extention;
struct st_mysql_options {
......@@ -318,7 +319,6 @@ typedef struct character_set
} MY_CHARSET_INFO;
struct st_mysql_methods;
struct st_mysql_stmt;
struct st_mysql_extension;
typedef struct st_mysql
{
NET net;
......@@ -354,7 +354,7 @@ typedef struct st_mysql
void *thd;
my_bool *unbuffered_fetch_owner;
char *info_buffer;
struct st_mysql_extension *extension;
void *extension;
} MYSQL;
typedef struct st_mysql_res {
my_ulonglong row_count;
......@@ -392,12 +392,6 @@ typedef struct st_mysql_parameters
unsigned long *p_net_buffer_length;
void *extension;
} MYSQL_PARAMETERS;
typedef enum {
MYSQL_WAIT_READ= 1,
MYSQL_WAIT_WRITE= 2,
MYSQL_WAIT_EXCEPT= 4,
MYSQL_WAIT_TIMEOUT= 8
} MYSQL_ASYNC_STATUS;
int mysql_server_init(int argc, char **argv, char **groups);
void mysql_server_end(void);
MYSQL_PARAMETERS * mysql_get_parameters(void);
......@@ -776,6 +770,7 @@ my_bool mysql_more_results(MYSQL *mysql);
int mysql_next_result(MYSQL *mysql);
int mysql_next_result_start(int *ret, MYSQL *mysql);
int mysql_next_result_cont(int *ret, MYSQL *mysql, int status);
void mysql_close_slow_part(MYSQL *mysql);
void mysql_close(MYSQL *sock);
int mysql_close_start(MYSQL *sock);
int mysql_close_cont(MYSQL *sock, int status);
......
/* Copyright (C) 2012 MariaDB Services and Kristian Nielsen
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 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.
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 */
/* Common definitions for MariaDB non-blocking client library. */
#ifndef MYSQL_ASYNC_H
#define MYSQL_ASYNC_H
extern int my_connect_async(struct mysql_async_context *b, my_socket fd,
const struct sockaddr *name, uint namelen,
uint timeout);
extern ssize_t my_recv_async(struct mysql_async_context *b, int fd,
unsigned char *buf, size_t size, uint timeout);
extern ssize_t my_send_async(struct mysql_async_context *b, int fd,
const unsigned char *buf, size_t size,
uint timeout);
extern my_bool my_poll_read_async(struct mysql_async_context *b,
uint timeout);
extern int my_ssl_read_async(struct mysql_async_context *b, SSL *ssl,
void *buf, int size);
extern int my_ssl_write_async(struct mysql_async_context *b, SSL *ssl,
const void *buf, int size);
#endif /* MYSQL_ASYNC_H */
......@@ -159,6 +159,15 @@ enum enum_server_command
#define CLIENT_PLUGIN_AUTH (1UL << 19) /* Client supports plugin authentication */
#define CLIENT_SSL_VERIFY_SERVER_CERT (1UL << 30)
/*
It used to be that if mysql_real_connect() failed, it would delete any
options set by the client, unless the CLIENT_REMEMBER_OPTIONS flag was
given.
That behaviour does not appear very useful, and it seems unlikely that
any applications would actually depend on this. So from MariaDB 5.5 we
always preserve any options set in case of failed connect, and this
option is effectively always set.
*/
#define CLIENT_REMEMBER_OPTIONS (1UL << 31)
#ifdef HAVE_COMPRESS
......
......@@ -32,9 +32,6 @@ struct mysql_async_context;
struct st_mysql_options_extention {
char *plugin_dir;
char *default_auth;
};
struct st_mysql_extension {
struct mysql_async_context *async_context;
};
......
drop table if exists t1;
CREATE TABLE t1 (a INT PRIMARY KEY);
INSERT INTO t1 VALUES (1);
SELECT * FROM t1;
......
# This runs the mysql_client_test using the non-blocking API.
# This test should work in embedded server after we fix mysqltest
# The non-blocking API is not supported in the embedded server.
-- source include/not_embedded.inc
SET @old_general_log= @@global.general_log;
......
# Test mixing the use of blocking and non-blocking API in a single connection.
--disable_warnings
drop table if exists t1;
--enable_warnings
--enable_non_blocking_api
connect (con_nonblock,localhost,root,,test);
--disable_non_blocking_api
......
/*
Copyright 2011 Kristian Nielsen
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/>.
......@@ -22,10 +20,8 @@
swapcontext().
*/
#include <stdio.h>
#include <errno.h>
#include "mysys_priv.h"
#include "m_string.h"
#include "my_context.h"
#ifdef HAVE_VALGRIND_VALGRIND_H
......@@ -77,13 +73,9 @@ my_context_continue(struct my_context *c)
if (!c->active)
return 0;
#ifndef DBUG_OFF
dbug_swap_code_state(&c->dbug_state);
#endif
DBUG_SWAP_CODE_STATE(&c->dbug_state);
err= swapcontext(&c->base_context, &c->spawned_context);
#ifndef DBUG_OFF
dbug_swap_code_state(&c->dbug_state);
#endif
DBUG_SWAP_CODE_STATE(&c->dbug_state);
if (err)
{
fprintf(stderr, "Aieie, swapcontext() failed: %d (errno=%d)\n",
......@@ -135,21 +127,16 @@ my_context_yield(struct my_context *c)
int
my_context_init(struct my_context *c, size_t stack_size)
{
if (2*sizeof(int) < sizeof(void *))
{
fprintf(stderr,
"Error: Unable to store pointer in 2 ints on this architecture\n");
return -1;
}
#if SIZEOF_CHARP > SIZEOF_INT*2
#error Error: Unable to store pointer in 2 ints on this architecture
#endif
bzero(c, sizeof(*c))
if (!(c->stack= malloc(stack_size)))
return -1; /* Out of memory */
c->stack_size= stack_size;
#ifdef HAVE_VALGRIND_VALGRIND_H
c->valgrind_stack_id=
VALGRIND_STACK_REGISTER(c->stack, ((unsigned char *)(c->stack))+stack_size);
#endif
#ifndef DBUG_OFF
c->dbug_state= NULL;
#endif
return 0;
}
......@@ -164,9 +151,7 @@ my_context_destroy(struct my_context *c)
#endif
free(c->stack);
}
#ifndef DBUG_OFF
dbug_free_code_state(&c->dbug_state);
#endif
DBUG_FREE_CODE_STATE(&c->dbug_state);
}
#endif /* MY_CONTEXT_USE_UCONTEXT */
......@@ -206,9 +191,7 @@ my_context_spawn(struct my_context *c, void (*f)(void *), void *d)
{
int ret;
#ifndef DBUG_OFF
dbug_swap_code_state(&c->dbug_state);
#endif
DBUG_SWAP_CODE_STATE(&c->dbug_state);
/*
There are 6 callee-save registers we need to save and restore when
......@@ -262,9 +245,7 @@ my_context_spawn(struct my_context *c, void (*f)(void *), void *d)
: "rcx", "rdx", "r8", "r9", "r10", "r11", "memory", "cc"
);
#ifndef DBUG_OFF
dbug_swap_code_state(&c->dbug_state);
#endif
DBUG_SWAP_CODE_STATE(&c->dbug_state);
return ret;
}
......@@ -274,9 +255,7 @@ my_context_continue(struct my_context *c)
{
int ret;
#ifndef DBUG_OFF
dbug_swap_code_state(&c->dbug_state);
#endif
DBUG_SWAP_CODE_STATE(&c->dbug_state);
__asm__ __volatile__
(
......@@ -335,9 +314,7 @@ my_context_continue(struct my_context *c)
: "rcx", "rdx", "rsi", "rdi", "r8", "r9", "r10", "r11", "memory", "cc"
);
#ifndef DBUG_OFF
dbug_swap_code_state(&c->dbug_state);
#endif
DBUG_SWAP_CODE_STATE(&c->dbug_state);
return ret;
}
......@@ -386,15 +363,13 @@ my_context_yield(struct my_context *c)
int
my_context_init(struct my_context *c, size_t stack_size)
{
bzero(c, sizeof(*c));
if (!(c->stack_bot= malloc(stack_size)))
return -1; /* Out of memory */
c->stack_top= ((unsigned char *)(c->stack_bot)) + stack_size;
#ifdef HAVE_VALGRIND_VALGRIND_H
c->valgrind_stack_id=
VALGRIND_STACK_REGISTER(c->stack_bot, c->stack_top);
#endif
#ifndef DBUG_OFF
c->dbug_state= NULL;
#endif
return 0;
}
......@@ -409,9 +384,7 @@ my_context_destroy(struct my_context *c)
VALGRIND_STACK_DEREGISTER(c->valgrind_stack_id);
#endif
}
#ifndef DBUG_OFF
dbug_free_code_state(&c->dbug_state);
#endif
DBUG_FREE_CODE_STATE(&c->dbug_state);
}
#endif /* MY_CONTEXT_USE_X86_64_GCC_ASM */
......@@ -449,9 +422,7 @@ my_context_spawn(struct my_context *c, void (*f)(void *), void *d)
{
int ret;
#ifndef DBUG_OFF
dbug_swap_code_state(&c->dbug_state);
#endif
DBUG_SWAP_CODE_STATE(&c->dbug_state);
/*
There are 4 callee-save registers we need to save and restore when
......@@ -504,9 +475,7 @@ my_context_spawn(struct my_context *c, void (*f)(void *), void *d)
: "ecx", "edx", "memory", "cc"
);
#ifndef DBUG_OFF
dbug_swap_code_state(&c->dbug_state);
#endif
DBUG_SWAP_CODE_STATE(&c->dbug_state);
return ret;
}
......@@ -516,9 +485,7 @@ my_context_continue(struct my_context *c)
{
int ret;
#ifndef DBUG_OFF
dbug_swap_code_state(&c->dbug_state);
#endif
DBUG_SWAP_CODE_STATE(&c->dbug_state);
__asm__ __volatile__
(
......@@ -573,9 +540,7 @@ my_context_continue(struct my_context *c)
: "ecx", "edx", "memory", "cc"
);
#ifndef DBUG_OFF
dbug_swap_code_state(&c->dbug_state);
#endif
DBUG_SWAP_CODE_STATE(&c->dbug_state);
return ret;
}
......@@ -622,15 +587,13 @@ my_context_yield(struct my_context *c)
int
my_context_init(struct my_context *c, size_t stack_size)
{
bzero(c, sizeof(*c));
if (!(c->stack_bot= malloc(stack_size)))
return -1; /* Out of memory */
c->stack_top= ((unsigned char *)(c->stack_bot)) + stack_size;
#ifdef HAVE_VALGRIND_VALGRIND_H
c->valgrind_stack_id=
VALGRIND_STACK_REGISTER(c->stack_bot, c->stack_top);
#endif
#ifndef DBUG_OFF
c->dbug_state= NULL;
#endif
return 0;
}
......@@ -645,9 +608,7 @@ my_context_destroy(struct my_context *c)
VALGRIND_STACK_DEREGISTER(c->valgrind_stack_id);
#endif
}
#ifndef DBUG_OFF
dbug_free_code_state(&c->dbug_state);
#endif
DBUG_FREE_CODE_STATE(&c->dbug_state);
}
#endif /* MY_CONTEXT_USE_I386_GCC_ASM */
......@@ -685,22 +646,17 @@ my_context_trampoline(void *p)
int
my_context_init(struct my_context *c, size_t stack_size)
{
#ifndef DBUG_OFF
c->dbug_state= NULL;
#endif
bzero(c, sizeof(*c));
c->lib_fiber= CreateFiber(stack_size, my_context_trampoline, c);
if (c->lib_fiber)
return 0;
else
return -1;
return -1;
}
void
my_context_destroy(struct my_context *c)
{
#ifndef DBUG_OFF
dbug_free_code_state(&c->dbug_state);
#endif
DBUG_FREE_CODE_STATE(&c->dbug_state);
if (c->lib_fiber)
{
DeleteFiber(c->lib_fiber);
......@@ -723,26 +679,18 @@ my_context_spawn(struct my_context *c, void (*f)(void *), void *d)
if (current_fiber == NULL || current_fiber == (void *)0x1e00)
current_fiber= ConvertThreadToFiber(c);
c->app_fiber= current_fiber;
#ifndef DBUG_OFF
dbug_swap_code_state(&c->dbug_state);
#endif
DBUG_SWAP_CODE_STATE(&c->dbug_state);
SwitchToFiber(c->lib_fiber);
#ifndef DBUG_OFF
dbug_swap_code_state(&c->dbug_state);
#endif
DBUG_SWAP_CODE_STATE(&c->dbug_state);
return c->return_value;
}
int
my_context_continue(struct my_context *c)
{
#ifndef DBUG_OFF
dbug_swap_code_state(&c->dbug_state);
#endif
DBUG_SWAP_CODE_STATE(&c->dbug_state);
SwitchToFiber(c->lib_fiber);
#ifndef DBUG_OFF
dbug_swap_code_state(&c->dbug_state);
#endif
DBUG_SWAP_CODE_STATE(&c->dbug_state);
return c->return_value;
}
......
This diff is collapsed.
This diff is collapsed.
/*
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");
/*
......
......@@ -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;
}
......
/* 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
......
......@@ -22,6 +22,7 @@
#include "vio_priv.h"
#include "my_context.h"
#include <mysql_async.h>
int vio_errno(Vio *vio __attribute__((unused)))
{
......@@ -32,8 +33,6 @@ int vio_errno(Vio *vio __attribute__((unused)))
size_t vio_read(Vio * vio, uchar* buf, size_t size)
{
size_t r;
extern ssize_t my_recv_async(struct mysql_async_context *b, int fd,
unsigned char *buf, size_t size, uint timeout);
DBUG_ENTER("vio_read");
DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %u", vio->sd, (long) buf,
(uint) size));
......@@ -119,9 +118,6 @@ size_t vio_read_buff(Vio *vio, uchar* buf, size_t size)
size_t vio_write(Vio * vio, const uchar* buf, size_t size)
{
size_t r;
extern ssize_t my_send_async(struct mysql_async_context *b, int fd,
const unsigned char *buf, size_t size,
uint timeout);
DBUG_ENTER("vio_write");
DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %u", vio->sd, (long) buf,
(uint) size));
......@@ -394,8 +390,6 @@ void vio_in_addr(Vio *vio, struct in_addr *in)
my_bool vio_poll_read(Vio *vio,uint timeout)
{
extern my_bool my_poll_read_async(struct mysql_async_context *b,
uint timeout);
#ifndef HAVE_POLL
#if __WIN__
int res;
......
......@@ -22,6 +22,7 @@
#include "vio_priv.h"
#include "my_context.h"
#include <mysql_async.h>
#ifdef HAVE_OPENSSL
......@@ -91,8 +92,6 @@ report_errors(SSL* ssl)
size_t vio_ssl_read(Vio *vio, uchar* buf, size_t size)
{
size_t r;
extern int my_ssl_read_async(struct mysql_async_context *b, SSL *ssl,
void *buf, int size);
DBUG_ENTER("vio_ssl_read");
DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %u ssl: 0x%lx",
vio->sd, (long) buf, (uint) size, (long) vio->ssl_arg));
......@@ -113,8 +112,6 @@ size_t vio_ssl_read(Vio *vio, uchar* buf, size_t size)
size_t vio_ssl_write(Vio *vio, const uchar* buf, size_t size)
{
size_t r;
extern int my_ssl_write_async(struct mysql_async_context *b, SSL *ssl,
const void *buf, int size);
DBUG_ENTER("vio_ssl_write");
DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %u", vio->sd,
(long) buf, (uint) size));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment