diff options
Diffstat (limited to 'libmariadb/plugins/pvio')
-rw-r--r-- | libmariadb/plugins/pvio/pvio_npipe.c | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/libmariadb/plugins/pvio/pvio_npipe.c b/libmariadb/plugins/pvio/pvio_npipe.c index 17c59cef..d2d5222a 100644 --- a/libmariadb/plugins/pvio/pvio_npipe.c +++ b/libmariadb/plugins/pvio/pvio_npipe.c @@ -150,19 +150,38 @@ static BOOL complete_io(HANDLE file, OVERLAPPED *ov, BOOL ret, DWORD timeout, DW return GetOverlappedResult(file, ov, size, FALSE); } +/* + Disable posting IO completion event to the port. + Handle can be bound to IOCP outside of the connector for other purposes + (e.g polling functionality) +*/ + +static inline void disable_iocp_notification(HANDLE *h) +{ + *h= (HANDLE) ((ULONG_PTR) *h | 1); +} + +static inline void enable_iocp_notification(HANDLE *h) +{ + *h= (HANDLE) ((ULONG_PTR) *h & ~1); +} + ssize_t pvio_npipe_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length) { BOOL ret; ssize_t r= -1; struct st_pvio_npipe *cpipe= NULL; DWORD size; + HANDLE *h; if (!pvio || !pvio->data) return -1; cpipe= (struct st_pvio_npipe *)pvio->data; - + h= &cpipe->overlapped.hEvent; + disable_iocp_notification(h); ret= ReadFile(cpipe->pipe, buffer, (DWORD)length, NULL, &cpipe->overlapped); + enable_iocp_notification(h); ret= complete_io(cpipe->pipe, &cpipe->overlapped, ret, pvio->timeout[PVIO_READ_TIMEOUT], &size); r= ret? (ssize_t) size:-1; @@ -175,13 +194,15 @@ ssize_t pvio_npipe_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length) struct st_pvio_npipe *cpipe= NULL; BOOL ret; DWORD size; - + HANDLE *h; if (!pvio || !pvio->data) return -1; cpipe= (struct st_pvio_npipe *)pvio->data; - + h= &cpipe->overlapped.hEvent; + disable_iocp_notification(h); ret= WriteFile(cpipe->pipe, buffer, (DWORD)length, NULL , &cpipe->overlapped); + enable_iocp_notification(h); ret= complete_io(cpipe->pipe, &cpipe->overlapped, ret, pvio->timeout[PVIO_WRITE_TIMEOUT], &size); r= ret ? (ssize_t)size : -1; return r; |