本文整理汇总了C++中SocketAddress::GetPortNumber方法的典型用法代码示例。如果您正苦于以下问题:C++ SocketAddress::GetPortNumber方法的具体用法?C++ SocketAddress::GetPortNumber怎么用?C++ SocketAddress::GetPortNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SocketAddress
的用法示例。
在下文中一共展示了SocketAddress::GetPortNumber方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SocketException
int
SocketBase::RecvFrom(void *pBuffer, int iBufLength, unsigned int uiFlags,
IPAddress &cSourceIP, int &iSourcePortNumber)
{
SocketAddress cSource;
socklen_t slDummy = cSource.SizeOf();
int iBytesRead;
WaitMutex();
if ((iBytesRead = recvfrom(iSockDesc, pBuffer, iBufLength, uiFlags, (sockaddr *)cSource, &slDummy)) < 0)
{
ClearMutex();
switch (errno)
{
case EBADF:
case ENOTSOCK: throw SocketException(SocketException::errBadDescriptor);
case ENOTCONN: throw SocketException(SocketException::errNotConnected);
case EAGAIN: throw SocketException(SocketException::errWouldBlock);
case EINTR: throw SocketException(SocketException::errInterrupted);
case EFAULT: throw SocketException(SocketException::errIllegalPointer);
case EINVAL: throw SocketException(SocketException::errInvalidArgument);
default: throw SocketException(SocketException::errUnknown, errno);
}
}
ClearMutex();
if (iBytesRead)
{
cSource.GetIPAddress(cSourceIP);
cSource.GetPortNumber(iSourcePortNumber);
return iBytesRead;
}
throw SocketException(SocketException::errNotConnected);
}
示例2: WaitMutex
void
SocketBase::GetPeerName(IPAddress &cRemoteAddr, int &iRemotePort)
{
SocketAddress cRemote;
socklen_t slDummy = cRemote.SizeOf();
WaitMutex();
if (getpeername(iSockDesc, (sockaddr *)cRemote, &slDummy) < 0)
{
ClearMutex();
switch (errno)
{
case EBADF:
case ENOTSOCK: throw SocketException(SocketException::errBadDescriptor);
case ENOBUFS: throw SocketException(SocketException::errKernelMemory);
case EFAULT: throw SocketException(SocketException::errIllegalPointer);
default: throw SocketException(SocketException::errUnknown, errno);
}
}
ClearMutex();
cRemote.GetIPAddress(cRemoteAddr);
cRemote.GetPortNumber(iRemotePort);
}