aboutsummaryrefslogtreecommitdiff
path: root/src/platform/windows
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-02-05 10:23:35 -0800
committerGarrett D'Amore <garrett@damore.org>2018-02-05 10:23:35 -0800
commit844ce972fed056e1c4e0517e43b814c62d68edce (patch)
treeadfa91e3f7188d268f3d081e80c14f7e8a609a87 /src/platform/windows
parentb893f8ff1f96dde567fa6a75f4b15bf69e53d6f5 (diff)
downloadnng-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')
-rw-r--r--src/platform/windows/win_ipc.c4
-rw-r--r--src/platform/windows/win_tcp.c8
-rw-r--r--src/platform/windows/win_udp.c25
3 files changed, 27 insertions, 10 deletions
diff --git a/src/platform/windows/win_ipc.c b/src/platform/windows/win_ipc.c
index 022a18ea..76180d23 100644
--- a/src/platform/windows/win_ipc.c
+++ b/src/platform/windows/win_ipc.c
@@ -59,8 +59,8 @@ nni_win_ipc_pipe_start(nni_win_event *evt, nni_aio *aio)
BOOL ok;
int rv;
nni_plat_ipc_pipe *pipe = evt->ptr;
- int idx;
- int naiov;
+ unsigned idx;
+ unsigned naiov;
nni_iov * aiov;
NNI_ASSERT(aio != NULL);
diff --git a/src/platform/windows/win_tcp.c b/src/platform/windows/win_tcp.c
index c9935719..254cf40b 100644
--- a/src/platform/windows/win_tcp.c
+++ b/src/platform/windows/win_tcp.c
@@ -12,6 +12,7 @@
#ifdef NNG_PLATFORM_WINDOWS
+#include <malloc.h>
#include <stdio.h>
struct nni_plat_tcp_pipe {
@@ -101,15 +102,16 @@ nni_win_tcp_pipe_start(nni_win_event *evt, nni_aio *aio)
{
int rv;
SOCKET s;
- WSABUF iov[4]; // XXX: consider _alloca()
DWORD niov;
DWORD flags;
nni_plat_tcp_pipe *pipe = evt->ptr;
int i;
- int naiov;
+ unsigned naiov;
nni_iov * aiov;
+ WSABUF * iov;
nni_aio_get_iov(aio, &naiov, &aiov);
+ iov = _malloca(naiov * sizeof(*iov));
// Put the AIOs in Windows form.
for (niov = 0, i = 0; i < naiov; i++) {
@@ -121,6 +123,7 @@ nni_win_tcp_pipe_start(nni_win_event *evt, nni_aio *aio)
}
if ((s = pipe->s) == INVALID_SOCKET) {
+ _freea(iov);
evt->status = NNG_ECLOSED;
evt->count = 0;
return (1);
@@ -136,6 +139,7 @@ nni_win_tcp_pipe_start(nni_win_event *evt, nni_aio *aio)
} else {
rv = WSARecv(s, iov, niov, NULL, &flags, &evt->olpd, NULL);
}
+ _freea(iov);
if ((rv == SOCKET_ERROR) &&
((rv = GetLastError()) != ERROR_IO_PENDING)) {
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.