summaryrefslogtreecommitdiff
path: root/vio/viosocket.c
diff options
context:
space:
mode:
Diffstat (limited to 'vio/viosocket.c')
-rw-r--r--vio/viosocket.c42
1 files changed, 33 insertions, 9 deletions
diff --git a/vio/viosocket.c b/vio/viosocket.c
index 2921eb7495e..de50dabba5f 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;
@@ -429,7 +440,8 @@ int vio_write_shared_memory(Vio * vio, const gptr buf, int size)
current_postion = buf;
while (remain != 0)
{
- if (WaitForSingleObject(vio->event_server_read,vio->net->write_timeout*1000) != WAIT_OBJECT_0)
+ if (WaitForSingleObject(vio->event_server_read, vio->net->write_timeout*1000)
+ != WAIT_OBJECT_0)
{
DBUG_RETURN(-1);
};
@@ -454,17 +466,29 @@ 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) */
+ /*
+ Set event_conn_closed for notification of both client and server that
+ connection is closed
+ */
+ SetEvent(vio->event_conn_closed);
+ /*
+ Close all handlers. UnmapViewOfFile and CloseHandle return non-zero
+ result if they are success.
+ */
+ 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__ */