int main() { std::cout << "==== start ====" << std::endl; Client c = Client(); Prototype* p0 = new ConcretePrototype("foo"); Prototype* p1 = new ConcretePrototype("bar"); c.Register("foo", p0); c.Register("bar", p1); std::cout << "[foo] " << p0 << std::endl; std::cout << "[foo] " << c.Create("foo") << std::endl; std::cout << "[foo] " << c.Create("foo") << std::endl; std::cout << "[foo] " << c.Create("foo") << std::endl; std::cout << "[bar] " << p1 << std::endl; std::cout << "[bar] " << c.Create("bar") << std::endl; std::cout << "[bar] " << c.Create("bar") << std::endl; std::cout << "[bar] " << c.Create("bar") << std::endl; std::cout << "==== end ====" << std::endl; }
void Server::PostAccept() { // If the number of clients is too big, we can just stop posting accept. // That's one of the benefits from AcceptEx. int count = m_MaxPostAccept - m_NumPostAccept; if (count > 0) { int i = 0; for (; i < count; ++i) { Client* client = new Client(); if (!client->Create()) { delete client; break; } IOEvent* event = IOEvent::Create(IOEvent::ACCEPT, client); assert(event); StartThreadpoolIo(m_pTPIO); if (!Network::AcceptEx(m_listenSocket, client->GetSocket(), &event->GetOverlapped())) { int error = WSAGetLastError(); if (error != ERROR_IO_PENDING) { CancelThreadpoolIo(m_pTPIO); ERROR_CODE(error, "AcceptEx() failed."); delete client; IOEvent::Destroy(event); break; } } else { OnAccept(event); IOEvent::Destroy(event); } } InterlockedExchangeAdd(&m_NumPostAccept, i); TRACE("[%d] Post AcceptEx : %d", GetCurrentThreadId(), m_NumPostAccept); } }