コード例 #1
0
ファイル: OSGDgramSocket.cpp プロジェクト: mlimper/OpenSG1x
/*! 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.
    \see recv Socket::recv
 */
int DgramSocket::peekFrom(void *buf,int size,SocketAddress &from)
{
    int len;
    SocketLenT addrLen=from.getSockAddrSize();

    len=recvfrom(_sd,
                 static_cast<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;
}
コード例 #2
0
/** \brief read the given number of bytes 
 *
 * Read size bytes into the buffer. Wait until size Bytes are available
 * data maight be lossed, if size is smaller then the incomming package.
 * This situation will not be treated as an error.
 *
 * \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 Socket::recvAvailable Socket::recv
 */
int DgramSocket::recvFrom(void *buf,int size,Address &from)
{
    int len;
    SocketLenT addrLen=from.getSockAddrSize();

    len=recvfrom(_sd,
                 (char*)buf,
                 size,
                 0,
                 from.getSockAddr(),
                 &addrLen);
    if(len<0)
    {
#if defined WIN32
        if(getError()==WSAECONNRESET)
        {
            throw SocketConnReset("recvfrom");
        }
        if(getError()==WSAEMSGSIZE)
        {
            len=size;
        }
        else
#endif
        throw SocketError("recvfrom()");
    }
    return len;
}
コード例 #3
0
ファイル: OSGDgramSocket.cpp プロジェクト: mlimper/OpenSG1x
/*! Read size bytes into the buffer. Wait until size Bytes are available
    data maight be lossed, if size is smaller then the incomming package.
    This situation will not be treated as an error.
    \see Socket::recvAvailable Socket::recv
 */
int DgramSocket::recvFrom(void *buf,int size,SocketAddress &from)
{
    int len;
    SocketLenT addrLen=from.getSockAddrSize();

#ifndef WIN32
    do
    {
#endif
        len=recvfrom(_sd,
                     static_cast<char *>(buf),
                     size,
                     0,
                     from.getSockAddr(),
                     &addrLen);
#ifndef WIN32
    } 
    while(len < 0 && errno == EAGAIN);
#endif

    if(len < 0)
    {
#if defined WIN32
        if(getError() == WSAECONNRESET)
        {
            throw SocketConnReset("recvfrom");
        }
        if(getError() == WSAEMSGSIZE)
        {
            len=size;
        }
        else
#endif
        throw SocketError("recvfrom()");
    }
    return len;
}