1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

win32: align hrtimer support with unix plat

Workaround last build warnings on win32.
This commit is contained in:
Andy Green 2018-05-05 07:18:00 +08:00
parent e7673b4c1d
commit e77dafba6f
3 changed files with 27 additions and 8 deletions

View file

@ -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;
}

View file

@ -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 <winsock2.h>
#include <ws2tcpip.h>
#include <windows.h>

View file

@ -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++;
}