|
| 1 | +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. |
| 2 | + * |
| 3 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 4 | + * of this software and associated documentation files (the "Software"), to |
| 5 | + * deal in the Software without restriction, including without limitation the |
| 6 | + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 7 | + * sell copies of the Software, and to permit persons to whom the Software is |
| 8 | + * furnished to do so, subject to the following conditions: |
| 9 | + * |
| 10 | + * The above copyright notice and this permission notice shall be included in |
| 11 | + * all copies or substantial portions of the Software. |
| 12 | + * |
| 13 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 16 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 17 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 18 | + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 19 | + * IN THE SOFTWARE. |
| 20 | + */ |
| 21 | + |
| 22 | +#ifdef _WIN32 |
| 23 | + |
| 24 | +#include <errno.h> |
| 25 | + |
| 26 | +#include "uv.h" |
| 27 | +#include "task.h" |
| 28 | + |
| 29 | +uv_os_sock_t sock; |
| 30 | +uv_poll_t handle; |
| 31 | + |
| 32 | +static int close_cb_called = 0; |
| 33 | + |
| 34 | + |
| 35 | +static void close_cb(uv_handle_t* h) { |
| 36 | + close_cb_called++; |
| 37 | +} |
| 38 | + |
| 39 | + |
| 40 | +static void poll_cb(uv_poll_t* h, int status, int events) { |
| 41 | + int r; |
| 42 | + |
| 43 | + ASSERT(status == 0); |
| 44 | + ASSERT(h == &handle); |
| 45 | + |
| 46 | + r = uv_poll_start(&handle, UV_READABLE, poll_cb); |
| 47 | + ASSERT(r == 0); |
| 48 | + |
| 49 | + closesocket(sock); |
| 50 | + uv_close((uv_handle_t*) &handle, close_cb); |
| 51 | + |
| 52 | +} |
| 53 | + |
| 54 | + |
| 55 | +TEST_IMPL(poll_closesocket) { |
| 56 | + struct WSAData wsa_data; |
| 57 | + int r; |
| 58 | + unsigned long on; |
| 59 | + struct sockaddr_in addr; |
| 60 | + |
| 61 | + r = WSAStartup(MAKEWORD(2, 2), &wsa_data); |
| 62 | + ASSERT(r == 0); |
| 63 | + |
| 64 | + sock = socket(AF_INET, SOCK_STREAM, 0); |
| 65 | + ASSERT(sock != INVALID_SOCKET); |
| 66 | + on = 1; |
| 67 | + r = ioctlsocket(sock, FIONBIO, &on); |
| 68 | + ASSERT(r == 0); |
| 69 | + |
| 70 | + r = uv_ip4_addr("127.0.0.1", TEST_PORT, &addr); |
| 71 | + ASSERT(r == 0); |
| 72 | + |
| 73 | + r = connect(sock, (const struct sockaddr*) &addr, sizeof addr); |
| 74 | + ASSERT(r != 0); |
| 75 | + ASSERT(WSAGetLastError() == WSAEWOULDBLOCK); |
| 76 | + |
| 77 | + r = uv_poll_init_socket(uv_default_loop(), &handle, sock); |
| 78 | + ASSERT(r == 0); |
| 79 | + r = uv_poll_start(&handle, UV_WRITABLE, poll_cb); |
| 80 | + ASSERT(r == 0); |
| 81 | + |
| 82 | + uv_run(uv_default_loop(), UV_RUN_DEFAULT); |
| 83 | + |
| 84 | + ASSERT(close_cb_called == 1); |
| 85 | + |
| 86 | + MAKE_VALGRIND_HAPPY(); |
| 87 | + return 0; |
| 88 | +} |
| 89 | +#endif |
0 commit comments