示例#1
0
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 &) {
	}
}
示例#2
0
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 &) {
	}
}