libassa 3.5.0
Public Member Functions

ASSA::UnConUDPSocket Class Reference

#include <UnConUDPSocket.h>

Inheritance diagram for ASSA::UnConUDPSocket:
ASSA::UDPSocket ASSA::Socket

List of all members.

Public Member Functions

 UnConUDPSocket ()
 Constructor.
 ~UnConUDPSocket ()
 Destructor.
int recvfrom (char *buf_, int size_, Address *peer_addr_)
 recvfrom() function receives a message from connectionless-mode socket.
int sendto (const char *buf_, const unsigned int size_, const Address *dest_addr_)
 sendto() function sends a message through connectionless-mode socket.
virtual int in_avail () const
 This function returns the number of characters immediately available in the get area of the underlying Socketbuf buffer without making a system call.

Detailed Description

Definition at line 26 of file UnConUDPSocket.h.


Constructor & Destructor Documentation

ASSA::UnConUDPSocket::UnConUDPSocket ( )

Constructor.

Definition at line 70 of file UnConUDPSocket.h.

References ASSA::SOCKTRACE, and trace_with_mask.

                  : UDPSocket() 
{
    trace_with_mask ("UnConUDPSocket::UnConUDPSocket", SOCKTRACE);
}
ASSA::UnConUDPSocket::~UnConUDPSocket ( )

Destructor.

Definition at line 76 of file UnConUDPSocket.h.

References ASSA::SOCKTRACE, and trace_with_mask.

{
    trace_with_mask ("UnConUDPSocket::~UnConUDPSocket", SOCKTRACE);
}

Member Function Documentation

virtual int ASSA::UnConUDPSocket::in_avail ( ) const [inline, virtual]

This function returns the number of characters immediately available in the get area of the underlying Socketbuf buffer without making a system call.

Always return 0.

Implements ASSA::Socket.

Definition at line 66 of file UnConUDPSocket.h.

{ return 0; }
int UnConUDPSocket::recvfrom ( char *  buf_,
int  size_,
Address peer_addr_ 
)

recvfrom() function receives a message from connectionless-mode socket.

It also permits the application to retrieve the source address of received data.

Parameters:
buf_points to buffer where the message should be stored
size_buffer length is bytes
peer_addr_pointer to the address structure where sending address is to be stored
Returns:
length of the peer address

Definition at line 25 of file UnConUDPSocket.cpp.

References ASSA::Address::getAddress(), ASSA::UDPSocket::getHandler(), and ASSA::Address::getLength().

{
    // ::recvfrom() can return 0 bytes which is not 
    // considered an eof. Peer can advertise its address to 
    // the server by sending 0 bytes length message.
    //

    // char self[] = "Socket::recvfro"; trace(self);

    // Setting saddr_len is crucial to proper ::recvfrom() operation.
    // If left improprely initialized, ::recvfrom() won't fill in peer's 
    // address and won't report an error either. If SA ptr is passed to 
    // recvfrom() along with uninitialized address len (or set to 0), 
    // recvfrom() returns zeroed out address structure!!!

    int len;
    socklen_t pa_len = peer_addr_->getLength();

    SA* pa = peer_addr_->getAddress();

#if defined (__CYGWIN32__) || defined (WIN32)
    len = ::recvfrom(getHandler(), buf_, size_, 0, pa, (int*)&pa_len);
#else  // posix/unix
    len = ::recvfrom(getHandler(), buf_, size_, 0, pa, &pa_len);
#endif

    // Q: for UNIX domain socket, returned length will be essential to
    // remember and probably should be set in peer_addr_ by calling
    // setLength().....
    
    return len;
}
int UnConUDPSocket::sendto ( const char *  buf_,
const unsigned int  size_,
const Address dest_addr_ 
)

sendto() function sends a message through connectionless-mode socket.

The message will be sent to the address specified by dest_addr_.

Parameters:
buf_pointer to the buffer containing the message to be sent
size_the size of the message in bytes
dest_addr_contains destination address
Returns:
upon successful completion, number of bytes sent. Otherwise, -1.

Definition at line 60 of file UnConUDPSocket.cpp.

References ASSA::Address::getAddress(), ASSA::UDPSocket::getHandler(), and ASSA::Address::getLength().

{
    return  ::sendto (getHandler(), buf_, size_, 0,
             peer_addr_->getAddress(),
             peer_addr_->getLength());
}

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines