summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <monty@hundin.mysql.fi>2001-06-15 22:55:15 +0300
committerunknown <monty@hundin.mysql.fi>2001-06-15 22:55:15 +0300
commit01dc56a5447d8f21224304f8370aee6f41de6160 (patch)
tree45f8ed4becf9182cefb0e93436d666caf7d35184
parent8b96a960c3c122b0c80afbdb730b2ccd00b3a41a (diff)
downloadmariadb-git-01dc56a5447d8f21224304f8370aee6f41de6160.tar.gz
Fixed bug when using more than 1 connection
libmysqld/Makefile.am: Added missing files libmysqld/libmysqld.c: cleanup
-rw-r--r--libmysqld/Makefile.am4
-rw-r--r--libmysqld/lib_sql.cc8
-rw-r--r--libmysqld/libmysqld.c152
3 files changed, 16 insertions, 148 deletions
diff --git a/libmysqld/Makefile.am b/libmysqld/Makefile.am
index fe8bcb4c4e4..aa358958a1b 100644
--- a/libmysqld/Makefile.am
+++ b/libmysqld/Makefile.am
@@ -54,7 +54,7 @@ sqlsources = convert.cc derror.cc field.cc field_conv.cc filesort.cc \
sql_rename.cc sql_repl.cc sql_select.cc sql_show.cc \
sql_string.cc sql_table.cc sql_test.cc sql_udf.cc \
sql_update.cc sql_yacc.cc table.cc thr_malloc.cc time.cc \
- unireg.cc uniques.cc
+ unireg.cc uniques.cc stacktrace.c sql_unions.cc hash_filo.cc
## XXX: we should not have to duplicate info from the sources list
sqlobjects = convert.lo derror.lo field.lo field_conv.lo filesort.lo \
@@ -72,7 +72,7 @@ sqlobjects = convert.lo derror.lo field.lo field_conv.lo filesort.lo \
sql_rename.lo sql_repl.lo sql_select.lo sql_show.lo \
sql_string.lo sql_table.lo sql_test.lo sql_udf.lo \
sql_update.lo sql_yacc.lo table.lo thr_malloc.lo time.lo \
- unireg.lo uniques.lo
+ unireg.lo uniques.lo stacktrace.lo sql_unions.lo hash_filo.lo
EXTRA_DIST = lib_vio.c
diff --git a/libmysqld/lib_sql.cc b/libmysqld/lib_sql.cc
index ed04d85ee6e..323bf42cf92 100644
--- a/libmysqld/lib_sql.cc
+++ b/libmysqld/lib_sql.cc
@@ -72,8 +72,10 @@ get_mysql_real_data_home(){ return mysql_real_data_home;};
bool lib_dispatch_command(enum enum_server_command command, NET *net,
const char *arg, ulong length)
{
- net_new_transaction(&((THD *)net->vio->dest_thd)->net);
- return dispatch_command(command, (THD *)net->vio->dest_thd, (char *)arg, length + 1);
+ THD *thd=(THD *) net->vio->dest_thd;
+ thd->store_globals(); // Fix if more than one connect
+ net_new_transaction(&thd->net);
+ return dispatch_command(command, thd, (char *) arg, length + 1);
}
@@ -116,7 +118,7 @@ void start_embedded_conn1(NET * net)
thd->net.vio = v;
if (thd->store_globals())
{
- printf("store_globals failed.\n");
+ fprintf(stderr,"store_globals failed.\n");
return;
}
diff --git a/libmysqld/libmysqld.c b/libmysqld/libmysqld.c
index fe429c4d54d..216261e220d 100644
--- a/libmysqld/libmysqld.c
+++ b/libmysqld/libmysqld.c
@@ -100,109 +100,6 @@ static ulong mysql_sub_escape_string(CHARSET_INFO *charset_info, char *to,
#define set_sigpipe(mysql)
#define reset_sigpipe(mysql)
-#if 0
-/****************************************************************************
-* A modified version of connect(). connect2() allows you to specify
-* a timeout value, in seconds, that we should wait until we
-* derermine we can't connect to a particular host. If timeout is 0,
-* connect2() will behave exactly like connect().
-*
-* Base version coded by Steve Bernacki, Jr. <steve@navinet.net>
-*****************************************************************************/
-
-static int connect2(my_socket s, const struct sockaddr *name, uint namelen,
- uint to)
-{
-#if defined(__WIN__)
- return connect(s, (struct sockaddr*) name, namelen);
-#else
- int flags, res, s_err;
- size_socket s_err_size = sizeof(uint);
- fd_set sfds;
- struct timeval tv;
- time_t start_time, now_time;
-
- /* If they passed us a timeout of zero, we should behave
- * exactly like the normal connect() call does.
- */
-
- if (to == 0)
- return connect(s, (struct sockaddr*) name, namelen);
-
- flags = fcntl(s, F_GETFL, 0); /* Set socket to not block */
-#ifdef O_NONBLOCK
- fcntl(s, F_SETFL, flags | O_NONBLOCK); /* and save the flags.. */
-#endif
-
- res = connect(s, (struct sockaddr*) name, namelen);
- s_err = errno; /* Save the error... */
- fcntl(s, F_SETFL, flags);
- if ((res != 0) && (s_err != EINPROGRESS))
- {
- errno = s_err; /* Restore it */
- return(-1);
- }
- if (res == 0) /* Connected quickly! */
- return(0);
-
- /* Otherwise, our connection is "in progress." We can use
- * the select() call to wait up to a specified period of time
- * for the connection to suceed. If select() returns 0
- * (after waiting howevermany seconds), our socket never became
- * writable (host is probably unreachable.) Otherwise, if
- * select() returns 1, then one of two conditions exist:
- *
- * 1. An error occured. We use getsockopt() to check for this.
- * 2. The connection was set up sucessfully: getsockopt() will
- * return 0 as an error.
- *
- * Thanks goes to Andrew Gierth <andrew@erlenstar.demon.co.uk>
- * who posted this method of timing out a connect() in
- * comp.unix.programmer on August 15th, 1997.
- */
-
- FD_ZERO(&sfds);
- FD_SET(s, &sfds);
- /*
- * select could be interrupted by a signal, and if it is,
- * the timeout should be adjusted and the select restarted
- * to work around OSes that don't restart select and
- * implementations of select that don't adjust tv upon
- * failure to reflect the time remaining
- */
- start_time = time(NULL);
- for (;;)
- {
- tv.tv_sec = (long) to;
- tv.tv_usec = 0;
- if ((res = select(s+1, NULL, &sfds, NULL, &tv)) >= 0)
- break;
- now_time=time(NULL);
- to-= (uint) (now_time - start_time);
- if (errno != EINTR || (int) to <= 0)
- return -1;
- }
-
- /* select() returned something more interesting than zero, let's
- * see if we have any errors. If the next two statements pass,
- * we've got an open socket!
- */
-
- s_err=0;
- if (getsockopt(s, SOL_SOCKET, SO_ERROR, (char*) &s_err, &s_err_size) != 0)
- return(-1);
-
- if (s_err)
- { /* getsockopt() could suceed */
- errno = s_err;
- return(-1); /* but return an error... */
- }
- return(0); /* It's all good! */
-#endif
-}
-#endif /* 0 */
-
-
/*****************************************************************************
** read a packet from server. Give error message if socket was down
** or packet is an error message
@@ -343,25 +240,15 @@ simple_command(MYSQL *mysql,enum enum_server_command command, const char *arg,
{
NET *net= &mysql->net;
int result= -1;
- init_sigpipe_variables
- /* Don't give sigpipe errors if the client doesn't want them */
- set_sigpipe(mysql);
- if (mysql->net.vio == 0)
- { /* Do reconnect if possible */
- if (mysql_reconnect(mysql))
- {
- net->last_errno=CR_SERVER_GONE_ERROR;
- strmov(net->last_error,ER(net->last_errno));
- goto end;
- }
- }
+ /* Check that we are calling the client functions in right order */
if (mysql->status != MYSQL_STATUS_READY)
{
strmov(net->last_error,ER(mysql->net.last_errno=CR_COMMANDS_OUT_OF_SYNC));
goto end;
}
+ /* Clear result variables */
mysql->net.last_error[0]=0;
mysql->net.last_errno=0;
mysql->info=0;
@@ -371,32 +258,11 @@ simple_command(MYSQL *mysql,enum enum_server_command command, const char *arg,
net_clear(net);
vio_reset(net->vio);
- if (!arg)
- arg="";
-
- result = lib_dispatch_command(command, net, arg,
- length ? length : (ulong) strlen(arg));
-#if 0
- if (net_write_command(net,(uchar) command,arg,
- length ? length : (ulong) strlen(arg)))
- {
- DBUG_PRINT("error",("Can't send command to server. Error: %d",errno));
- end_server(mysql);
- if (mysql_reconnect(mysql) ||
- net_write_command(net,(uchar) command,arg,
- length ? length : (ulong) strlen(arg)))
- {
- net->last_errno=CR_SERVER_GONE_ERROR;
- strmov(net->last_error,ER(net->last_errno));
- goto end;
- }
- }
-#endif
+ result = lib_dispatch_command(command, net, arg,length);
if (!skipp_check)
result= ((mysql->packet_length=net_safe_read(mysql)) == packet_error ?
-1 : 0);
end:
- reset_sigpipe(mysql);
return result;
}
@@ -1280,7 +1146,7 @@ mysql_close(MYSQL *mysql)
{
free_old_query(mysql);
mysql->status=MYSQL_STATUS_READY; /* Force command */
- simple_command(mysql,COM_QUIT,NullS,0,1);
+ simple_command(mysql,COM_QUIT,"",0,1);
end_server(mysql);
}
my_free((gptr) mysql->host_info,MYF(MY_ALLOW_ZERO_PTR));
@@ -1756,7 +1622,7 @@ mysql_list_processes(MYSQL *mysql)
DBUG_ENTER("mysql_list_processes");
LINT_INIT(fields);
- if (simple_command(mysql,COM_PROCESS_INFO,0,0,0))
+ if (simple_command(mysql,COM_PROCESS_INFO,"",0,0))
DBUG_RETURN(0);
free_old_query(mysql);
pos=(uchar*) mysql->net.read_pos;
@@ -1795,7 +1661,7 @@ int STDCALL
mysql_shutdown(MYSQL *mysql)
{
DBUG_ENTER("mysql_shutdown");
- DBUG_RETURN(simple_command(mysql,COM_SHUTDOWN,0,0,0));
+ DBUG_RETURN(simple_command(mysql,COM_SHUTDOWN,"",0,0));
}
@@ -1822,14 +1688,14 @@ int STDCALL
mysql_dump_debug_info(MYSQL *mysql)
{
DBUG_ENTER("mysql_dump_debug_info");
- DBUG_RETURN(simple_command(mysql,COM_DEBUG,0,0,0));
+ DBUG_RETURN(simple_command(mysql,COM_DEBUG,"",0,0));
}
char * STDCALL
mysql_stat(MYSQL *mysql)
{
DBUG_ENTER("mysql_stat");
- if (simple_command(mysql,COM_STATISTICS,0,0,0))
+ if (simple_command(mysql,COM_STATISTICS,"",0,0))
return mysql->net.last_error;
mysql->net.read_pos[mysql->packet_length]=0; /* End of stat string */
if (!mysql->net.read_pos[0])
@@ -1846,7 +1712,7 @@ int STDCALL
mysql_ping(MYSQL *mysql)
{
DBUG_ENTER("mysql_ping");
- DBUG_RETURN(simple_command(mysql,COM_PING,0,0,0));
+ DBUG_RETURN(simple_command(mysql,COM_PING,"",0,0));
}