18 #if defined(_WIN32) && defined(HAVE_SMEM)
20 size_t vio_read_shared_memory(
Vio *vio, uchar *
buf,
size_t size)
24 char *current_position;
27 DBUG_ENTER(
"vio_read_shared_memory");
30 current_position=
buf;
31 timeout= vio->read_timeout >= 0 ? vio->read_timeout : INFINITE;
33 events[0]= vio->event_server_wrote;
34 events[1]= vio->event_conn_closed;
38 if (vio->shared_memory_remain == 0)
42 wait_status= WaitForMultipleObjects(array_elements(events), events,
52 if (wait_status != WAIT_OBJECT_0)
60 if (wait_status == WAIT_TIMEOUT)
61 SetLastError(SOCKET_ETIMEDOUT);
62 else if (wait_status == (WAIT_OBJECT_0 + 1))
68 vio->shared_memory_pos= vio->handle_map;
69 vio->shared_memory_remain= uint4korr((ulong*)vio->shared_memory_pos);
70 vio->shared_memory_pos+= 4;
75 if (vio->shared_memory_remain < length)
76 length= vio->shared_memory_remain;
77 if (length > remain_local)
80 memcpy(current_position, vio->shared_memory_pos, length);
82 vio->shared_memory_remain-= length;
83 vio->shared_memory_pos+= length;
84 current_position+= length;
85 remain_local-= length;
87 if (!vio->shared_memory_remain)
89 if (!SetEvent(vio->event_client_read))
92 }
while (remain_local);
99 size_t vio_write_shared_memory(
Vio *vio,
const uchar *buf,
size_t size)
101 size_t length, remain, sz;
103 const uchar *current_position;
106 DBUG_ENTER(
"vio_write_shared_memory");
109 current_position=
buf;
110 timeout= vio->write_timeout >= 0 ? vio->write_timeout : INFINITE;
112 events[0]= vio->event_server_read;
113 events[1]= vio->event_conn_closed;
119 wait_status= WaitForMultipleObjects(array_elements(events), events,
122 if (wait_status != WAIT_OBJECT_0)
125 if (wait_status == WAIT_TIMEOUT)
126 SetLastError(SOCKET_ETIMEDOUT);
128 SetLastError(ERROR_GRACEFUL_DISCONNECT);
130 DBUG_RETURN((
size_t) -1);
133 sz= (remain > shared_memory_buffer_length ? shared_memory_buffer_length :
136 int4store(vio->handle_map, sz);
137 pos= vio->handle_map + 4;
138 memcpy(pos, current_position, sz);
140 current_position+= sz;
141 if (!SetEvent(vio->event_client_wrote))
142 DBUG_RETURN((
size_t) -1);
150 my_bool vio_is_connected_shared_memory(
Vio *vio)
152 return (WaitForSingleObject(vio->event_conn_closed, 0) != WAIT_OBJECT_0);
156 void vio_delete_shared_memory(
Vio *vio)
158 DBUG_ENTER(
"vio_delete_shared_memory");
163 if (vio->inactive == FALSE)
164 vio->vioshutdown(vio);
170 if (UnmapViewOfFile(vio->handle_map) == 0)
171 DBUG_PRINT(
"vio_error", (
"UnmapViewOfFile() failed"));
173 if (CloseHandle(vio->event_server_wrote) == 0)
174 DBUG_PRINT(
"vio_error", (
"CloseHandle(vio->esw) failed"));
176 if (CloseHandle(vio->event_server_read) == 0)
177 DBUG_PRINT(
"vio_error", (
"CloseHandle(vio->esr) failed"));
179 if (CloseHandle(vio->event_client_wrote) == 0)
180 DBUG_PRINT(
"vio_error", (
"CloseHandle(vio->ecw) failed"));
182 if (CloseHandle(vio->event_client_read) == 0)
183 DBUG_PRINT(
"vio_error", (
"CloseHandle(vio->ecr) failed"));
185 if (CloseHandle(vio->handle_file_map) == 0)
186 DBUG_PRINT(
"vio_error", (
"CloseHandle(vio->hfm) failed"));
188 if (CloseHandle(vio->event_conn_closed) == 0)
189 DBUG_PRINT(
"vio_error", (
"CloseHandle(vio->ecc) failed"));
207 int vio_shutdown_shared_memory(
Vio * vio)
209 DBUG_ENTER(
"vio_shutdown_shared_memory");
210 if (vio->inactive == FALSE)
216 SetEvent(vio->event_conn_closed);