diff options
| author | Garrett D'Amore <garrett@damore.org> | 2018-02-05 10:23:35 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2018-02-05 10:23:35 -0800 |
| commit | 844ce972fed056e1c4e0517e43b814c62d68edce (patch) | |
| tree | adfa91e3f7188d268f3d081e80c14f7e8a609a87 /src/platform/windows/win_udp.c | |
| parent | b893f8ff1f96dde567fa6a75f4b15bf69e53d6f5 (diff) | |
| download | nng-844ce972fed056e1c4e0517e43b814c62d68edce.tar.gz nng-844ce972fed056e1c4e0517e43b814c62d68edce.tar.bz2 nng-844ce972fed056e1c4e0517e43b814c62d68edce.zip | |
fixes #228 aio iov should have larger limits (dynamically allocated)
Diffstat (limited to 'src/platform/windows/win_udp.c')
| -rw-r--r-- | src/platform/windows/win_udp.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/platform/windows/win_udp.c b/src/platform/windows/win_udp.c index ba947719..81aa2c06 100644 --- a/src/platform/windows/win_udp.c +++ b/src/platform/windows/win_udp.c @@ -15,6 +15,7 @@ #ifdef NNG_PLATFORM_WINDOWS +#include <malloc.h> #include <stdio.h> struct nni_plat_udp { @@ -134,11 +135,11 @@ nni_win_udp_start_rx(nni_win_event *evt, nni_aio *aio) { int rv; SOCKET s; - WSABUF iov[4]; // XXX: consider _alloca DWORD flags; nni_plat_udp *u = evt->ptr; nni_iov * aiov; - int naiov; + unsigned naiov; + WSABUF * iov; if ((s = u->s) == INVALID_SOCKET) { evt->status = NNG_ECLOSED; @@ -149,8 +150,13 @@ nni_win_udp_start_rx(nni_win_event *evt, nni_aio *aio) u->rxsalen = sizeof(SOCKADDR_STORAGE); nni_aio_get_iov(aio, &naiov, &aiov); + // This is a stack allocation- it should always succeed - or + // throw an exception if there is not sufficient stack space. + // (Turns out it can allocate from the heap, but same semantics.) + iov = _malloca(sizeof(*iov) * naiov); + // Put the AIOs in Windows form. - for (int i = 0; i < naiov; i++) { + for (unsigned i = 0; i < naiov; i++) { iov[i].buf = aiov[i].iov_buf; iov[i].len = (ULONG) aiov[i].iov_len; } @@ -164,6 +170,8 @@ nni_win_udp_start_rx(nni_win_event *evt, nni_aio *aio) rv = WSARecvFrom(u->s, iov, (DWORD) naiov, NULL, &flags, (struct sockaddr *) &u->rxsa, &u->rxsalen, &evt->olpd, NULL); + _freea(iov); + if ((rv == SOCKET_ERROR) && ((rv = GetLastError()) != ERROR_IO_PENDING)) { // Synchronous failure. @@ -183,12 +191,12 @@ nni_win_udp_start_tx(nni_win_event *evt, nni_aio *aio) { int rv; SOCKET s; - WSABUF iov[4]; - int naiov; + unsigned naiov; nni_iov * aiov; nni_plat_udp *u = evt->ptr; int salen; nni_sockaddr *sa; + WSABUF * iov; if ((s = u->s) == INVALID_SOCKET) { evt->status = NNG_ECLOSED; @@ -205,8 +213,11 @@ nni_win_udp_start_tx(nni_win_event *evt, nni_aio *aio) } nni_aio_get_iov(aio, &naiov, &aiov); + + iov = _malloca(sizeof(*iov) * naiov); + // Put the AIOs in Windows form. - for (int i = 0; i < naiov; i++) { + for (unsigned i = 0; i < naiov; i++) { iov[i].buf = aiov[i].iov_buf; iov[i].len = (ULONG) aiov[i].iov_len; } @@ -219,6 +230,8 @@ nni_win_udp_start_tx(nni_win_event *evt, nni_aio *aio) rv = WSASendTo(u->s, iov, (DWORD) naiov, NULL, 0, (struct sockaddr *) &u->txsa, salen, &evt->olpd, NULL); + _freea(iov); + if ((rv == SOCKET_ERROR) && ((rv = GetLastError()) != ERROR_IO_PENDING)) { // Synchronous failure. |
