Lines Matching +full:libev +full:- +full:dev
2 * libwebsockets - small server side websockets and web server implementation
4 * Copyright (C) 2010 - 2020 Andy Green <andy@warmcat.com>
25 #include "private-lib-core.h"
26 #include "private-lib-event-libs-libev.h"
28 #define pt_to_priv_ev(_pt) ((struct lws_pt_eventlibs_libev *)(_pt)->evlib_pt)
29 #define vh_to_priv_ev(_vh) ((struct lws_vh_eventlibs_libev *)(_vh)->evlib_vh)
30 #define wsi_to_priv_ev(_w) ((struct lws_wsi_eventlibs_libev *)(_w)->evlib_wsi)
37 struct lws_context_per_thread *pt = ptpr->pt; in lws_ev_hrtimer_cb()
41 us = __lws_sul_service_ripe(pt->pt_sul_owner, LWS_COUNT_PT_SUL_OWNERS, in lws_ev_hrtimer_cb()
44 ev_timer_set(&ptpr->hrtimer, ((float)us) / 1000000.0, 0); in lws_ev_hrtimer_cb()
45 ev_timer_start(ptpr->io_loop, &ptpr->hrtimer); in lws_ev_hrtimer_cb()
55 struct lws_context_per_thread *pt = ptpr->pt; in lws_ev_idle_cb()
64 if (!lws_service_adjust_timeout(pt->context, 1, pt->tid)) in lws_ev_idle_cb()
65 /* -1 timeout means just do forced service */ in lws_ev_idle_cb()
66 reschedule = _lws_plat_service_forced_tsi(pt->context, pt->tid); in lws_ev_idle_cb()
71 us = __lws_sul_service_ripe(pt->pt_sul_owner, LWS_COUNT_PT_SUL_OWNERS, in lws_ev_idle_cb()
74 ev_timer_set(&ptpr->hrtimer, ((float)us) / 1000000.0, 0); in lws_ev_idle_cb()
75 ev_timer_start(ptpr->io_loop, &ptpr->hrtimer); in lws_ev_idle_cb()
83 if (pt->destroy_self) in lws_ev_idle_cb()
84 lws_context_destroy(pt->context); in lws_ev_idle_cb()
92 struct lws_context *context = lws_io->context; in lws_accept_cb()
101 eventfd.fd = watcher->fd; in lws_accept_cb()
114 wsi = wsi_from_fd(context, watcher->fd); in lws_accept_cb()
115 pt = &context->pt[(int)wsi->tsi]; in lws_accept_cb()
118 lws_service_fd_tsi(context, &eventfd, (int)wsi->tsi); in lws_accept_cb()
120 ev_idle_start(ptpr->io_loop, &ptpr->idle); in lws_accept_cb()
126 struct lws_context *context = watcher->data; in lws_ev_sigint_cb()
128 if (context->eventlib_signal_cb) { in lws_ev_sigint_cb()
129 context->eventlib_signal_cb((void *)watcher, watcher->signum); in lws_ev_sigint_cb()
141 struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; in elops_listen_init_ev()
144 struct lws_vhost *vh = wsi->a.vhost; in elops_listen_init_ev()
146 w->w_read.context = context; in elops_listen_init_ev()
147 w->w_write.context = context; in elops_listen_init_ev()
148 vh_to_priv_ev(vh)->w_accept.context = context; in elops_listen_init_ev()
150 ev_io_init(&vh_to_priv_ev(vh)->w_accept.watcher, in elops_listen_init_ev()
151 lws_accept_cb, wsi->desc.sockfd, EV_READ); in elops_listen_init_ev()
152 ev_io_start(ptpr->io_loop, &vh_to_priv_ev(vh)->w_accept.watcher); in elops_listen_init_ev()
160 struct lws_context_per_thread *pt = &context->pt[tsi]; in elops_init_pt_ev()
162 struct ev_signal *w_sigint = &ptpr->w_sigint.watcher; in elops_init_pt_ev()
170 ptpr->pt = pt; in elops_init_pt_ev()
175 context->pt[tsi].event_loop_foreign = 1; in elops_init_pt_ev()
180 return -1; in elops_init_pt_ev()
183 ptpr->io_loop = loop; in elops_init_pt_ev()
188 if (!context->pt[tsi].event_loop_foreign) { in elops_init_pt_ev()
190 w_sigint->data = context; in elops_init_pt_ev()
219 backend_name = "/dev/poll"; in elops_init_pt_ev()
225 backend_name = "Unknown libev backend"; in elops_init_pt_ev()
229 lwsl_cx_info(context, " libev backend: %s", backend_name); in elops_init_pt_ev()
232 ev_timer_init(&ptpr->hrtimer, lws_ev_hrtimer_cb, 0, 0); in elops_init_pt_ev()
233 ptpr->hrtimer.data = pt; in elops_init_pt_ev()
235 ev_idle_init(&ptpr->idle, lws_ev_idle_cb); in elops_init_pt_ev()
245 struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; in elops_listen_destroy_ev()
247 struct lws_vhost *vh = wsi->a.vhost; in elops_listen_destroy_ev()
249 ev_io_stop(ptpr->io_loop, &vh_to_priv_ev(vh)->w_accept.watcher); in elops_listen_destroy_ev()
257 struct lws_context_per_thread *pt = &context->pt[tsi]; in elops_destroy_pt_ev()
264 ev_timer_stop(ptpr->io_loop, &ptpr->hrtimer); in elops_destroy_pt_ev()
265 ev_idle_stop(ptpr->io_loop, &ptpr->idle); in elops_destroy_pt_ev()
267 if (!pt->event_loop_foreign) in elops_destroy_pt_ev()
268 ev_signal_stop(ptpr->io_loop, &ptpr->w_sigint.watcher); in elops_destroy_pt_ev()
277 context->eventlib_signal_cb = info->signal_cb; in elops_init_context_ev()
279 for (n = 0; n < context->count_threads; n++) in elops_init_context_ev()
280 pt_to_priv_ev(&context->pt[n])->w_sigint.context = context; in elops_init_context_ev()
291 if (wsi->role_ops->file_handle) in elops_accept_ev()
292 fd = wsi->desc.filefd; in elops_accept_ev()
294 fd = wsi->desc.sockfd; in elops_accept_ev()
296 w->w_read.context = wsi->a.context; in elops_accept_ev()
297 w->w_write.context = wsi->a.context; in elops_accept_ev()
299 ev_io_init(&w->w_read.watcher, lws_accept_cb, fd, EV_READ); in elops_accept_ev()
300 ev_io_init(&w->w_write.watcher, lws_accept_cb, fd, EV_WRITE); in elops_accept_ev()
308 struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; in elops_io_ev()
312 lwsl_wsi_debug(wsi, "%s flags 0x%x %p %d", wsi->role_ops->name, flags, in elops_io_ev()
313 ptpr->io_loop, in elops_io_ev()
314 pt->is_destroyed); in elops_io_ev()
316 if (!ptpr->io_loop || pt->is_destroyed) in elops_io_ev()
324 ev_io_start(ptpr->io_loop, &w->w_write.watcher); in elops_io_ev()
326 ev_io_start(ptpr->io_loop, &w->w_read.watcher); in elops_io_ev()
329 ev_io_stop(ptpr->io_loop, &w->w_write.watcher); in elops_io_ev()
331 ev_io_stop(ptpr->io_loop, &w->w_read.watcher); in elops_io_ev()
334 if (pt->destroy_self) in elops_io_ev()
335 lws_context_destroy(pt->context); in elops_io_ev()
341 if (pt_to_priv_ev(&context->pt[tsi])->io_loop) in elops_run_pt_ev()
342 ev_run(pt_to_priv_ev(&context->pt[tsi])->io_loop, 0); in elops_run_pt_ev()
352 for (n = 0; n < context->count_threads; n++) { in elops_destroy_context2_ev()
355 pt = &context->pt[n]; in elops_destroy_context2_ev()
360 if (pt->event_loop_foreign || !ptpr->io_loop) in elops_destroy_context2_ev()
363 if (!context->evlib_finalize_destroy_after_int_loops_stop) { in elops_destroy_context2_ev()
364 ev_break(ptpr->io_loop, EVBREAK_ONE); in elops_destroy_context2_ev()
367 while (budget-- && in elops_destroy_context2_ev()
368 (m = ev_run(ptpr->io_loop, 0))) in elops_destroy_context2_ev()
371 ev_loop_destroy(ptpr->io_loop); in elops_destroy_context2_ev()
389 w->w_read.context = wsi->a.context; in elops_init_vhost_listen_wsi_ev()
390 w->w_write.context = wsi->a.context; in elops_init_vhost_listen_wsi_ev()
392 if (wsi->role_ops->file_handle) in elops_init_vhost_listen_wsi_ev()
393 fd = wsi->desc.filefd; in elops_init_vhost_listen_wsi_ev()
395 fd = wsi->desc.sockfd; in elops_init_vhost_listen_wsi_ev()
397 ev_io_init(&w->w_read.watcher, lws_accept_cb, fd, EV_READ); in elops_init_vhost_listen_wsi_ev()
398 //ev_io_init(&w->w_write.watcher, lws_accept_cb, fd, EV_WRITE); in elops_init_vhost_listen_wsi_ev()
408 struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; in elops_destroy_wsi_ev()
412 ev_io_stop(ptpr->io_loop, &w->w_read.watcher); in elops_destroy_wsi_ev()
413 ev_io_stop(ptpr->io_loop, &w->w_write.watcher); in elops_destroy_wsi_ev()
417 /* name */ "libev",
446 "libev event loop",