Refactor io_accept for Windows
This commit is contained in:
@@ -392,25 +392,13 @@ static bool io_accept_windows(struct io_context *ioc,
|
|||||||
if (new_os_handle == INVALID_SOCKET)
|
if (new_os_handle == INVALID_SOCKET)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
LPFN_ACCEPTEX lpfnAcceptEx = NULL;
|
LPFN_ACCEPTEX lpfnAcceptEx = res->acceptfn;
|
||||||
GUID GuidAcceptEx = WSAID_ACCEPTEX;
|
|
||||||
|
|
||||||
unsigned long num;
|
|
||||||
int ret = WSAIoctl((SOCKET) os_handle,
|
|
||||||
SIO_GET_EXTENSION_FUNCTION_POINTER,
|
|
||||||
&GuidAcceptEx, sizeof(GuidAcceptEx),
|
|
||||||
&lpfnAcceptEx, sizeof(lpfnAcceptEx),
|
|
||||||
&num, NULL, NULL);
|
|
||||||
if (ret == SOCKET_ERROR) {
|
|
||||||
DEBUG_LOG("WSAIoctl failure\n");
|
|
||||||
closesocket(new_os_handle);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
_Static_assert(IO_SOCKADDR_IN_SIZE == sizeof(struct sockaddr_in));
|
_Static_assert(IO_SOCKADDR_IN_SIZE == sizeof(struct sockaddr_in));
|
||||||
|
|
||||||
int ok = lpfnAcceptEx((SOCKET) os_handle, new_os_handle, op->accept_buffer,
|
unsigned long num;
|
||||||
sizeof(op->accept_buffer) - ((sizeof(struct sockaddr_in) + 16) * 2),
|
int ok = lpfnAcceptEx((SOCKET) os_handle, new_os_handle, res->accept_buffer,
|
||||||
|
sizeof(res->accept_buffer) - ((sizeof(struct sockaddr_in) + 16) * 2),
|
||||||
sizeof(struct sockaddr_in) + 16,
|
sizeof(struct sockaddr_in) + 16,
|
||||||
sizeof(struct sockaddr_in) + 16,
|
sizeof(struct sockaddr_in) + 16,
|
||||||
&num, (OVERLAPPED*) &op->ov);
|
&num, (OVERLAPPED*) &op->ov);
|
||||||
@@ -743,10 +731,24 @@ io_handle io_start_server(struct io_context *ioc,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if IO_PLATFORM_WINDOWS
|
#if IO_PLATFORM_WINDOWS
|
||||||
|
LPFN_ACCEPTEX lpfnAcceptEx = NULL;
|
||||||
|
GUID GuidAcceptEx = WSAID_ACCEPTEX;
|
||||||
|
unsigned long num;
|
||||||
|
int ret = WSAIoctl(fd,
|
||||||
|
SIO_GET_EXTENSION_FUNCTION_POINTER,
|
||||||
|
&GuidAcceptEx, sizeof(GuidAcceptEx),
|
||||||
|
&lpfnAcceptEx, sizeof(lpfnAcceptEx),
|
||||||
|
&num, NULL, NULL);
|
||||||
|
if (ret == SOCKET_ERROR) {
|
||||||
|
DEBUG_LOG("WSAIoctl failure\n");
|
||||||
|
closesocket(fd);
|
||||||
|
return IO_INVALID;
|
||||||
|
}
|
||||||
if (CreateIoCompletionPort((HANDLE) fd, ioc->os_handle, 0, 0) == NULL) {
|
if (CreateIoCompletionPort((HANDLE) fd, ioc->os_handle, 0, 0) == NULL) {
|
||||||
closesocket(fd);
|
closesocket(fd);
|
||||||
return IO_INVALID;
|
return IO_INVALID;
|
||||||
}
|
}
|
||||||
|
res->acceptfn = lpfnAcceptEx;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
res->type = IO_RES_SOCKET;
|
res->type = IO_RES_SOCKET;
|
||||||
|
|||||||
@@ -60,7 +60,6 @@ struct io_operation {
|
|||||||
#if IO_PLATFORM_WINDOWS
|
#if IO_PLATFORM_WINDOWS
|
||||||
io_os_handle accepted;
|
io_os_handle accepted;
|
||||||
struct io_os_overlap ov;
|
struct io_os_overlap ov;
|
||||||
char accept_buffer[2 * (IO_SOCKADDR_IN_SIZE + 16)];
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -75,6 +74,11 @@ struct io_resource {
|
|||||||
io_os_handle os_handle;
|
io_os_handle os_handle;
|
||||||
uint16_t pending;
|
uint16_t pending;
|
||||||
uint16_t gen;
|
uint16_t gen;
|
||||||
|
|
||||||
|
#if IO_PLATFORM_WINDOWS
|
||||||
|
void *acceptfn;
|
||||||
|
char accept_buffer[2 * (IO_SOCKADDR_IN_SIZE + 16)];
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
struct io_context {
|
struct io_context {
|
||||||
|
|||||||
Reference in New Issue
Block a user