diff options
| author | Garrett D'Amore <garrett@damore.org> | 2024-12-28 16:10:48 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2024-12-28 16:24:49 -0800 |
| commit | 6a414614d906999bd4eb6e9b2f96ca972b437ffc (patch) | |
| tree | 6454a86b9c23a38056c72260e8d1e7d6fba38c8a /src/platform/windows/win_tcpdial.c | |
| parent | 7b5515ca641f475dce8184a5d9fd67ceb860e843 (diff) | |
| download | nng-6a414614d906999bd4eb6e9b2f96ca972b437ffc.tar.gz nng-6a414614d906999bd4eb6e9b2f96ca972b437ffc.tar.bz2 nng-6a414614d906999bd4eb6e9b2f96ca972b437ffc.zip | |
windows tcp: Lookup extended TCP function pointers at startup
This avoids the need for a lock during listener or dialer initialization,
and it avoids the need to carry these pointers on those objects.
It also eliminates a potential failure case "post startup".
Diffstat (limited to 'src/platform/windows/win_tcpdial.c')
| -rw-r--r-- | src/platform/windows/win_tcpdial.c | 27 |
1 files changed, 2 insertions, 25 deletions
diff --git a/src/platform/windows/win_tcpdial.c b/src/platform/windows/win_tcpdial.c index 474bd79f..f9844655 100644 --- a/src/platform/windows/win_tcpdial.c +++ b/src/platform/windows/win_tcpdial.c @@ -17,8 +17,7 @@ #include <stdio.h> struct nni_tcp_dialer { - LPFN_CONNECTEX connectex; // looked up name via ioctl - nni_list aios; // in flight connections + nni_list aios; // in flight connections bool closed; bool nodelay; // initial value for child conns bool keepalive; // initial value for child conns @@ -40,31 +39,10 @@ nni_tcp_dialer_init(nni_tcp_dialer **dp) if ((d = NNI_ALLOC_STRUCT(d)) == NULL) { return (NNG_ENOMEM); } - ZeroMemory(d, sizeof(*d)); nni_mtx_init(&d->mtx); nni_aio_list_init(&d->aios); d->nodelay = true; - // Create a scratch socket for use with ioctl. - s = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP); - if (s == INVALID_SOCKET) { - rv = nni_win_error(GetLastError()); - nni_tcp_dialer_fini(d); - return (rv); - } - - // Look up the function pointer. - if (WSAIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER, &guid, - sizeof(guid), &d->connectex, sizeof(d->connectex), &nbytes, - NULL, NULL) == SOCKET_ERROR) { - rv = nni_win_error(GetLastError()); - closesocket(s); - nni_tcp_dialer_fini(d); - return (rv); - } - - closesocket(s); - *dp = d; return (0); } @@ -255,8 +233,7 @@ nni_tcp_dial(nni_tcp_dialer *d, const nni_sockaddr *sa, nni_aio *aio) nni_aio_list_append(&d->aios, aio); // dialing is concurrent. - if (!d->connectex(s, (struct sockaddr *) &c->peername, len, NULL, 0, - NULL, &c->conn_io.olpd)) { + if (!nni_win_connectex(s, &c->peername, len, &c->conn_io.olpd)) { if ((rv = GetLastError()) != ERROR_IO_PENDING) { nni_aio_list_remove(aio); nni_mtx_unlock(&d->mtx); |
