当前位置: 首页>>代码示例>>C++>>正文


C++ SocketAddress::GetPortNumber方法代码示例

本文整理汇总了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);
}
开发者ID:RonberKing,项目名称:IosExample,代码行数:35,代码来源:socketbase.cpp

示例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);
}
开发者ID:RonberKing,项目名称:IosExample,代码行数:25,代码来源:socketbase.cpp


注:本文中的SocketAddress::GetPortNumber方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。