static void enable_write(EVENT_KERNEL *ev, ACL_EVENT_FDTABLE *fdp) { const char *myname = "enable_write"; ACL_SOCKET sockfd = ACL_VSTREAM_SOCK(fdp->stream); int err; fdp->flag &= ~EVENT_FDTABLE_FLAG_ADD_WRITE; fdp->flag |= EVENT_FDTABLE_FLAG_WRITE; if ((fdp->flag & EVENT_FDTABLE_FLAG_READ)) { #if (ACL_EVENTS_KERNEL_STYLE == ACL_EVENTS_STYLE_KQUEUE) EVENT_REG_ADD_WRITE(err, ev->event_fd, sockfd, fdp); #else EVENT_REG_MOD_RDWR(err, ev->event_fd, sockfd, fdp); #endif } else { EVENT_REG_ADD_WRITE(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_write(ACL_EVENT *eventp, ACL_VSTREAM *stream, int timeout, ACL_EVENT_NOTIFY_RDWR callback, void *context) { const char *myname = "event_enable_write"; 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->flag & EVENT_FDTABLE_FLAG_READ) acl_msg_panic("%s(%d)->%s: fd %d: multiple I/O request", __FILE__, __LINE__, myname, sockfd); if ((fdp->flag & EVENT_FDTABLE_FLAG_WRITE) == 0) { fdp->flag = EVENT_FDTABLE_FLAG_WRITE | 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_WRITE(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->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->event_present + fdp->w_timeout; } else { fdp->w_ttl = 0; fdp->w_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_write(ACL_EVENT *eventp, ACL_VSTREAM *stream, int timeout, ACL_EVENT_NOTIFY_RDWR callback, void *context) { const char *myname = "event_enable_write"; 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_READ) 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->w_callback != callback || fdp->w_context != context) { fdp->w_callback = callback; fdp->w_context = context; } if (timeout > 0) { fdp->w_timeout = ((acl_int64) timeout) * 1000000; fdp->w_ttl = eventp->present + fdp->w_timeout; } else { fdp->w_ttl = 0; fdp->w_timeout = 0; } if ((fdp->flag & EVENT_FDTABLE_FLAG_WRITE) == 0) { fdp->flag = EVENT_FDTABLE_FLAG_WRITE | EVENT_FDTABLE_FLAG_EXPT; stream->nrefer++; 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_WRITE(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); }