HRESULT CTestPolling::TestInit(size_t sizePolling, size_t sizePipeArray) { HRESULT hr = S_OK; TestUnInit(); ChkA(CreatePollingInstance(_polltype, sizePolling, _spPolling.GetPointerPointer())); for (size_t index = 0; index < sizePipeArray; index++) { ChkA(CreateAndAddPipe()); } Cleanup: return hr; }
HRESULT CTCPStunThread::Init(const TransportAddressSet& tsaListen, const TransportAddressSet& tsaHandler, IStunAuth* pAuth, int maxConnections, boost::shared_ptr<RateLimiter>& spLimiter) { HRESULT hr = S_OK; int ret; int countListen = 0; int countHandler = 0; // we shouldn't be initialized at this point ChkIfA(_pipe[0] != -1, E_UNEXPECTED); ChkIfA(_fThreadIsValid, E_UNEXPECTED); _maxConnections = (maxConnections > 0) ? maxConnections : c_MaxNumberOfConnectionsDefault; // Max sure we didn't accidently pass in anything crazy ChkIfA(_maxConnections >= 100000, E_INVALIDARG); for (size_t i = 0; i < ARRAYSIZE(_tsa.set); i++) { countListen += tsaListen.set[i].fValid ? 1 : 0; countHandler += tsaHandler.set[i].fValid ? 1 : 0; } ChkIfA(countListen == 0, E_INVALIDARG); ChkIfA(countHandler == 0, E_INVALIDARG); _tsaListen = tsaListen; _tsa = tsaHandler; _spAuth.Attach(pAuth); ChkA(CreateListenSockets()); ChkA(CreatePipes()); // +5 for listening sockets and pipe ChkA(CreatePollingInstance(IPOLLING_TYPE_BEST, (size_t)(_maxConnections + 5), _spPolling.GetPointerPointer())); // add listen socket to epoll ASSERT(_fListenSocketsOnEpoll == false); ChkA(SetListenSocketsOnEpoll(true)); // add read end of pipe to epoll so we can get notified of when a signal to exit has occurred ChkA(_spPolling->Add(_pipe[0], EPOLL_PIPE_EVENT_SET)); ret = _hashConnections1.InitTable(_maxConnections, 0); ChkIfA(ret == -1, E_FAIL); ret = _hashConnections2.InitTable(_maxConnections, 0); ChkIfA(ret == -1, E_FAIL); _pNewConnList = &_hashConnections1; _pOldConnList = &_hashConnections2; _spLimiter = spLimiter; _fNeedToExit = false; Cleanup: if (FAILED(hr)) { Reset(); } return hr; }