static void ev_io_on_request(struct ev_loop* mainloop, ev_io* watcher, const int events) { int client_fd; struct sockaddr_in sockaddr; socklen_t addrlen; addrlen = sizeof(struct sockaddr_in); client_fd = accept(watcher->fd, (struct sockaddr*)&sockaddr, &addrlen); if(client_fd < 0) { DBG("Could not accept() client: errno %d", errno); return; } int flags = fcntl(client_fd, F_GETFL, 0); if(fcntl(client_fd, F_SETFL, (flags < 0 ? 0 : flags) | O_NONBLOCK) == -1) { DBG("Could not set_nonblocking() client %d: errno %d", client_fd, errno); return; } GIL_LOCK(0); Request* request = Request_new(client_fd, inet_ntoa(sockaddr.sin_addr)); GIL_UNLOCK(0); DBG_REQ(request, "Accepted client %s:%d on fd %d", inet_ntoa(sockaddr.sin_addr), ntohs(sockaddr.sin_port), client_fd); ev_io_init(&request->ev_watcher, &ev_io_on_read, client_fd, EV_READ); ev_io_start(mainloop, &request->ev_watcher); }
static void ev_io_on_request(struct ev_loop* mainloop, ev_io* watcher, const int events) { int client_fd; if((client_fd = accept(watcher->fd, NULL, NULL)) < 0) { DBG("Could not accept() client: errno %d", errno); return; } if(!set_nonblocking(client_fd)) { DBG("Could not set_nonnblocking() client: errno %d", errno); return; } Request* request = Request_new(client_fd); ev_io_init(&request->ev_watcher, &ev_io_on_read, client_fd, EV_READ); ev_io_start(mainloop, &request->ev_watcher); }
// Public void Request_cb(struct evhttp_request *req, void * data) { Request_T R = Request_new(req, data); Request_handle(R); Request_free(&R); }