本文整理汇总了C++中PSockEvent::OnAccept方法的典型用法代码示例。如果您正苦于以下问题:C++ PSockEvent::OnAccept方法的具体用法?C++ PSockEvent::OnAccept怎么用?C++ PSockEvent::OnAccept使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PSockEvent
的用法示例。
在下文中一共展示了PSockEvent::OnAccept方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnAccept
void TSockSys::OnAccept(uv_stream_t* ServerSockHnd, int Status) {
// get socket handle
uv_tcp_t* SockHnd = (uv_tcp_t*)ServerSockHnd;
IAssert(SockSys.IsSockHnd((uint64)SockHnd));
// get socket id
const uint64 SockId = SockSys.SockHndToIdH.GetDat((uint64)SockHnd);
IAssert(SockSys.IsSock(SockId));
// get socket event
const uint64 SockEventId = SockSys.SockHndToEventIdH.GetDat((uint64)SockHnd);
PSockEvent SockEvent;
if (SockSys.IsSockEvent(SockEventId)) {
SockEvent = SockSys.GetSockEvent(SockEventId);
} else {
SaveToErrLog("SockSys.OnAccept: Socket without SockEvent");
return;
}
// check for success status
if (Status == 0) {
// create a new socket for client connection
PSock ClientSock = TSock::New(SockEvent);
// get client socket handle
uv_tcp_t* ClientSockHnd = SockSys.SockIdToHndH.GetDat(ClientSock->GetSockId());
// accept request
const int AcceptResCd = uv_accept(ServerSockHnd, (uv_stream_t*)ClientSockHnd);
// start listening for incoming data
if (AcceptResCd == 0) {
int ReadStartResCd = uv_read_start((uv_stream_t*)ClientSockHnd, TSockSys::OnAlloc, TSockSys::OnRead);
// execute callback
if (ReadStartResCd == 0) {
SockEvent->OnAccept(ClientSock->GetSockId(), ClientSock);
} else {
TStr ErrMsg = (Status == -1) ?
"SockSys.OnAccept: Error starting read " + SockSys.GetLastErr() :
"SockSys.OnAccept: Error starting read";
SockEvent->OnError(SockId, ReadStartResCd, ErrMsg);
}
} else {
// handle errors
TStr ErrMsg = (Status == -1) ?
"SockSys.OnAccept: Error accepting new connection " + SockSys.GetLastErr() :
"SockSys.OnAccept: Error accepting new connection";
SockEvent->OnError(SockId, AcceptResCd, ErrMsg);
}
} else {
TStr ErrMsg = (Status == -1) ?
"SockSys.OnAccept: Error connecting" + SockSys.GetLastErr() :
"SockSys.OnAccept: Error connecting";
SockEvent->OnError(SockId, Status, ErrMsg);
}
}