diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-12-28 16:02:53 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-12-28 16:02:53 -0800 |
| commit | aa3bb50aeca3b7350a41f0538817c49d9656d207 (patch) | |
| tree | 4abafbdc7553e52776394e067fa1ff9a08a14a57 /src/platform | |
| parent | 838d92deabffbaae1b1a9e447d2088f966078726 (diff) | |
| download | nng-aa3bb50aeca3b7350a41f0538817c49d9656d207.tar.gz nng-aa3bb50aeca3b7350a41f0538817c49d9656d207.tar.bz2 nng-aa3bb50aeca3b7350a41f0538817c49d9656d207.zip | |
Fix compilation warnings, bugs, and crashes found on Windows.
This addresses a number of problems that were found on Windows,
including one bug that actually turned up in testing on POSIX.
Diffstat (limited to 'src/platform')
| -rw-r--r-- | src/platform/posix/posix_epdesc.c | 2 | ||||
| -rw-r--r-- | src/platform/windows/win_tcp.c | 10 | ||||
| -rw-r--r-- | src/platform/windows/win_thread.c | 9 |
3 files changed, 14 insertions, 7 deletions
diff --git a/src/platform/posix/posix_epdesc.c b/src/platform/posix/posix_epdesc.c index 80711ed0..7b168679 100644 --- a/src/platform/posix/posix_epdesc.c +++ b/src/platform/posix/posix_epdesc.c @@ -318,6 +318,7 @@ nni_posix_epdesc_accept(nni_posix_epdesc *ed, nni_aio *aio) // connection is ready for us. There isn't anything else for us to // do really, as that will have been done in listen. nni_mtx_lock(&ed->mtx); + aio->a_pipe = NULL; // If we can't start, it means that the AIO was stopped. if ((rv = nni_aio_start(aio, nni_posix_epdesc_cancel, ed)) != 0) { nni_mtx_unlock(&ed->mtx); @@ -343,6 +344,7 @@ nni_posix_epdesc_connect(nni_posix_epdesc *ed, nni_aio *aio) int fd; nni_mtx_lock(&ed->mtx); + aio->a_pipe = NULL; // If we can't start, it means that the AIO was stopped. if ((rv = nni_aio_start(aio, nni_posix_epdesc_cancel, ed)) != 0) { nni_mtx_unlock(&ed->mtx); diff --git a/src/platform/windows/win_tcp.c b/src/platform/windows/win_tcp.c index 01818af4..93cead91 100644 --- a/src/platform/windows/win_tcp.c +++ b/src/platform/windows/win_tcp.c @@ -163,6 +163,12 @@ nni_win_tcp_pipe_cancel(nni_win_event *evt) static void nni_win_tcp_pipe_finish(nni_win_event *evt, nni_aio *aio) { + if ((evt->status == 0) && (evt->count == 0)) { + // Windows sometimes returns a zero read. Convert these + // into an NNG_ECLOSED. (We are never supposed to come + // back with zero length read.) + evt->status = NNG_ECLOSED; + } nni_aio_finish(aio, evt->status, evt->count); } @@ -263,10 +269,10 @@ nni_plat_tcp_ep_init(nni_plat_tcp_ep **epp, const nni_sockaddr *lsa, ep->s = INVALID_SOCKET; - if (rsa->s_un.s_family != NNG_AF_UNSPEC) { + if ((rsa != NULL) && (rsa->s_un.s_family != NNG_AF_UNSPEC)) { ep->remlen = nni_win_nn2sockaddr(&ep->remaddr, rsa); } - if (lsa->s_un.s_family != NNG_AF_UNSPEC) { + if ((lsa != NULL) && (lsa->s_un.s_family != NNG_AF_UNSPEC)) { ep->loclen = nni_win_nn2sockaddr(&ep->locaddr, lsa); } diff --git a/src/platform/windows/win_thread.c b/src/platform/windows/win_thread.c index 0d9e7387..6cfb4162 100644 --- a/src/platform/windows/win_thread.c +++ b/src/platform/windows/win_thread.c @@ -14,20 +14,19 @@ #ifdef NNG_PLATFORM_WINDOWS +#include <stdlib.h> + void * nni_alloc(size_t sz) { - void *v; - - v = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sz); - return (v); + return (calloc(sz, 1)); } void nni_free(void *b, size_t z) { NNI_ARG_UNUSED(z); - HeapFree(GetProcessHeap(), 0, b); + free(b); } void |
