void SelEpolKqEvPrt::initialize(SOCKET sockfd, const int& timeout) { this->timeoutMilis = timeout; this->sockfd = sockfd; if(sockfd<=0) { listenerMode = false; sockfd = 0; } else { listenerMode = true; } curfds = 1; #if defined(USE_WIN_IOCP) initIOCP(); #elif defined(USE_MINGW_SELECT) fdMax = sockfd; FD_ZERO(&readfds); FD_ZERO(&master); #elif defined(USE_SELECT) fdsetSize = MAXDESCRIPTORS/FD_SETSIZE; fdMax = sockfd; for (int var = 0; var < fdsetSize; ++var) { FD_ZERO(&readfds[var]); FD_ZERO(&master[var]); } #elif defined USE_EPOLL epoll_handle = epoll_create(MAXDESCRIPTORS); memset(&ev, 0, sizeof(ev)); #elif defined USE_KQUEUE kq = kqueue(); if (kq == -1) { perror("kqueue"); } #elif defined USE_DEVPOLL if((dev_poll_fd = open("/dev/poll", O_RDWR)) <0) { perror("devpoll"); } if (fcntl(dev_poll_fd, F_SETFD, FD_CLOEXEC) < 0) { perror("devpoll fcntl"); } #elif defined USE_EVPORT if ((port = port_create()) < 0) { perror("port_create"); } #elif defined USE_POLL nfds=1; polled_fds = (struct pollfd *)calloc(1, nfds*sizeof(struct pollfd)); polled_fds->fd = descriptor; polled_fds->events = POLLIN | POLLPRI; return; #endif #if !defined(USE_WIN_IOCP) if(sockfd>0)registerForEvent(sockfd); #endif }
bool TCPServer::start(unsigned short port) { if(!_isStarted) { if(initIOCP()) { if(createListenerSocket(port)) { _isStarted = true; } } } return _isStarted; }