summaryrefslogtreecommitdiff
path: root/vio/viopipe.c
diff options
context:
space:
mode:
authorVladislav Vaintroub <wlad@montyprogram.com>2012-11-04 21:04:04 +0100
committerVladislav Vaintroub <wlad@montyprogram.com>2012-11-04 21:04:04 +0100
commitcdb54f480d9a7aada5c4035aa603c139bdd8e727 (patch)
treed7e5ef83bc56b91bc412df666462f886af143700 /vio/viopipe.c
parent5e68c5ce7db95610c2084f9d9c6d01473ae243db (diff)
downloadmariadb-git-cdb54f480d9a7aada5c4035aa603c139bdd8e727.tar.gz
MDEV-3822 :10.0-serg fails on windows buildslaves
Fix mismerged code from 5.6 (named-pipe related). viopipe.c, which was introduced in 5.6 is now copied almost identically into 10.0 The unused vio::pipe_overlapped is removed.
Diffstat (limited to 'vio/viopipe.c')
-rw-r--r--vio/viopipe.c75
1 files changed, 26 insertions, 49 deletions
diff --git a/vio/viopipe.c b/vio/viopipe.c
index 045ab8edfb8..f9af50bc3c9 100644
--- a/vio/viopipe.c
+++ b/vio/viopipe.c
@@ -34,42 +34,38 @@ static void enable_iocp_notification(OVERLAPPED *overlapped)
*handle = (HANDLE)((ULONG_PTR) *handle & ~1);
}
-
-/*
- Finish pending IO on pipe. Honor wait timeout
-*/
-
static size_t wait_overlapped_result(Vio *vio, int timeout)
{
size_t ret= (size_t) -1;
DWORD transferred, wait_status, timeout_ms;
- DBUG_ENTER("wait_overlapped_result");
timeout_ms= timeout >= 0 ? timeout : INFINITE;
/* Wait for the overlapped operation to be completed. */
- wait_status= WaitForSingleObjectEx(vio->pipe_overlapped.hEvent, timeout_ms, TRUE);
+ wait_status= WaitForSingleObject(vio->overlapped.hEvent, timeout_ms);
- /*
- WaitForSingleObjects will normally return WAIT_OBJECT_O (success,
- IO completed) or WAIT_TIMEOUT.
- */
- if (ret != WAIT_OBJECT_0)
+ /* The operation might have completed, attempt to retrieve the result. */
+ if (wait_status == WAIT_OBJECT_0)
{
+ /* If retrieval fails, a error code will have been set. */
+ if (GetOverlappedResult(vio->hPipe, &vio->overlapped, &transferred, FALSE))
+ ret= transferred;
+ }
+ else
+ {
+ /* Error or timeout, cancel the pending I/O operation. */
CancelIo(vio->hPipe);
- DBUG_PRINT("error",("WaitForSingleObject() returned %d", ret));
+
+ /*
+ If the wait timed out, set error code to indicate a
+ timeout error. Otherwise, wait_status is WAIT_FAILED
+ and extended error information was already set.
+ */
if (wait_status == WAIT_TIMEOUT)
SetLastError(SOCKET_ETIMEDOUT);
- DBUG_RETURN((size_t)-1);
}
- if (!GetOverlappedResult(vio->hPipe,&(vio->overlapped),&transferred, FALSE))
- {
- DBUG_PRINT("error",("GetOverlappedResult() returned last error %d",
- GetLastError()));
- DBUG_RETURN((size_t)-1);
- }
- DBUG_RETURN(transferred);
+ return ret;
}
@@ -78,10 +74,9 @@ size_t vio_read_pipe(Vio *vio, uchar *buf, size_t count)
DWORD transferred;
size_t ret= (size_t) -1;
DBUG_ENTER("vio_read_pipe");
- DBUG_PRINT("enter", ("sd: %p buf: %p size: %d", vio->hPipe, buf,
- (int) count));
disable_iocp_notification(&vio->overlapped);
+
/* Attempt to read from the pipe (overlapped I/O). */
if (ReadFile(vio->hPipe, buf, count, &transferred, &vio->overlapped))
{
@@ -89,19 +84,11 @@ size_t vio_read_pipe(Vio *vio, uchar *buf, size_t count)
ret= transferred;
}
/* Read operation is pending completion asynchronously? */
- else
- {
- if (GetLastError() != ERROR_IO_PENDING)
- {
- enable_iocp_notification(&vio->pipe_overlapped);
- DBUG_PRINT("error",("ReadFile() returned last error %d",
- GetLastError()));
- DBUG_RETURN((size_t)-1);
- }
+ else if (GetLastError() == ERROR_IO_PENDING)
ret= wait_overlapped_result(vio, vio->read_timeout);
- }
+
enable_iocp_notification(&vio->overlapped);
- DBUG_PRINT("exit", ("%d", (int) ret));
+
DBUG_RETURN(ret);
}
@@ -111,29 +98,19 @@ size_t vio_write_pipe(Vio *vio, const uchar *buf, size_t count)
DWORD transferred;
size_t ret= (size_t) -1;
DBUG_ENTER("vio_write_pipe");
- DBUG_PRINT("enter", ("sd: %d buf: %p size: %d", vio->hPipe, buf,
- (int) count));
- disable_iocp_notification(&vio->pipe_overlapped);
+ disable_iocp_notification(&vio->overlapped);
/* Attempt to write to the pipe (overlapped I/O). */
if (WriteFile(vio->hPipe, buf, count, &transferred, &vio->overlapped))
{
/* The operation completed immediately. */
ret= transferred;
}
- else
- {
- enable_iocp_notification(&vio->pipe_overlapped);
- if (GetLastError() != ERROR_IO_PENDING)
- {
- DBUG_PRINT("vio_error",("WriteFile() returned last error %d",
- GetLastError()));
- DBUG_RETURN((size_t)-1);
- }
+ /* Write operation is pending completion asynchronously? */
+ else if (GetLastError() == ERROR_IO_PENDING)
ret= wait_overlapped_result(vio, vio->write_timeout);
- }
- enable_iocp_notification(&vio->pipe_overlapped);
- DBUG_PRINT("exit", ("%d", (int) ret));
+
+ enable_iocp_notification(&vio->overlapped);
DBUG_RETURN(ret);
}