static void event_enable_read(ACL_EVENT *eventp, ACL_VSTREAM *stream, int timeout, ACL_EVENT_NOTIFY_RDWR callback, void *context) { const char *myname = "event_enable_read"; EVENT_KERNEL *ev = (EVENT_KERNEL *) eventp; ACL_EVENT_FDTABLE *fdp = (ACL_EVENT_FDTABLE *) stream->fdp; ACL_SOCKET sockfd = ACL_VSTREAM_SOCK(stream); if (fdp == NULL) { fdp = event_fdtable_alloc(); fdp->flag = EVENT_FDTABLE_FLAG_ADD_READ | EVENT_FDTABLE_FLAG_EXPT; fdp->stream = stream; acl_ring_append(&ev->fdp_delay_list, &fdp->delay_entry); fdp->flag |= EVENT_FDTABLE_FLAG_DELAY_OPER; stream->fdp = (void *) fdp; /* 添加流关闭时的回调函数 */ acl_vstream_add_close_handle(stream, stream_on_close, eventp); } else if ((fdp->flag & EVENT_FDTABLE_FLAG_ADD_READ)) { goto END; } else if ((fdp->flag & EVENT_FDTABLE_FLAG_DEL_READ)) { /* 停止禁止读监听过程 */ acl_assert((fdp->flag & EVENT_FDTABLE_FLAG_READ)); /* 重新启用读监听过程, 因为之前的过程是正在拆除读监听过程但 * 还没有正式拆除,所以只需要清除拆除标志位即可 */ fdp->flag &= ~EVENT_FDTABLE_FLAG_DEL_READ; } else if (!(fdp->flag & EVENT_FDTABLE_FLAG_READ)) { fdp->flag |= EVENT_FDTABLE_FLAG_ADD_READ; if (!(fdp->flag & EVENT_FDTABLE_FLAG_DELAY_OPER)) { acl_ring_append(&ev->fdp_delay_list, &fdp->delay_entry); fdp->flag |= EVENT_FDTABLE_FLAG_DELAY_OPER; } } END: if (fdp->fdidx == -1) { fdp->fdidx = eventp->fdcnt; eventp->fdtabs[eventp->fdcnt++] = fdp; } if (eventp->maxfd != ACL_SOCKET_INVALID && eventp->maxfd < sockfd) eventp->maxfd = sockfd; if (fdp->r_callback != callback || fdp->r_context != context) { fdp->r_callback = callback; fdp->r_context = context; } if (timeout > 0) { fdp->r_timeout = timeout * 1000000; fdp->r_ttl = eventp->present + fdp->r_timeout; } else { fdp->r_ttl = 0; fdp->r_timeout = 0; } }
static void event_enable_write(ACL_EVENT *eventp, ACL_VSTREAM *stream, int timeout, ACL_EVENT_NOTIFY_RDWR callback, void *context) { EVENT_KERNEL *ev = (EVENT_KERNEL *) eventp; ACL_EVENT_FDTABLE *fdp = (ACL_EVENT_FDTABLE *) stream->fdp; ACL_SOCKET sockfd = ACL_VSTREAM_SOCK(stream); if (fdp == NULL) { fdp = event_fdtable_alloc(); fdp->flag = EVENT_FDTABLE_FLAG_ADD_WRITE | EVENT_FDTABLE_FLAG_EXPT; fdp->stream = stream; acl_ring_append(&ev->fdp_delay_list, &fdp->delay_entry); fdp->flag |= EVENT_FDTABLE_FLAG_DELAY_OPER; stream->fdp = (void *) fdp; /* 添加流关闭时的回调函数 */ acl_vstream_add_close_handle(stream, stream_on_close, eventp); #ifdef USE_FDMAP acl_fdmap_add(ev->fdmap, sockfd, fdp); #endif } else if ((fdp->flag & EVENT_FDTABLE_FLAG_ADD_WRITE)) { goto END; } else if ((fdp->flag & EVENT_FDTABLE_FLAG_DEL_WRITE)) { acl_assert((fdp->flag & EVENT_FDTABLE_FLAG_WRITE)); fdp->flag &= ~EVENT_FDTABLE_FLAG_DEL_WRITE; } else if (!(fdp->flag & EVENT_FDTABLE_FLAG_WRITE)) { fdp->flag |= EVENT_FDTABLE_FLAG_ADD_WRITE; if (!(fdp->flag & EVENT_FDTABLE_FLAG_DELAY_OPER)) { acl_ring_append(&ev->fdp_delay_list, &fdp->delay_entry); fdp->flag |= EVENT_FDTABLE_FLAG_DELAY_OPER; } } END: if (fdp->fdidx == -1) { fdp->fdidx = eventp->fdcnt; eventp->fdtabs[eventp->fdcnt++] = fdp; } if (eventp->maxfd != ACL_SOCKET_INVALID && eventp->maxfd < sockfd) eventp->maxfd = sockfd; if (fdp->w_callback != callback || fdp->w_context != context) { fdp->w_callback = callback; fdp->w_context = context; } if (timeout > 0) { fdp->w_timeout = timeout * 1000000; fdp->w_ttl = eventp->present + fdp->w_timeout; } else { fdp->w_ttl = 0; fdp->w_timeout = 0; } }
void acl_xml_node_append(ACL_XML_NODE *node1, ACL_XML_NODE *node2) { /* if (node1->parent) acl_xml_node_add_child(node1->parent, node2); else */ acl_ring_append(&node1->node, &node2->node); node2->parent = node1->parent; }
static void __create_ring(int flag, int size) { MY_TYPE *my_type; int i; for (i = 0; i < size; i++) { my_type = acl_mycalloc(1, sizeof(MY_TYPE)); snprintf(my_type->name, sizeof(my_type->name), "name:%d", i); snprintf(my_type->value, sizeof(my_type->value), "value:%d", i); my_type->i = i; if (flag) acl_ring_prepend(&__ring_header, &my_type->ring_entry); else acl_ring_append(&__ring_header, &my_type->ring_entry); } }
static void event_disable_write(ACL_EVENT *eventp, ACL_VSTREAM *stream) { const char *myname = "event_disable_write"; EVENT_KERNEL *ev = (EVENT_KERNEL *) eventp; ACL_EVENT_FDTABLE *fdp = (ACL_EVENT_FDTABLE *) stream->fdp; if (fdp == NULL) { acl_msg_warn("%s(%d): fdp null", myname, __LINE__); return; } if (fdp->fdidx < 0 || fdp->fdidx >= eventp->fdcnt) { acl_msg_warn("%s(%d): sockfd(%d)'s fdidx(%d) invalid", myname, __LINE__, ACL_VSTREAM_SOCK(stream), fdp->fdidx); return; } if ((fdp->flag & EVENT_FDTABLE_FLAG_DEL_WRITE)) { return; } if ((fdp->flag & EVENT_FDTABLE_FLAG_ADD_WRITE)) { fdp->flag &= ~EVENT_FDTABLE_FLAG_ADD_WRITE; goto DEL_WRITE_TAG; } if (!(fdp->flag & EVENT_FDTABLE_FLAG_WRITE)) { acl_msg_warn("%s(%d): sockfd(%d) not be set", myname, __LINE__, ACL_VSTREAM_SOCK(stream)); return; } fdp->flag |= EVENT_FDTABLE_FLAG_DEL_WRITE; if (!(fdp->flag & EVENT_FDTABLE_FLAG_DELAY_OPER)) { acl_ring_append(&ev->fdp_delay_list, &fdp->delay_entry); fdp->flag |= EVENT_FDTABLE_FLAG_DELAY_OPER; } DEL_WRITE_TAG: fdp->w_ttl = 0; fdp->w_timeout = 0; fdp->w_callback = NULL; fdp->event_type &= ~(ACL_EVENT_WRITE | ACL_EVENT_CONNECT); if ((fdp->flag & EVENT_FDTABLE_FLAG_READ) || (fdp->flag & EVENT_FDTABLE_FLAG_ADD_READ)) { return; } if (eventp->maxfd == ACL_VSTREAM_SOCK(stream)) eventp->maxfd = ACL_SOCKET_INVALID; if (fdp->fdidx < --eventp->fdcnt) { eventp->fdtabs[fdp->fdidx] = eventp->fdtabs[eventp->fdcnt]; eventp->fdtabs[fdp->fdidx]->fdidx = fdp->fdidx; } fdp->fdidx = -1; if (fdp->fdidx_ready >= 0 && fdp->fdidx_ready < eventp->fdcnt_ready && eventp->fdtabs_ready[fdp->fdidx_ready] == fdp) { eventp->fdtabs_ready[fdp->fdidx_ready] = NULL; } fdp->fdidx_ready = -1; }