Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Allow named pipe connection handle to be used with IO completion port
Client programs can use pipe handle via mysql_get_socket().
They also might want to use IO completion ports with this handle.

Prevent IOCP notifications to be sent to completion port, for internal
read and write with timeout.
  • Loading branch information
vaintroub committed Nov 19, 2023
1 parent 458a439 commit 75ab6fb
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions plugins/pvio/pvio_npipe.c
Expand Up @@ -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;

Expand All @@ -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;
Expand Down

0 comments on commit 75ab6fb

Please sign in to comment.