static int curl_conn_add_write(engine_t e,curl_conn_t conn){ int ret; if(!conn->flag) ret = kn_event_add(e,(handle_t)conn,EVENT_WRITE); else ret = kn_enable_write(e,(handle_t)conn); if(0 == ret && !conn->flag) conn->flag = 1; return ret; }
static int stream_socket_associate(engine_t e,handle_t h,void (*callback)(handle_t,void*,int,int)){ if(((handle_t)h)->type != KN_SOCKET) return -1; kn_socket *s = (kn_socket*)h; if(!callback) return -1; if(s->e){ kn_event_del(s->e,h); s->e = NULL; } if(h->status == SOCKET_ESTABLISH){ kn_set_noblock(h->fd,0); #ifdef _LINUX kn_event_add(e,h,EVENT_WRITE | EVENT_READ); #elif _BSD kn_event_add(e,h,EVENT_WRITE); kn_event_add(e,h,EVENT_READ); //kn_disable_read(e,h); //kn_disable_write(e,h); #else return -1; #endif }else if(h->status == SOCKET_LISTENING){ #ifdef _LINUX kn_event_add(e,h,EVENT_READ); #elif _BSD kn_event_add(e,EVENT_READ); #else return -1; #endif }else if(h->status == SOCKET_CONNECTING){ #ifdef _LINUX kn_event_add(e,h,EVENT_WRITE | EVENT_READ); #elif _BSD kn_event_add(e,h,EVENT_WRITE); kn_event_add(e,h,EVENT_READ); #else return -1; #endif } else{ return -1; } s->callback = callback; s->e = e; return 0; }
int kn_chrdev_read(handle_t h,st_io *req){ if(((handle_t)h)->type != KN_CHRDEV) return -1; if(((handle_t)h)->status == KN_CHRDEV_RELEASE) return -1; kn_chr_dev *r = (kn_chr_dev*)h; if(!(r->events & EPOLLIN)){ int ret = 0; if(r->events == 0){ ret = kn_event_add(r->e,(handle_t)r,EPOLLIN); }else ret = kn_event_mod(r->e,(handle_t)r,EPOLLIN); if(ret == 0) r->events = EPOLLIN; else return -1; } kn_list_pushback(&r->pending_read,(kn_list_node*)req); return 0; }