static void enable_read(EVENT_KERNEL *ev, ACL_EVENT_FDTABLE *fdp) { const char *myname = "enable_read"; ACL_SOCKET sockfd = ACL_VSTREAM_SOCK(fdp->stream); int err; fdp->flag &= ~EVENT_FDTABLE_FLAG_ADD_READ; fdp->flag |= EVENT_FDTABLE_FLAG_READ; if ((fdp->flag & EVENT_FDTABLE_FLAG_WRITE)) { #if (ACL_EVENTS_KERNEL_STYLE == ACL_EVENTS_STYLE_KQUEUE) EVENT_REG_ADD_READ(err, ev->event_fd, sockfd, fdp); #else EVENT_REG_MOD_RDWR(err, ev->event_fd, sockfd, fdp); #endif } else { EVENT_REG_ADD_READ(err, ev->event_fd, sockfd, fdp); } if (err < 0) { acl_msg_fatal("%s: %s: %s, err(%d), fd(%d)", myname, EVENT_REG_ADD_TEXT, acl_last_serror(), err, sockfd); } }
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_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); /* * Disallow multiple requests on the same file descriptor. * Allow duplicates of the same request. */ fdp = stream->fdp; if (fdp == NULL) fdp = event_fdtable_alloc(); if (fdp == NULL) acl_msg_fatal("%s(%d): alloc fdtable error", __FILE__, __LINE__); if (fdp->flag & EVENT_FDTABLE_FLAG_WRITE) acl_msg_panic("%s(%d)->%s: fd %d: multiple I/O request", __FILE__, __LINE__, myname, sockfd); if ((fdp->flag & EVENT_FDTABLE_FLAG_READ) == 0) { fdp->flag = EVENT_FDTABLE_FLAG_READ | EVENT_FDTABLE_FLAG_EXPT; stream->fdp = (void *) fdp; stream->nrefer++; fdp->stream = stream; fdp->listener = 0; fdp->fdidx = eventp->fdcnt; eventp->fdtabs[eventp->fdcnt] = fdp; eventp->fdcnt++; if (eventp->maxfd != ACL_SOCKET_INVALID && eventp->maxfd < sockfd) eventp->maxfd = sockfd; #ifdef USE_FDMAP acl_fdmap_add(event_thr->fdmap, sockfd, fdp); #endif EVENT_REG_ADD_READ(err, event_thr->event_fd, sockfd, fdp); if (err < 0) { acl_msg_fatal("%s: %s: %s, err(%d), fd(%d)", myname, EVENT_REG_ADD_TEXT, acl_last_strerror(ebuf, sizeof(ebuf)), err, 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->event_present + fdp->r_timeout; } else { fdp->r_ttl = 0; fdp->r_timeout = 0; } THREAD_UNLOCK(&event_thr->event.tb_mutex); /* 主要是为了减少通知次数 */ if (event_thr->event.blocked && event_thr->event.evdog && event_dog_client(event_thr->event.evdog) != stream) event_dog_notify(event_thr->event.evdog); }
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_THR *event_thr = (EVENT_KERNEL_THR *) eventp; ACL_EVENT_FDTABLE *fdp; ACL_SOCKET sockfd; int err = 0; sockfd = ACL_VSTREAM_SOCK(stream); fdp = (ACL_EVENT_FDTABLE*) stream->fdp; if (fdp == NULL) { fdp = event_fdtable_alloc(); fdp->listener = 0; fdp->stream = stream; stream->fdp = (void *) fdp; } /* 对同一连接的读写操作禁止同时进行监控 */ else if (fdp->flag & EVENT_FDTABLE_FLAG_WRITE) acl_msg_panic("%s(%d), %s: fd %d: multiple I/O request", __FILE__, __LINE__, myname, sockfd); else { fdp->listener = 0; fdp->stream = stream; } if (fdp->r_callback != callback || fdp->r_context != context) { fdp->r_callback = callback; fdp->r_context = context; } if (timeout > 0) { fdp->r_timeout = ((acl_int64) timeout) * 1000000; fdp->r_ttl = eventp->present + fdp->r_timeout; } else { fdp->r_ttl = 0; fdp->r_timeout = 0; } if ((fdp->flag & EVENT_FDTABLE_FLAG_READ) == 0) { stream->nrefer++; fdp->flag = EVENT_FDTABLE_FLAG_READ | EVENT_FDTABLE_FLAG_EXPT; THREAD_LOCK(&event_thr->event.tb_mutex); fdp->fdidx = eventp->fdcnt; eventp->fdtabs[eventp->fdcnt] = fdp; eventp->fdcnt++; #ifdef USE_FDMAP acl_fdmap_add(event_thr->fdmap, sockfd, fdp); #endif EVENT_REG_ADD_READ(err, event_thr->event_fd, sockfd, fdp); THREAD_UNLOCK(&event_thr->event.tb_mutex); if (err < 0) { acl_msg_fatal("%s: %s: %s, err(%d), fd(%d)", myname, EVENT_REG_ADD_TEXT, acl_last_serror(), err, sockfd); } } /* 主要是为了减少通知次数 */ if (event_thr->event.blocked && event_thr->event.evdog && event_dog_client(event_thr->event.evdog) != stream) event_dog_notify(event_thr->event.evdog); }