From aa3bb50aeca3b7350a41f0538817c49d9656d207 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Thu, 28 Dec 2017 16:02:53 -0800 Subject: 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. --- src/platform/windows/win_tcp.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/platform/windows/win_tcp.c') 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); } -- cgit v1.2.3-70-g09d2