20 static size_t wait_overlapped_result(
Vio *vio,
int timeout)
22 size_t ret= (size_t) -1;
23 DWORD transferred, wait_status, timeout_ms;
25 timeout_ms= timeout >= 0 ? timeout : INFINITE;
28 wait_status= WaitForSingleObject(vio->overlapped.hEvent, timeout_ms);
31 if (wait_status == WAIT_OBJECT_0)
34 if (GetOverlappedResult(vio->hPipe, &vio->overlapped, &transferred, FALSE))
47 if (wait_status == WAIT_TIMEOUT)
48 SetLastError(SOCKET_ETIMEDOUT);
55 size_t vio_read_pipe(
Vio *vio, uchar *
buf,
size_t count)
58 size_t ret= (size_t) -1;
59 DBUG_ENTER(
"vio_read_pipe");
62 if (ReadFile(vio->hPipe, buf, count, &transferred, &vio->overlapped))
68 else if (GetLastError() == ERROR_IO_PENDING)
69 ret= wait_overlapped_result(vio, vio->read_timeout);
75 size_t vio_write_pipe(
Vio *vio,
const uchar *buf,
size_t count)
78 size_t ret= (size_t) -1;
79 DBUG_ENTER(
"vio_write_pipe");
82 if (WriteFile(vio->hPipe, buf, count, &transferred, &vio->overlapped))
88 else if (GetLastError() == ERROR_IO_PENDING)
89 ret= wait_overlapped_result(vio, vio->write_timeout);
95 my_bool vio_is_connected_pipe(
Vio *vio)
97 if (PeekNamedPipe(vio->hPipe, NULL, 0, NULL, NULL, NULL))
100 return (GetLastError() != ERROR_BROKEN_PIPE);
104 int vio_shutdown_pipe(
Vio *vio)
107 DBUG_ENTER(
"vio_shutdown_pipe");
109 CancelIo(vio->hPipe);
110 CloseHandle(vio->overlapped.hEvent);
111 DisconnectNamedPipe(vio->hPipe);
112 ret= CloseHandle(vio->hPipe);