time_t time(time_t *t)
{
time_t ret = time_in_microseconds() / 1000000;
- *t = ret;
+
+ if(t != NULL)
+ *t = ret;
+
return ret;
}
#endif
memset(&_lws, 0, sizeof(_lws));
_lws.context = context;
- context->service_tid_detected = context->protocols[0].callback(
- &_lws, LWS_CALLBACK_GET_THREAD_ID, NULL, NULL, 0);
+ context->service_tid_detected = context->vhost_list->
+ protocols[0].callback(&_lws, LWS_CALLBACK_GET_THREAD_ID,
+ NULL, NULL, 0);
}
context->service_tid = context->service_tid_detected;
+ if (timeout_ms < 0)
+ goto faked_service;
+
for (i = 0; i < pt->fds_count; ++i) {
pfd = &pt->fds[i];
- if (pfd->fd == pt->lserv_fd)
+
+ if (!(pfd->events & LWS_POLLOUT))
continue;
- if (pfd->events & LWS_POLLOUT) {
- wsi = wsi_from_fd(context, pfd->fd);
- if (!wsi || wsi->sock_send_blocking)
- continue;
- pfd->revents = LWS_POLLOUT;
- n = lws_service_fd(context, pfd);
- if (n < 0)
- return -1;
- /* if something closed, retry this slot */
- if (n)
- i--;
- }
+ wsi = wsi_from_fd(context, pfd->fd);
+ if (wsi->listener)
+ continue;
+ if (!wsi || wsi->sock_send_blocking)
+ continue;
+ pfd->revents = LWS_POLLOUT;
+ n = lws_service_fd(context, pfd);
+ if (n < 0)
+ return -1;
+ /* if something closed, retry this slot */
+ if (n)
+ i--;
}
/* if we know something needs service already, don't wait in poll */
wsi->sock_send_blocking = 0;
}
+faked_service:
+
/* if someone faked their LWS_POLLIN, then go through all active fds */
if (lws_service_flag_pending(context, tsi)) {
return 0;
}
+ if (timeout_ms < 0)
+ return 0;
+
/* otherwise just do the one... must be a way to improve that... */
return lws_service_fd_tsi(context, pfd, tsi);
}
LWS_VISIBLE int
-lws_plat_set_socket_options(struct lws_context *context, lws_sockfd_type fd)
+lws_plat_set_socket_options(struct lws_vhost *vhost, lws_sockfd_type fd)
{
int optval = 1;
int optlen = sizeof(optval);
u_long optl = 1;
DWORD dwBytesRet;
struct tcp_keepalive alive;
+ int protonbr;
+#ifndef _WIN32_WCE
struct protoent *tcp_proto;
+#endif
- if (context->ka_time) {
+ if (vhost->ka_time) {
/* enable keepalive on this socket */
optval = 1;
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE,
return 1;
alive.onoff = TRUE;
- alive.keepalivetime = context->ka_time;
- alive.keepaliveinterval = context->ka_interval;
+ alive.keepalivetime = vhost->ka_time;
+ alive.keepaliveinterval = vhost->ka_interval;
if (WSAIoctl(fd, SIO_KEEPALIVE_VALS, &alive, sizeof(alive),
NULL, 0, &dwBytesRet, NULL, NULL))
/* Disable Nagle */
optval = 1;
+#ifndef _WIN32_WCE
tcp_proto = getprotobyname("TCP");
if (!tcp_proto) {
lwsl_err("getprotobyname() failed with error %d\n", LWS_ERRNO);
return 1;
}
+ protonbr = tcp_proto->p_proto;
+#else
+ protonbr = 6;
+#endif
- setsockopt(fd, tcp_proto->p_proto, TCP_NODELAY, (const char *)&optval, optlen);
+ setsockopt(fd, protonbr, TCP_NODELAY, (const char *)&optval, optlen);
/* We are nonblocking... */
ioctlsocket(fd, FIONBIO, &optl);
{
DWORD _amount;
- (void *)wsi;
if (!ReadFile((HANDLE)fd, buf, (DWORD)len, &_amount, NULL)) {
*amount = 0;