void OnAccept(const AsyncResultPtr &asyncResult) { try { SocketPtr listenSocket = asyncResult->asyncState; SocketPtr acceptSocket = listenSocket->EndAccept(asyncResult); acceptSocket->BeginReceive(BufferPtr(8192, NoRebindTag()), &OnReceive, acceptSocket); listenSocket->BeginAccept(&OnAccept, listenSocket); } catch (const std::exception &) { } }
void OnReceive(const AsyncResultPtr &asyncResult) { try { SocketPtr acceptSocket = asyncResult->asyncState; BufferPtr buffer = asyncResult->buffer; size_t size = acceptSocket->EndReceive(asyncResult); if (size != 0) { buffer->Resize(size); acceptSocket->BeginSend(buffer); acceptSocket->BeginReceive(BufferPtr(8192, NoRebindTag()), &OnReceive, acceptSocket); } else { acceptSocket->BeginDisconnect(); } } catch (const std::exception &) { } }