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


C++ Address::getSockAddr方法代码示例

本文整理汇总了C++中Address::getSockAddr方法的典型用法代码示例。如果您正苦于以下问题:C++ Address::getSockAddr方法的具体用法?C++ Address::getSockAddr怎么用?C++ Address::getSockAddr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Address的用法示例。


在下文中一共展示了Address::getSockAddr方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: peekFrom

/** \brief peek the given number of bytes 
 *
 * Read size bytes into the buffer. Wait until size Bytes are available
 * On Dgram sockets data maight be lossed, if size is smaller then the
 * incomming package. This situation will not be treated as an error.
 * The read bytes will not be removed from the in buffer. A call to
 * recv after peek will result in the same data.
 *
 * \param buf   Pointer to the data buffer.
 * \param size  Maximum count of bytes to read.
 * \param from  Will be overwritten with the address of the sender
 *
 * \see recv Socket::recv
 */
int DgramSocket::peekFrom(void *buf,int size,Address &from)
{
    int len;
    SocketLenT addrLen=from.getSockAddrSize();

    len=recvfrom(_sd,
                 (char*)buf,
                 size,
                 MSG_PEEK,
                 from.getSockAddr(),
                 &addrLen);
    if(len==-1)
    {
#if defined WIN32
        if(getError()==WSAECONNRESET)
        {
            throw SocketConnReset("recvfrom");
        }
        if(getError()==WSAEMSGSIZE)
        {
            len=size;
        }
        else
#endif
        throw SocketError("recvfrom()");
    }
    return len;
}
开发者ID:BackupTheBerlios,项目名称:opensgplus,代码行数:42,代码来源:OSGDgramSocket.cpp

示例2: leave

/** \brief Leave a multicast group
 *
 * Don't receive messages from the given group.
 *
 * \param group   Multicast group 
 * \param interf  Which network interface to use. (Default AnyAddress)
 */
void DgramSocket::leave(const Address &group,const Address &interf)
{
    struct ip_mreq joinAddr;
    int rc;

    // group to join
    joinAddr.imr_multiaddr.s_addr
    = ((sockaddr_in*)group.getSockAddr())->sin_addr.s_addr;
    // interface that joins. (equal to bind address)
    joinAddr.imr_interface
    = ((sockaddr_in*)interf.getSockAddr())->sin_addr;
    rc=setsockopt(_sd,
                  IPPROTO_IP,
                  IP_DROP_MEMBERSHIP,
                  (SocketOptT*)&joinAddr,
                  sizeof(joinAddr));
    if(rc < 0)
    {
        throw SocketError("setsockopt(IPPROTO_IP,IP_DROP_MEMBERSHIP)");
    }
}
开发者ID:BackupTheBerlios,项目名称:opensgplus,代码行数:28,代码来源:OSGDgramSocket.cpp

示例3: sendTo

/** \brief Write the given number of bytes to the socket
 *
 * Write size bytes to the socket. This method maight block, if the
 * output buffer is full.
 *
 * \param buf   Pointer to the data buffer.
 * \param size  number of bytes to write
 * \param to    destination address
 *
 * \see recv Socket::send
 */
int DgramSocket::sendTo(const void *buf,int size,const Address &to)
{
    int len;

    // send Request
    len=sendto(_sd,
               (const char*)buf,size,
               0,
               to.getSockAddr(),
               to.getSockAddrSize());
    if(len == -1)
    {
        throw SocketError("sendto()");
    }
    return len;
}
开发者ID:BackupTheBerlios,项目名称:opensgplus,代码行数:27,代码来源:OSGDgramSocket.cpp


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