}
static void
+lws_uv_idle(uv_idle_t *handle)
+{
+ struct lws_context_per_thread *pt = container_of(handle,
+ struct lws_context_per_thread, uv_idle);
+
+ lwsl_debug("%s\n", __func__);
+
+ /*
+ * is there anybody with pending stuff that needs service forcing?
+ */
+ if (!lws_service_adjust_timeout(pt->context, 1, pt->tid)) {
+ /* -1 timeout means just do forced service */
+ lws_plat_service_tsi(pt->context, -1, pt->tid);
+ /* still somebody left who wants forced service? */
+ if (!lws_service_adjust_timeout(pt->context, 1, pt->tid))
+ /* yes... come back again later */
+ return;
+ }
+
+ /* there is nobody who needs service forcing, shut down idle */
+ uv_idle_stop(handle);
+}
+
+static void
lws_io_cb(uv_poll_t *watcher, int status, int revents)
{
struct lws_io_watcher *lws_io = container_of(watcher,
struct lws_io_watcher, uv_watcher);
+ struct lws *wsi = container_of(lws_io, struct lws, w_read);
struct lws_context *context = lws_io->context;
struct lws_pollfd eventfd;
}
}
lws_service_fd(context, &eventfd);
+
+ uv_idle_start(&context->pt[(int)wsi->tsi].uv_idle, lws_uv_idle);
}
LWS_VISIBLE void
struct lws_context_per_thread *pt = container_of(timer,
struct lws_context_per_thread, uv_timeout_watcher);
- lwsl_info("%s\n", __func__);
- /* do timeout check only */
+ lwsl_debug("%s\n", __func__);
lws_service_fd_tsi(pt->context, NULL, pt->tid);
}
pt->ev_loop_foreign = 1;
pt->io_loop_uv = loop;
+ uv_idle_init(loop, &pt->uv_idle);
if (pt->context->use_ev_sigint) {
assert(ARRAY_SIZE(sigs) <= ARRAY_SIZE(pt->signals));
lws_plat_service_tsi(struct lws_context *context, int timeout_ms, int tsi)
{
struct lws_context_per_thread *pt = &context->pt[tsi];
- int n, m, c;
+ int n = -1, m, c;
char buf;
/* stay dead once we are dead */
if (!context)
return 1;
+ if (timeout_ms < 0)
+ goto faked_service;
+
lws_libev_run(context, tsi);
lws_libuv_run(context, tsi);
return 0;
}
+faked_service:
m = lws_service_flag_pending(context, tsi);
if (m)
c = -1; /* unknown limit */
}
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)
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);