int swReactor_setHandle(swReactor *reactor, int _fdtype, swReactor_handle handle) { int fdtype = swReactor_fdtype(_fdtype); if (fdtype >= SW_MAX_FDTYPE) { swWarn("fdtype > SW_MAX_FDTYPE[%d]", SW_MAX_FDTYPE); return SW_ERR; } if (swReactor_event_read(_fdtype)) { reactor->handle[fdtype] = handle; } else if (swReactor_event_write(_fdtype)) { reactor->write_handle[fdtype] = handle; } else if (swReactor_event_error(_fdtype)) { reactor->error_handle[fdtype] = handle; } else { swWarn("unknow fdtype"); return SW_ERR; } return SW_OK; }
static int swReactorPoll_add(swReactor *reactor, int fd, int fdtype) { swReactorPoll *object = reactor->object; int cur = reactor->event_num; if (reactor->event_num == object->max_fd_num) { swError("too many connection, more than %d", object->max_fd_num); return SW_ERR; } object->fds[cur].fdtype = swReactor_fdtype(fdtype); object->events[cur].fd = fd; //object->events[cur].events = POLLRDHUP; object->events[cur].events = 0; if (swReactor_event_read(fdtype)) { object->events[cur].events |= POLLIN; } if (swReactor_event_write(fdtype)) { object->events[cur].events |= POLLOUT; } if (swReactor_event_error(fdtype)) { object->events[cur].events |= POLLHUP; } reactor->event_num++; return SW_OK; }
static int swReactorPoll_add(swReactor *reactor, int fd, int fdtype) { if (swReactorPoll_exist(reactor, fd)) { swWarn("fd#%d is already exists.", fd); return SW_ERR; } if (swReactor_add(reactor, fd, fdtype) < 0) { return SW_ERR; } swReactorPoll *object = reactor->object; int cur = reactor->event_num; if (reactor->event_num == object->max_fd_num) { swWarn("too many connection, more than %d", object->max_fd_num); return SW_ERR; } swTrace("fd=%d, fdtype=%d", fd, fdtype); object->fds[cur].fdtype = swReactor_fdtype(fdtype); object->events[cur].fd = fd; object->events[cur].events = 0; if (swReactor_event_read(fdtype)) { object->events[cur].events |= POLLIN; } if (swReactor_event_write(fdtype)) { object->events[cur].events |= POLLOUT; } if (swReactor_event_error(fdtype)) { object->events[cur].events |= POLLHUP; } reactor->event_num++; return SW_OK; }
SWINLINE static int swReactorEpoll_event_set(int fdtype) { uint32_t flag = 0; #ifdef SW_USE_EPOLLET flag = EPOLLET; #endif if (swReactor_event_read(fdtype)) { flag |= EPOLLIN; } if (swReactor_event_write(fdtype)) { flag |= EPOLLOUT; } if (swReactor_event_error(fdtype)) { flag |= (EPOLLRDHUP | EPOLLHUP | EPOLLERR); } return flag; }