本文整理汇总了C++中PSockEvent::OnConnect方法的典型用法代码示例。如果您正苦于以下问题:C++ PSockEvent::OnConnect方法的具体用法?C++ PSockEvent::OnConnect怎么用?C++ PSockEvent::OnConnect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PSockEvent
的用法示例。
在下文中一共展示了PSockEvent::OnConnect方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnConnect
void TSockSys::OnConnect(uv_connect_t* ConnectHnd, int Status) {
// get socket handle
uv_tcp_t* SockHnd = (uv_tcp_t*)ConnectHnd->handle;
IAssert(SockSys.IsSockHnd((uint64)SockHnd));
// cleanup
free(ConnectHnd);
// 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.OnConnect: Socket without SockEvent");
return;
}
// execute callback
if (Status == 0) {
SockEvent->OnConnect(SockId);
} else {
TStr ErrMsg = (Status == -1) ?
"SockSys.OnConnect: " + SockSys.GetLastErr() :
"SockSys.OnConnect: Error connecting";
SockEvent->OnError(SockId, Status, ErrMsg);
return;
}
// start listening for incoming data
int ResCd = uv_read_start((uv_stream_t*)SockHnd, TSockSys::OnAlloc, TSockSys::OnRead);
// check for errors
if (ResCd != 0) {
TStr ErrMsg = (Status == -1) ?
"SockSys.OnConnect: " + SockSys.GetLastErr() :
"SockSys.OnConnect: Error establishing read callbacks";
SockEvent->OnError(SockId, ResCd, ErrMsg);
}
}