static int emit_command (workerState * ws) { simpleBuf *sb; sb = &ws->out; assert (sb->cp == sb->buf); sb->ep = sb->buf + sb->cap; // tps == 0 means no limit if (ws->tps > 0) { if (ws->token_val < SINGLE_TOKEN_VAL) { ws->wprepare_at_token = 1; return 0; } ws->token_val -= SINGLE_TOKEN_VAL; } ws->start_usec = currtime_usec (); ws->key = get_key (ws); if (ks_crc[ws->key] == -1 || ks_crc[ws->key] != ks_crc_next[ws->key]) { ws->is_sync = 1; return emit_get (ws); } else { return emit_set (ws); } }
static int edpnet_sock_epollerr_handler(emit_t em, edp_event_t *ev){ struct edpnet_sock *s; s = emit_get(em); ASSERT(s != NULL); s->es_cbs->sock_error(s, s->es_data); //FIXME: clear pending writes return 0; }
static int edpnet_sock_epollhup_handler(emit_t em, edp_event_t *ev){ struct edpnet_sock *s; s = emit_get(em); ASSERT(s != NULL); spi_spin_lock(&s->es_lock); s->es_status &= ~kEDPNET_SOCK_STATUS_CONNECT; spi_spin_unlock(&s->es_lock); s->es_cbs->sock_close(s, s->es_data); //FIXME: clear pending writes return 0; }
static int edpnet_sock_epollout_handler(emit_t em, edp_event_t *ev){ struct edpnet_sock *s; ioctx_t *ioc = NULL; s = emit_get(em); ASSERT(s != NULL); if(!(s->es_status & kEDPNET_SOCK_STATUS_CONNECT)){ spi_spin_lock(&s->es_lock); s->es_status |= kEDPNET_SOCK_STATUS_CONNECT; spi_spin_unlock(&s->es_lock); // call connect callback s->es_cbs->sock_connect(s, s->es_data); }else if(s->es_status & kEDPNET_SOCK_STATUS_WRITE){ spi_spin_lock(&s->es_lock); if(s->es_write != NULL){ // current write io is oky ioc = s->es_write; s->es_write = NULL; spi_spin_unlock(&s->es_lock); // call current write io's callbacks ioc->ioc_iocb(s, ioc, 0); }else{ spi_spin_unlock(&s->es_lock); // write next io to sock sock_write_next(s, 1); } }else{ // call drain to notify caller s->es_cbs->data_drain(s, s->es_data); } return 0; }
static int edpnet_sock_epollin_handler(emit_t em, edp_event_t *ev){ struct edpnet_sock *s; int ready = 0; s = emit_get(em); ASSERT(s != NULL); ASSERT(s->es_status & kEDPNET_SOCK_STATUS_CONNECT); // data come in spi_spin_lock(&s->es_lock); if(!(s->es_status & kEDPNET_SOCK_STATUS_READ)){ s->es_status |= kEDPNET_SOCK_STATUS_READ; ready = 1; } spi_spin_unlock(&s->es_lock); // call user regiested callback:data_ready if(ready) s->es_cbs->data_ready(s, s->es_data); return 0; }