lxl_int_t lxl_handler_read_event(lxl_event_t *rev) { if (lxl_event_flags & LXL_USE_CLEAR_EVENT) { if (!rev->active && !rev->ready) { return lxl_add_event(rev, LXL_READ_EVENT, LXL_CLEAR_EVENT); } return 0; } else if (lxl_event_flags & LXL_USE_LEVEL_EVENT) { if (!rev->active && !rev->ready) { return lxl_add_event(rev, LXL_READ_EVENT, LXL_LEVEL_EVENT); } return 0; } return 0; }
static void lxl_enable_accept_events(lxl_cycle_t *cycle) { lxl_uint_t i, nelts; lxl_listening_t *ls; lxl_connection_t *c; nelts = lxl_array_nelts(&cycle->listening); for (i = 0; i < nelts; ++i) { ls = lxl_array_data(&cycle->listening, lxl_listening_t, i); c = ls->connection; if (c->read->active) { continue; } lxl_add_event(c->read, LXL_READ_EVENT, 0); } }
int lxl_handle_write_event(lxl_event_t *wev, size_t lowat) { lxl_connection_t *c; if (lowat) { c = wev->data; if (lxl_send_lowat(c, lowat) == -1) { return -1; } } if (!wev->active && !wev->ready) { return lxl_add_event(wev, LXL_WRITE_EVENT, LXL_CLEAR_EVENT); } return 0; }
int lxl_event_process_init(lxl_cycle_t *cycle) { lxl_uint_t i, nelts; lxl_connection_t *c, *next; lxl_listening_t *ls; lxl_core_conf_t *ccf; lxl_event_conf_t *ecf; lxl_event_module_t *m; ccf = (lxl_core_conf_t *) lxl_get_conf(cycle->conf_ctx, lxl_core_module); ecf = (*(lxl_get_conf(cycle->conf_ctx, lxl_events_module))) [lxl_event_core_module.ctx_index]; if (ccf->worker_process > 1 && ecf->accept_mutex) { lxl_use_accept_mutex = 1; } else { lxl_use_accept_mutex = 0; } lxl_accept_disabled = 1; //lxl_list_init(&lxl_posted_event_list); lxl_event_timer_init(); for (i = 0; lxl_modules[i]; ++i) { if (lxl_modules[i]->type != LXL_EVENT_MODULE) { continue; } if (lxl_modules[i]->ctx_index != ecf->use) { continue; } m = lxl_modules[i]->ctx; if (m->actions.init(cycle) != 0) { /* fatal */ exit(2); } break; } cycle->connections = lxl_alloc(cycle->connection_n * sizeof(lxl_connection_t)); if (cycle->connections == NULL) { return -1; } cycle->read_events = lxl_alloc(cycle->connection_n * sizeof(lxl_event_t)); if (cycle->read_events == NULL) { return -1; } for (i = 0; i < cycle->connection_n; ++i) { cycle->read_events[i].closed = 1; } cycle->write_events = lxl_alloc(cycle->connection_n * sizeof(lxl_event_t)); if (cycle->write_events == NULL) { return -1; } for (i = 0; i < cycle->connection_n; ++i) { cycle->write_events[i].closed = 1; } next = NULL; i = cycle->connection_n; c = cycle->connections; do { --i; c[i].data = next; c[i].fd = -1; c[i].read = &cycle->read_events[i]; c[i].write = &cycle->write_events[i]; next = &c[i]; } while (i); cycle->free_connection_n = cycle->connection_n; cycle->free_connections = next; ls = lxl_array_elts(&cycle->listening); nelts = lxl_array_nelts(&cycle->listening); for (i = 0; i < nelts; ++i) { c = lxl_get_connection(ls[i].fd); if (c == NULL) { return -1; } c->listening = &ls[i]; ls[i].connection = c; //rev = c->read; c->read->accept = 1; if (ls[i].type == SOCK_STREAM) { c->udp = 0; //c->closefd = 1; c->read->handler = lxl_event_accept; /* tcp or udp */ } else { c->udp = 1; //c->closefd = 1; c->read->handler = lxl_event_accept_udp; /*c->recv = lxl_recvfrom; c->send = lxl_sendto;*/ } if (lxl_use_accept_mutex) { continue; } if (lxl_add_event(c->read, LXL_READ_EVENT, LXL_LEVEL_EVENT) == -1) { return -1; } } return 0; }