diff options
author | Jack R. Dunaway <jack@wirebirdlabs.com> | 2016-04-25 18:03:54 -0500 |
---|---|---|
committer | Jack R. Dunaway <jack@wirebirdlabs.com> | 2016-04-25 18:03:54 -0500 |
commit | 69846d0bea3a9c9842fb87199d70a728aec7a299 (patch) | |
tree | 13c4a6e1b80131a3fd9d00baf2fc0788851f9748 /src/aio | |
parent | 8422f526059c48e86a2db3cb6f5ef4e55ab73fc1 (diff) | |
download | nanomsg-69846d0bea3a9c9842fb87199d70a728aec7a299.tar.gz |
fixes #672 MSVC x64 reports compiler warnings in usock_win.inc
Diffstat (limited to 'src/aio')
-rw-r--r-- | src/aio/usock_win.inc | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/src/aio/usock_win.inc b/src/aio/usock_win.inc index ae3c081..0af756d 100644 --- a/src/aio/usock_win.inc +++ b/src/aio/usock_win.inc @@ -323,7 +323,7 @@ void nn_usock_connect (struct nn_usock *self, const struct sockaddr *addr, size_t addrlen) { BOOL brc; - const GUID fid = WSAID_CONNECTEX; + GUID fid = WSAID_CONNECTEX; LPFN_CONNECTEX pconnectex; DWORD nbytes; DWORD winerror; @@ -334,7 +334,6 @@ void nn_usock_connect (struct nn_usock *self, const struct sockaddr *addr, /* Notify the state machine that we've started connecting. */ nn_fsm_action (&self->fsm, NN_USOCK_ACTION_CONNECT); - nn_assert(addrlen < INT_MAX); memset (&self->out.olpd, 0, sizeof (self->out.olpd)); if (self->domain == AF_UNIX) { @@ -343,16 +342,20 @@ void nn_usock_connect (struct nn_usock *self, const struct sockaddr *addr, else { /* Get the pointer to connect function. */ - brc = WSAIoctl(self->s, SIO_GET_EXTENSION_FUNCTION_POINTER, - (void*)&fid, sizeof(fid), (void*)&pconnectex, sizeof(pconnectex), + brc = WSAIoctl (self->s, SIO_GET_EXTENSION_FUNCTION_POINTER, + &fid, sizeof (fid), &pconnectex, sizeof (pconnectex), &nbytes, NULL, NULL) == 0; - wsa_assert(brc == TRUE); - nn_assert(nbytes == sizeof(pconnectex)); + wsa_assert (brc == TRUE); + nn_assert (nbytes == sizeof (pconnectex)); + + /* Ensure it is safe to cast this value to what might be a smaller + integer type to conform to the pconnectex function signature. */ + nn_assert (addrlen < INT_MAX); /* Connect itself. */ - brc = pconnectex(self->s, (struct sockaddr*) addr, addrlen, - NULL, 0, NULL, &self->out.olpd); - winerror = brc ? ERROR_SUCCESS : WSAGetLastError(); + brc = pconnectex (self->s, addr, (int) addrlen, NULL, 0, NULL, + &self->out.olpd); + winerror = brc ? ERROR_SUCCESS : WSAGetLastError (); } /* Immediate success. */ @@ -390,7 +393,7 @@ void nn_usock_send (struct nn_usock *self, const struct nn_iovec *iov, nn_assert (iovcnt <= NN_USOCK_MAX_IOVCNT); for (i = 0; i != iovcnt; ++i) { wbuf [i].buf = (char FAR*) iov [i].iov_base; - wbuf [i].len = (u_long) iov [i].iov_len; + wbuf [i].len = (ULONG) iov [i].iov_len; len += iov [i].iov_len; } @@ -401,6 +404,10 @@ void nn_usock_send (struct nn_usock *self, const struct nn_iovec *iov, /* TODO: Do not copy the buffer, find an efficent way to Write multiple buffers that doesn't affect the state machine. */ + /* Ensure the total buffer size does not exceed size limitation + of WriteFile. */ + nn_assert (len <= MAXDWORD); + nn_assert (!self->pipesendbuf); self->pipesendbuf = nn_alloc (len, "named pipe sendbuf"); @@ -409,7 +416,7 @@ void nn_usock_send (struct nn_usock *self, const struct nn_iovec *iov, memcpy ((char*)(self->pipesendbuf) + idx, iov [i].iov_base, iov [i].iov_len); idx += iov [i].iov_len; } - brc = WriteFile (self->p, self->pipesendbuf, len, NULL, &self->out.olpd); + brc = WriteFile (self->p, self->pipesendbuf, (DWORD) len, NULL, &self->out.olpd); if (nn_fast (brc || GetLastError() == ERROR_IO_PENDING)) { nn_worker_op_start (&self->out, 0); return; @@ -454,13 +461,18 @@ void nn_usock_recv (struct nn_usock *self, void *buf, size_t len, int *fd) nn_assert_state (self, NN_USOCK_STATE_ACTIVE); /* Start the receive operation. */ - wbuf.len = (u_long) len; + wbuf.len = (ULONG) len; wbuf.buf = (char FAR*) buf; wflags = MSG_WAITALL; memset (&self->in.olpd, 0, sizeof (self->in.olpd)); + if (self->domain == AF_UNIX) { - brc = ReadFile(self->p, buf, len, NULL, &self->in.olpd); - error = brc ? ERROR_SUCCESS : GetLastError(); + + /* Ensure the total buffer size does not exceed size limitation + of WriteFile. */ + nn_assert (len <= MAXDWORD); + brc = ReadFile (self->p, buf, (DWORD) len, NULL, &self->in.olpd); + error = brc ? ERROR_SUCCESS : GetLastError (); } else { rc = WSARecv (self->s, &wbuf, 1, NULL, &wflags, &self->in.olpd, NULL); |