EventLoop::EventLoop(): nSize(10240), nMaxfd(-1), nMaxWaitTime(0), bRunning(false), pTickHead(NULL), pTickTail(NULL), pBeforeData(NULL) { EV_CB_INIT(cbBefore); pEvents = (IOEvent*)zmalloc(sizeof(IOEvent) * nSize); pFireds = (IOFired*)zmalloc(sizeof(IOFired) * nSize); for (int i = 0; i < nSize; i++){ pEvents[i].mask = EV_IO_NONE; } #if HAVE_EPOLL pPoll = new EventEPoll(this); #elif HAVE_KQUEUE pPoll = new EventKqueue(this); #else pPoll = new EventSelect(this); #endif }
Connection::Connection(EventLoop *loop, int fd): pEventLoop(loop), sSocket(fd), bWriting(false), bClosed(false), pData(NULL), nPort(0), nTimeout(0), nTimerId(0), nError(0) { EV_CB_INIT(cbRead); EV_CB_INIT(cbClose); EV_CB_INIT(cbWriteComplete); EV_CB_INIT(cbConnect); memset(sHost, 0, sizeof(sHost)); if(sSocket.isValid()){ sSocket.setNonBlock(); initSocket(); } }