summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/violite.h4
-rw-r--r--sql-common/client.c12
-rw-r--r--sql/mysqld.cc11
-rw-r--r--vio/vio.c4
-rw-r--r--vio/viosocket.c31
5 files changed, 50 insertions, 12 deletions
diff --git a/include/violite.h b/include/violite.h
index ba7de3ee175..64e834d6653 100644
--- a/include/violite.h
+++ b/include/violite.h
@@ -45,7 +45,8 @@ Vio* vio_new_win32shared_memory(NET *net,HANDLE handle_file_map,
HANDLE event_server_wrote,
HANDLE event_server_read,
HANDLE event_client_wrote,
- HANDLE event_client_read);
+ HANDLE event_client_read,
+ HANDLE event_conn_closed);
int vio_read_pipe(Vio *vio, gptr buf, int size);
int vio_write_pipe(Vio *vio, const gptr buf, int size);
int vio_close_pipe(Vio * vio);
@@ -197,6 +198,7 @@ struct st_vio
HANDLE event_server_read;
HANDLE event_client_wrote;
HANDLE event_client_read;
+ HANDLE event_conn_closed;
long shared_memory_remain;
char *shared_memory_pos;
NET *net;
diff --git a/sql-common/client.c b/sql-common/client.c
index b847c467b85..0714ca4291f 100644
--- a/sql-common/client.c
+++ b/sql-common/client.c
@@ -396,6 +396,7 @@ HANDLE create_shared_memory(MYSQL *mysql,NET *net, uint connect_timeout)
HANDLE event_server_read = NULL;
HANDLE event_client_wrote = NULL;
HANDLE event_client_read = NULL;
+ HANDLE event_conn_closed = NULL;
HANDLE handle_file_map = NULL;
ulong connect_number;
char connect_number_char[22], *p;
@@ -508,6 +509,13 @@ HANDLE create_shared_memory(MYSQL *mysql,NET *net, uint connect_timeout)
error_allow = CR_SHARED_MEMORY_EVENT_ERROR;
goto err2;
}
+
+ strmov(suffix_pos, "CONNECTION_CLOSED");
+ if ((event_conn_closed = OpenEvent(EVENT_ALL_ACCESS,FALSE,tmp)) == NULL)
+ {
+ error_allow = CR_SHARED_MEMORY_EVENT_ERROR;
+ goto err2;
+ }
/*
Set event that server should send data
*/
@@ -519,7 +527,7 @@ err2:
net->vio= vio_new_win32shared_memory(net,handle_file_map,handle_map,
event_server_wrote,
event_server_read,event_client_wrote,
- event_client_read);
+ event_client_read,event_conn_closed);
}
else
{
@@ -532,6 +540,8 @@ err2:
CloseHandle(event_client_read);
if (event_client_wrote)
CloseHandle(event_client_wrote);
+ if (event_conn_closed)
+ CloseHandle(event_conn_closed);
if (handle_map)
UnmapViewOfFile(handle_map);
if (handle_file_map)
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index e39c902444e..4a6dc037557 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -3813,6 +3813,7 @@ pthread_handler_decl(handle_connections_shared_memory,arg)
HANDLE event_client_read= 0; // for transfer data server <-> client
HANDLE event_server_wrote= 0;
HANDLE event_server_read= 0;
+ HANDLE event_conn_closed= 0;
THD *thd= 0;
p= int10_to_str(connect_number, connect_number_char, 10);
@@ -3866,6 +3867,12 @@ pthread_handler_decl(handle_connections_shared_memory,arg)
errmsg= "Could not create server write event";
goto errorconn;
}
+ strmov(suffix_pos, "CONNECTION_CLOSED");
+ if ((event_conn_closed= CreateEvent(0,TRUE,FALSE,tmp)) == 0)
+ {
+ errmsg= "Could not create closed connection event";
+ goto errorconn;
+ }
if (abort_loop)
goto errorconn;
if (!(thd= new THD))
@@ -3889,7 +3896,8 @@ pthread_handler_decl(handle_connections_shared_memory,arg)
event_client_wrote,
event_client_read,
event_server_wrote,
- event_server_read)) ||
+ event_server_read,
+ event_conn_closed)) ||
my_net_init(&thd->net, thd->net.vio))
{
close_connection(thd, ER_OUT_OF_RESOURCES, 1);
@@ -3916,6 +3924,7 @@ errorconn:
if (event_server_read) CloseHandle(event_server_read);
if (event_client_wrote) CloseHandle(event_client_wrote);
if (event_client_read) CloseHandle(event_client_read);
+ if (event_conn_closed) CloseHandle(event_conn_closed);
delete thd;
}
diff --git a/vio/vio.c b/vio/vio.c
index a356d8edeff..92d69dc5148 100644
--- a/vio/vio.c
+++ b/vio/vio.c
@@ -171,7 +171,8 @@ Vio *vio_new_win32pipe(HANDLE hPipe)
#ifdef HAVE_SMEM
Vio *vio_new_win32shared_memory(NET *net,HANDLE handle_file_map, HANDLE handle_map,
HANDLE event_server_wrote, HANDLE event_server_read,
- HANDLE event_client_wrote, HANDLE event_client_read)
+ HANDLE event_client_wrote, HANDLE event_client_read,
+ HANDLE event_conn_closed)
{
Vio *vio;
DBUG_ENTER("vio_new_win32shared_memory");
@@ -184,6 +185,7 @@ Vio *vio_new_win32shared_memory(NET *net,HANDLE handle_file_map, HANDLE handle_m
vio->event_server_read = event_server_read;
vio->event_client_wrote = event_client_wrote;
vio->event_client_read = event_client_read;
+ vio->event_conn_closed = event_conn_closed;
vio->shared_memory_remain = 0;
vio->shared_memory_pos = handle_map;
vio->net = net;
diff --git a/vio/viosocket.c b/vio/viosocket.c
index 48a9058480a..caf9451df7a 100644
--- a/vio/viosocket.c
+++ b/vio/viosocket.c
@@ -381,10 +381,21 @@ int vio_read_shared_memory(Vio * vio, gptr buf, int size)
{
if (vio->shared_memory_remain == 0)
{
- if (WaitForSingleObject(vio->event_server_wrote,vio->net->read_timeout*1000) != WAIT_OBJECT_0)
+ HANDLE events[2];
+ events[0]= vio->event_server_wrote;
+ events[1]= vio->event_conn_closed;
+ /*
+ WaitForMultipleObjects can return next values:
+ WAIT_OBJECT_0+0 - event from vio->event_server_wrote
+ WAIT_OBJECT_0+1 - event from vio->event_conn_closed. We can't read anything
+ WAIT_ABANDONED_0 and WAIT_TIMEOUT - fail. We can't read anything
+ */
+ if (WaitForMultipleObjects(2,(HANDLE*)&events,FALSE,
+ vio->net->read_timeout*1000) != WAIT_OBJECT_0)
{
DBUG_RETURN(-1);
};
+
vio->shared_memory_pos = vio->handle_map;
vio->shared_memory_remain = uint4korr((ulong*)vio->shared_memory_pos);
vio->shared_memory_pos+=4;
@@ -454,17 +465,21 @@ int vio_close_shared_memory(Vio * vio)
{
int r;
DBUG_ENTER("vio_close_shared_memory");
- r=UnmapViewOfFile(vio->handle_map) || CloseHandle(vio->event_server_wrote) ||
- CloseHandle(vio->event_server_read) || CloseHandle(vio->event_client_wrote) ||
- CloseHandle(vio->event_client_read) || CloseHandle(vio->handle_file_map);
- if (r)
+ if (vio->type != VIO_CLOSED)
{
- DBUG_PRINT("vio_error", ("close() failed, error: %d",r));
- /* FIXME: error handling (not critical for MySQL) */
+ SetEvent(vio->event_conn_closed);
+ r=UnmapViewOfFile(vio->handle_map) || CloseHandle(vio->event_server_wrote) ||
+ CloseHandle(vio->event_server_read) || CloseHandle(vio->event_client_wrote) ||
+ CloseHandle(vio->event_client_read) || CloseHandle(vio->handle_file_map);
+ if (!r)
+ {
+ DBUG_PRINT("vio_error", ("close() failed, error: %d",r));
+ /* FIXME: error handling (not critical for MySQL) */
+ }
}
vio->type= VIO_CLOSED;
vio->sd= -1;
- DBUG_RETURN(r);
+ DBUG_RETURN(!r);
}
#endif /* HAVE_SMEM */
#endif /* __WIN__ */