diff --git a/lib/core/libwebsockets.c b/lib/core/libwebsockets.c index 51e4e5a4..4360e958 100644 --- a/lib/core/libwebsockets.c +++ b/lib/core/libwebsockets.c @@ -2653,8 +2653,13 @@ lws_create_adopt_udp(struct lws_vhost *vhost, int port, int flags, goto bail1; } - if ((flags & LWS_CAUDP_BIND) && - bind(sock.sockfd, rp->ai_addr, rp->ai_addrlen) == -1) { + if ((flags & LWS_CAUDP_BIND) && bind(sock.sockfd, rp->ai_addr, +#if defined(_WIN32) + (int)rp->ai_addrlen +#else + rp->ai_addrlen +#endif + ) == -1) { lwsl_err("%s: bind failed\n", __func__); goto bail2; } diff --git a/lib/core/private.h b/lib/core/private.h index cb3ab4ca..b31b6938 100644 --- a/lib/core/private.h +++ b/lib/core/private.h @@ -93,7 +93,7 @@ #define compatible_close(fd) closesocket(fd) #define lws_set_blocking_send(wsi) wsi->sock_send_blocking = 1 #define lws_socket_is_valid(x) (!!x) - #define LWS_SOCK_INVALID 0 + #define LWS_SOCK_INVALID (INVALID_SOCKET) #include #include #include diff --git a/lib/plat/lws-plat-win.c b/lib/plat/lws-plat-win.c index b7f28de6..948db628 100644 --- a/lib/plat/lws-plat-win.c +++ b/lib/plat/lws-plat-win.c @@ -20,7 +20,7 @@ lws_plat_pipe_signal(struct lws *wsi) { struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; - WSASetEvent(pt->events[0]); + WSASetEvent(pt->events[0]); /* trigger the cancel event */ return 0; } @@ -46,9 +46,10 @@ time_in_microseconds() #endif /* - * As per Windows documentation for FILETIME, copy the resulting FILETIME structure to a - * ULARGE_INTEGER structure using memcpy (using memcpy instead of direct assignment can - * prevent alignment faults on 64-bit Windows). + * As per Windows documentation for FILETIME, copy the resulting + * FILETIME structure to a ULARGE_INTEGER structure using memcpy + * (using memcpy instead of direct assignment can prevent alignment + * faults on 64-bit Windows). */ memcpy(&datetime, &filetime, sizeof(datetime)); @@ -218,6 +219,9 @@ _lws_plat_service_tsi(struct lws_context *context, int timeout_ms, int tsi) return 0; } + if (context->event_loop_ops->run_pt) + context->event_loop_ops->run_pt(context, tsi); + for (i = 0; i < pt->fds_count; ++i) { pfd = &pt->fds[i]; @@ -256,6 +260,16 @@ _lws_plat_service_tsi(struct lws_context *context, int timeout_ms, int tsi) timeout_ms = 0; } + if (timeout_ms) { + lws_pt_lock(pt, __func__); + /* don't stay in poll wait longer than next hr timeout */ + lws_usec_t t = __lws_hrtimer_service(pt); + + if ((lws_usec_t)timeout_ms * 1000 > t) + timeout_ms = (int)(t / 1000); + lws_pt_unlock(pt); + } + ev = WSAWaitForMultipleEvents(1, pt->events, FALSE, timeout_ms, FALSE); if (ev == WSA_WAIT_EVENT_0) { unsigned int eIdx, err; @@ -738,7 +752,7 @@ lws_plat_init(struct lws_context *context, } pt->fds_count = 0; - pt->events[0] = WSACreateEvent(); + pt->events[0] = WSACreateEvent(); /* the cancel event */ pt++; }