static int event_client_monitor(struct gridd_client_pool_s *pool, struct event_client_s *mc) { int fd, rc, interest; struct epoll_event ev; EXTRA_ASSERT(pool != NULL); EXTRA_ASSERT(mc != NULL); EXTRA_ASSERT(mc->client != NULL); memset(&ev, 0, sizeof(ev)); interest = gridd_client_interest(mc->client); if (interest & CLIENT_RD) ev.events |= EPOLLIN; if (interest & CLIENT_WR) ev.events |= EPOLLOUT; EXTRA_ASSERT(ev.events != 0); ev.events |= (EPOLLHUP|EPOLLERR|EPOLLONESHOT); ev.data.fd = fd = gridd_client_fd(mc->client); EXTRA_ASSERT(fd >= 0); rc = epoll_ctl(pool->fdmon, EPOLL_CTL_ADD, fd, &ev); if (rc < 0) { pool->active_clients[fd] = NULL; GRID_WARN("MONITOR error: (%d) %s", errno, strerror(errno)); return 0; } pool->active_count ++; pool->active_clients[fd] = mc; return 1; }
static inline int _client_to_pollfd(struct client_s *client, struct pollfd *pfd) { int fd = gridd_client_fd(client); int interest = gridd_client_interest(client); if (fd < 0 || !interest) return 0; pfd->fd = fd; pfd->events = 0; pfd->revents = 0; if (interest & CLIENT_WR) pfd->events = POLLOUT; if (interest & CLIENT_RD) pfd->events = POLLIN; return 1; }