Signed-off-by: Guillaume Charifi guillaume.charifi@sfr.fr --- dlls/ws2_32/tests/afd.c | 73 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-)
diff --git a/dlls/ws2_32/tests/afd.c b/dlls/ws2_32/tests/afd.c index eb7c8ee50de..2568f251b6f 100644 --- a/dlls/ws2_32/tests/afd.c +++ b/dlls/ws2_32/tests/afd.c @@ -148,8 +148,10 @@ static void test_poll(void) const struct sockaddr_in bind_addr = {.sin_family = AF_INET, .sin_addr.s_addr = htonl(INADDR_LOOPBACK)}; char in_buffer[offsetof(struct afd_poll_params, sockets[3])]; char out_buffer[offsetof(struct afd_poll_params, sockets[3])]; + char out_buffer1[offsetof(struct afd_poll_params, sockets[3])]; struct afd_poll_params *in_params = (struct afd_poll_params *)in_buffer; struct afd_poll_params *out_params = (struct afd_poll_params *)out_buffer; + struct afd_poll_params *out_params1 = (struct afd_poll_params *)out_buffer1; int large_buffer_size = 1024 * 1024; SOCKET client, server, listener; struct sockaddr_in addr; @@ -157,13 +159,14 @@ static void test_poll(void) IO_STATUS_BLOCK io; LARGE_INTEGER now; ULONG params_size; - HANDLE event; + HANDLE event, event1; int ret, len;
large_buffer = malloc(large_buffer_size); memset(in_buffer, 0, sizeof(in_buffer)); memset(out_buffer, 0, sizeof(out_buffer)); event = CreateEventW(NULL, TRUE, FALSE, NULL); + event1 = CreateEventW(NULL, TRUE, FALSE, NULL);
listener = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); ret = bind(listener, (const struct sockaddr *)&bind_addr, sizeof(bind_addr)); @@ -208,10 +211,77 @@ static void test_poll(void) IOCTL_AFD_POLL, in_params, params_size, out_params, params_size); ok(ret == STATUS_INVALID_PARAMETER, "got %#x\n", ret);
+ /* Test exclusive flag */ + + client = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + + in_params->timeout = -1000 * 10000; + in_params->count = 1; + in_params->exclusive = FALSE; + in_params->sockets[0].socket = client; + in_params->sockets[0].flags = ~0; + in_params->sockets[0].status = 0; + + out_params->sockets[0].socket = 0; + out_params->sockets[0].flags = 0; + out_params->sockets[0].status = 0xdeadbeef; + + ret = NtDeviceIoControlFile((HANDLE)listener, event, NULL, NULL, &io, + IOCTL_AFD_POLL, in_params, params_size, out_params, params_size); + ok(ret == STATUS_PENDING, "got %#x\n", ret); + + in_params->timeout = 0x7fffffffffffffff; /* TIMEOUT_INFINITE */ + in_params->exclusive = TRUE; + + ret = NtDeviceIoControlFile((HANDLE)listener, event1, NULL, NULL, &io, + IOCTL_AFD_POLL, in_params, params_size, out_params1, params_size); + ok(ret == STATUS_PENDING, "got %#x\n", ret); + + ret = WaitForSingleObject(event, 100); + ok(ret == STATUS_TIMEOUT, "got %#x\n", ret); + ok(!out_params->sockets[0].socket, "got socket %#Ix\n", out_params->sockets[0].socket); + ok(!out_params->sockets[0].flags, "got flags %#x\n", out_params->sockets[0].flags); + ok(out_params->sockets[0].status == 0xdeadbeef, "got status %#x\n", out_params->sockets[0].status); + + closesocket(client); + + ret = WaitForSingleObject(event, 100); + ok(!ret, "got %#x\n", ret); + + client = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + + out_params->sockets[0].socket = 0; + out_params->sockets[0].flags = 0; + out_params->sockets[0].status = 0xdeadbeef; + + ret = NtDeviceIoControlFile((HANDLE)listener, event, NULL, NULL, &io, + IOCTL_AFD_POLL, in_params, params_size, out_params, params_size); + ok(ret == STATUS_PENDING, "got %#x\n", ret); + + ret = NtDeviceIoControlFile((HANDLE)listener, event1, NULL, NULL, &io, + IOCTL_AFD_POLL, in_params, params_size, out_params1, params_size); + ok(ret == STATUS_PENDING, "got %#x\n", ret); + + ret = WaitForSingleObject(event, 100); + ok(!ret, "got %#x\n", ret); + ok(io.Status == STATUS_SUCCESS, "got %#x\n", io.Status); + ok(io.Information == offsetof(struct afd_poll_params, sockets[0]), "got %#Ix\n", io.Information); + ok(out_params->timeout == 0x7fffffffffffffff, "got timeout %#I64x\n", out_params->timeout); + ok(!out_params->count, "got count %u\n", out_params->count); + ok(!out_params->sockets[0].socket, "got socket %#Ix\n", out_params->sockets[0].socket); + ok(!out_params->sockets[0].flags, "got flags %#x\n", out_params->sockets[0].flags); + ok(out_params->sockets[0].status == 0xdeadbeef, "got status %#x\n", out_params->sockets[0].status); + + closesocket(client); + + ret = WaitForSingleObject(event1, 100); + ok(!ret, "got %#x\n", ret); + /* Basic semantics of the ioctl. */
in_params->timeout = 0; in_params->count = 1; + in_params->exclusive = FALSE; in_params->sockets[0].socket = listener; in_params->sockets[0].flags = ~0; in_params->sockets[0].status = 0xdeadbeef; @@ -743,6 +813,7 @@ static void test_poll(void) closesocket(server);
CloseHandle(event); + CloseHandle(event1); free(large_buffer); }