static int disable_write(EVENT_KERNEL *ev, ACL_EVENT_FDTABLE *fdp) { const char *myname = "disable_write"; ACL_VSTREAM *stream = fdp->stream; ACL_SOCKET sockfd = ACL_VSTREAM_SOCK(stream); int err, ret = 0; fdp->flag &= ~EVENT_FDTABLE_FLAG_DEL_WRITE; fdp->flag &= ~EVENT_FDTABLE_FLAG_WRITE; fdp->event_type &= ~(ACL_EVENT_WRITE | ACL_EVENT_CONNECT); if ((fdp->flag & EVENT_FDTABLE_FLAG_READ)) { #if (ACL_EVENTS_KERNEL_STYLE == ACL_EVENTS_STYLE_KQUEUE) EVENT_REG_DEL_WRITE(err, ev->event_fd, sockfd); #else EVENT_REG_MOD_READ(err, ev->event_fd, sockfd, fdp); #endif } else { #ifdef USE_FDMAP acl_fdmap_del(ev->fdmap, sockfd); #endif #ifdef EVENT_REG_DEL_BOTH EVENT_REG_DEL_BOTH(err, ev->event_fd, sockfd); #else EVENT_REG_DEL_WRITE(err, ev->event_fd, sockfd); #endif ret = 1; } if (err < 0) { acl_msg_fatal("%s: %s: %s, err(%d), fd(%d), ret(%d)", myname, EVENT_REG_DEL_TEXT, acl_last_serror(), err, sockfd, ret); } return (ret); }
static void event_disable_readwrite(ACL_EVENT *eventp, ACL_VSTREAM *stream) { const char *myname = "event_disable_readwrite"; EVENT_KERNEL *ev = (EVENT_KERNEL *) eventp; ACL_SOCKET sockfd = ACL_VSTREAM_SOCK(stream); ACL_EVENT_FDTABLE *fdp = (ACL_EVENT_FDTABLE *) stream->fdp; int err = 0; if (fdp == NULL) { return; } if (fdp->flag == 0 || fdp->fdidx < 0 || fdp->fdidx >= eventp->fdcnt) { acl_msg_warn("%s(%d): sockfd(%d) no set, fdp no null", myname, __LINE__, sockfd); event_fdtable_free(fdp); stream->fdp = NULL; return; } if (eventp->maxfd == sockfd) 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; #ifdef EVENT_REG_DEL_BOTH EVENT_REG_DEL_BOTH(err, ev->event_fd, sockfd); #else if (fdp->flag & EVENT_FDTABLE_FLAG_READ) { EVENT_REG_DEL_READ(err, ev->event_fd, sockfd); } if (fdp->flag & EVENT_FDTABLE_FLAG_WRITE) { EVENT_REG_DEL_WRITE(err, ev->event_fd, sockfd); } #endif if (err < 0) { acl_msg_fatal("%s: %s: %s", myname, EVENT_REG_DEL_TEXT, acl_last_serror()); } #ifdef USE_FDMAP acl_fdmap_del(ev->fdmap, sockfd); #endif 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; event_fdtable_free(fdp); stream->fdp = NULL; }
static void event_disable_write(ACL_EVENT *eventp, ACL_VSTREAM *stream) { const char *myname = "event_disable_write"; EVENT_POLL *ev = (EVENT_POLL *) eventp; ACL_SOCKET sockfd = ACL_VSTREAM_SOCK(stream); 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__, sockfd, fdp->fdidx); return; } if (!(fdp->flag & EVENT_FDTABLE_FLAG_WRITE)) { acl_msg_warn("%s(%d): sockfd(%d) not be set", myname, __LINE__, sockfd); return; } fdp->w_ttl = 0; fdp->w_timeout = 0; fdp->w_callback = NULL; fdp->event_type &= ~(ACL_EVENT_WRITE | ACL_EVENT_CONNECT); fdp->flag &= ~EVENT_FDTABLE_FLAG_WRITE; if ((fdp->flag & EVENT_FDTABLE_FLAG_READ)) { ev->fds[fdp->fdidx].events = POLLIN | POLLHUP | POLLERR; return; } if (eventp->maxfd == sockfd) eventp->maxfd = ACL_SOCKET_INVALID; if (fdp->fdidx < --eventp->fdcnt) { ev->fds[fdp->fdidx] = ev->fds[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->ready_cnt && eventp->ready[fdp->fdidx_ready] == fdp) { eventp->ready[fdp->fdidx_ready] = NULL; } fdp->fdidx_ready = -1; acl_fdmap_del(ev->fdmap, sockfd); }
static void event_disable_readwrite(ACL_EVENT *eventp, ACL_VSTREAM *stream) { const char *myname = "event_disable_readwrite"; EVENT_POLL *ev = (EVENT_POLL *) eventp; ACL_EVENT_FDTABLE *fdp = (ACL_EVENT_FDTABLE *) stream->fdp; ACL_SOCKET sockfd = ACL_VSTREAM_SOCK(stream); if (fdp == NULL) { return; } if (fdp->flag == 0 || fdp->fdidx < 0 || fdp->fdidx >= eventp->fdcnt) { acl_msg_warn("%s(%d): sockfd(%d) no set, fdp no null", myname, __LINE__, sockfd); acl_fdmap_del(ev->fdmap, sockfd); event_fdtable_free(fdp); stream->fdp = NULL; return; } if (eventp->maxfd == sockfd) eventp->maxfd = ACL_SOCKET_INVALID; if (fdp->fdidx < --eventp->fdcnt) { ev->fds[fdp->fdidx] = ev->fds[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->ready_cnt && eventp->ready[fdp->fdidx_ready] == fdp) { eventp->ready[fdp->fdidx_ready] = NULL; } fdp->fdidx_ready = -1; acl_fdmap_del(ev->fdmap, sockfd); event_fdtable_free(fdp); stream->fdp = NULL; }
static void event_disable_readwrite(ACL_EVENT *eventp, ACL_VSTREAM *stream) { const char *myname = "event_disable_readwrite"; EVENT_POLL_THR *event_thr = (EVENT_POLL_THR *) eventp; ACL_EVENT_FDTABLE *fdp; ACL_SOCKET sockfd; sockfd = ACL_VSTREAM_SOCK(stream); fdp = (ACL_EVENT_FDTABLE *) stream->fdp; if (fdp == NULL) { acl_msg_error("%s(%d): fdp null", myname, __LINE__); return; } if ((fdp->flag & (EVENT_FDTABLE_FLAG_READ | EVENT_FDTABLE_FLAG_WRITE)) == 0) { acl_msg_error("%s(%d): sockfd(%d) not be set", myname, __LINE__, sockfd); return; } if (fdp->fdidx == -1) acl_msg_fatal("%s(%d): fdidx(%d) invalid", myname, __LINE__, fdp->fdidx); THREAD_LOCK(&event_thr->event.tb_mutex); if (eventp->maxfd == sockfd) eventp->maxfd = ACL_SOCKET_INVALID; if (eventp->fdtabs[fdp->fdidx] != fdp) acl_msg_fatal("%s(%d): fdidx(%d)'s fdp invalid", myname, __LINE__, fdp->fdidx); if (fdp->fdidx < --eventp->fdcnt) { eventp->fdtabs[fdp->fdidx] = eventp->fdtabs[eventp->fdcnt]; eventp->fdtabs[fdp->fdidx]->fdidx = fdp->fdidx; event_thr->fds[fdp->fdidx] = event_thr->fds[eventp->fdcnt]; } acl_fdmap_del(event_thr->fdmap, sockfd); THREAD_UNLOCK(&event_thr->event.tb_mutex); if (fdp->flag & EVENT_FDTABLE_FLAG_READ) stream->nrefer--; if (fdp->flag & EVENT_FDTABLE_FLAG_WRITE) stream->nrefer--; event_fdtable_reset(fdp); }
static void stream_on_close(ACL_VSTREAM *stream, void *arg) { EVENT_POLL *ev = (EVENT_POLL*) arg; ACL_EVENT_FDTABLE *fdp = (ACL_EVENT_FDTABLE*) stream->fdp; ACL_SOCKET sockfd = ACL_VSTREAM_SOCK(stream); int ret = 0; if (fdp == NULL) return; if ((fdp->flag & EVENT_FDTABLE_FLAG_READ) && (fdp->flag & EVENT_FDTABLE_FLAG_WRITE)) { ret = 1; } else if ((fdp->flag & EVENT_FDTABLE_FLAG_READ)) { ret = 2; } else if ((fdp->flag & EVENT_FDTABLE_FLAG_WRITE)) { ret = 3; } if (ret) { acl_fdmap_del(ev->fdmap, sockfd); } if (ev->event.maxfd == ACL_VSTREAM_SOCK(fdp->stream)) ev->event.maxfd = ACL_SOCKET_INVALID; if (fdp->fdidx >= 0 && fdp->fdidx < --ev->event.fdcnt) { ev->fds[fdp->fdidx] = ev->fds[ev->event.fdcnt]; ev->event.fdtabs[fdp->fdidx] = ev->event.fdtabs[ev->event.fdcnt]; ev->event.fdtabs[fdp->fdidx]->fdidx = fdp->fdidx; } fdp->fdidx = -1; if (fdp->fdidx_ready >= 0 && fdp->fdidx_ready < ev->event.ready_cnt && ev->event.ready[fdp->fdidx_ready] == fdp) { ev->event.ready[fdp->fdidx_ready] = NULL; } fdp->fdidx_ready = -1; event_fdtable_free(fdp); stream->fdp = NULL; }
static void stream_on_close(ACL_VSTREAM *stream, void *arg) { const char *myname = "stream_on_close"; EVENT_KERNEL *ev = (EVENT_KERNEL*) arg; ACL_EVENT_FDTABLE *fdp = (ACL_EVENT_FDTABLE*) stream->fdp; ACL_SOCKET sockfd = ACL_VSTREAM_SOCK(stream); int err = 0, ret = 0; if (fdp == NULL) acl_msg_fatal("%s(%d): fdp null, sockfd(%d)", myname, __LINE__, sockfd); #ifdef EVENT_REG_DEL_BOTH if ((fdp->flag & EVENT_FDTABLE_FLAG_READ) || (fdp->flag & EVENT_FDTABLE_FLAG_WRITE)) { # ifndef EVENT_AUTO_DEL EVENT_REG_DEL_BOTH(err, ev->event_fd, sockfd); ret = 1; # else ret = 2; # endif } #else if ((fdp->flag & EVENT_FDTABLE_FLAG_READ) && (fdp->flag & EVENT_FDTABLE_FLAG_WRITE)) { # ifndef EVENT_AUTO_DEL EVENT_REG_DEL_READ(err, ev->event_fd, sockfd); EVENT_REG_DEL_WRITE(err, ev->event_fd, sockfd); ret = 3; # else ret = 4; # endif } else if ((fdp->flag & EVENT_FDTABLE_FLAG_READ)) { # ifndef EVENT_AUTO_DEL EVENT_REG_DEL_READ(err, ev->event_fd, sockfd); ret = 5; # else ret = 6; # endif } else if ((fdp->flag & EVENT_FDTABLE_FLAG_WRITE)) { # ifndef EVENT_AUTO_DEL EVENT_REG_DEL_WRITE(err, ev->event_fd, sockfd); # else ret = 7; # endif ret = 8; } #endif if (err < 0) { acl_msg_fatal("%s: %s: %s, err(%d), fd(%d), ret(%d)", myname, EVENT_REG_DEL_TEXT, acl_last_serror(), err, sockfd, ret); } if ((fdp->flag & EVENT_FDTABLE_FLAG_DELAY_OPER)) { fdp->flag &= ~EVENT_FDTABLE_FLAG_DELAY_OPER; acl_ring_detach(&fdp->delay_entry); } if (ret) { #ifdef USE_FDMAP acl_fdmap_del(ev->fdmap, sockfd); #endif } if (ev->event.maxfd == ACL_VSTREAM_SOCK(fdp->stream)) ev->event.maxfd = ACL_SOCKET_INVALID; if (fdp->fdidx >= 0 && fdp->fdidx < --ev->event.fdcnt) { ev->event.fdtabs[fdp->fdidx] = ev->event.fdtabs[ev->event.fdcnt]; ev->event.fdtabs[fdp->fdidx]->fdidx = fdp->fdidx; } fdp->fdidx = -1; if (fdp->fdidx_ready >= 0 && fdp->fdidx_ready < ev->event.fdcnt_ready && ev->event.fdtabs_ready[fdp->fdidx_ready] == fdp) { ev->event.fdtabs_ready[fdp->fdidx_ready] = NULL; } fdp->fdidx_ready = -1; event_fdtable_free(fdp); stream->fdp = NULL; }
static void event_disable_readwrite(ACL_EVENT *eventp, ACL_VSTREAM *stream) { const char *myname = "event_disable_readwrite"; EVENT_KERNEL_THR *event_thr = (EVENT_KERNEL_THR *) eventp; ACL_EVENT_FDTABLE *fdp; ACL_SOCKET sockfd; char ebuf[256]; int err = 0; sockfd = ACL_VSTREAM_SOCK(stream); THREAD_LOCK(&event_thr->event.tb_mutex); fdp = (ACL_EVENT_FDTABLE *) stream->fdp; if (fdp == NULL) { acl_msg_error("%s(%d): fdp null", myname, __LINE__); THREAD_UNLOCK(&event_thr->event.tb_mutex); return; } if ((fdp->flag & (EVENT_FDTABLE_FLAG_READ | EVENT_FDTABLE_FLAG_WRITE)) == 0) { acl_msg_error("%s(%d): sockfd(%d) not be set", myname, __LINE__, sockfd); THREAD_UNLOCK(&event_thr->event.tb_mutex); return; } if (fdp->fdidx == -1) acl_msg_fatal("%s(%d): fdidx(%d) invalid", myname, __LINE__, fdp->fdidx); if (eventp->maxfd == sockfd) eventp->maxfd = ACL_SOCKET_INVALID; if (eventp->fdtabs[fdp->fdidx] == fdp) { if (fdp->fdidx < --eventp->fdcnt) { eventp->fdtabs[fdp->fdidx] = eventp->fdtabs[eventp->fdcnt]; eventp->fdtabs[fdp->fdidx]->fdidx = fdp->fdidx; } } else acl_msg_fatal("%s(%d): fdidx(%d)'s fdp invalid", myname, __LINE__, fdp->fdidx); #ifdef EVENT_REG_DEL_BOTH EVENT_REG_DEL_BOTH(err, event_thr->event_fd, sockfd); #else if (fdp->flag & EVENT_FDTABLE_FLAG_READ) { EVENT_REG_DEL_READ(err, event_thr->event_fd, sockfd); } if (fdp->flag & EVENT_FDTABLE_FLAG_WRITE) { EVENT_REG_DEL_WRITE(err, event_thr->event_fd, sockfd); } #endif if (fdp->flag & EVENT_FDTABLE_FLAG_READ) { stream->nrefer--; } if (fdp->flag & EVENT_FDTABLE_FLAG_WRITE) { stream->nrefer--; } if (err < 0) { acl_msg_fatal("%s: %s: %s", myname, EVENT_REG_DEL_TEXT, acl_last_strerror(ebuf, sizeof(ebuf))); } #ifdef USE_FDMAP acl_fdmap_del(event_thr->fdmap, sockfd); #endif 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; } event_fdtable_free(fdp); stream->fdp = NULL; THREAD_UNLOCK(&event_thr->event.tb_mutex); }