libassa 3.5.0
|
#include <ConUDPSocket.h>
Public Member Functions | |
ConUDPSocket () | |
Constructor. | |
virtual | ~ConUDPSocket () |
Destructor. | |
bool | connect (const Address &peer_addr_) |
Connect socket to the peer. | |
void | unconnect () |
Unconnect connected socket. | |
int | read (char *buf_, const unsigned int size_) |
Read specified number of bytes off the socket. | |
int | write (const char *buf_=NULL, const unsigned int size_=0) |
Perform blocking write by writing packet of specified size. | |
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 if Socket is doing buffering I/O. |
Definition at line 24 of file ConUDPSocket.h.
ASSA::ConUDPSocket::ConUDPSocket | ( | ) | [inline] |
virtual ASSA::ConUDPSocket::~ConUDPSocket | ( | ) | [inline, virtual] |
Destructor.
Definition at line 32 of file ConUDPSocket.h.
References trace.
{ char self[] = "ConUDPSocket::~ConUDPSocket"; trace(self); }
bool ConUDPSocket::connect | ( | const Address & | peer_addr_ | ) | [virtual] |
Connect socket to the peer.
peer_addr_ | peer address |
Reimplemented from ASSA::Socket.
Definition at line 23 of file ConUDPSocket.cpp.
References ASSA::Socket::failbit, ASSA::Address::getAddress(), ASSA::UDPSocket::getHandler(), ASSA::Address::getLength(), ASSA::Socket::setstate(), and trace.
Referenced by unconnect().
{ char self[] = "ConUDPSocket::connect"; trace(self); if ( ::connect (getHandler(),peer_address_.getAddress(), peer_address_.getLength()) < 0 ) { setstate (Socket::failbit); return false; } return true; }
virtual int ASSA::ConUDPSocket::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 if Socket is doing buffering I/O.
It is certain that returned number of characters may be fetched without error, and without accessing any external device.
Implements ASSA::Socket.
Definition at line 63 of file ConUDPSocket.h.
{ return 0; }
int ConUDPSocket::read | ( | char * | buf_, |
const unsigned int | size_ | ||
) | [virtual] |
Read specified number of bytes off the socket.
This function cannot be moved up in class hierarchy because IPv4 read() is *very* different from UDP read (one time shot).
buf_ | buffer to save received data into |
size_ | expected packet size |
Reimplemented from ASSA::Socket.
Definition at line 64 of file ConUDPSocket.cpp.
References ASSA::Socket::eofbit, ASSA::Socket::failbit, ASSA::UDPSocket::getHandler(), and ASSA::Socket::setstate().
{ int len; len = ::read(getHandler(), packet_, size_); if (len == -1) { setstate (Socket::failbit); } else if ( len == 0 ) { setstate (Socket::failbit | Socket::eofbit); } return len; }
void ConUDPSocket::unconnect | ( | ) |
Unconnect connected socket.
Definition at line 37 of file ConUDPSocket.cpp.
References connect(), ASSA::UNIXAddress::getAddress(), ASSA::INETAddress::getAddress(), ASSA::UDPSocket::getDomain(), and trace.
{ // Ignore errors here. On some systems connect() might return // EAFNOSUPPORT error, on some might not, but it is OK. // char self[] = "ConUDPSocket::unconnect"; trace(self); if ( getDomain() == AF_INET ) { INETAddress addr; SA_IN* addrp = (SA_IN*) addr.getAddress(); addrp->sin_family = AF_UNSPEC; (void) connect(addr); } else { // AF_LOCAL // I haven't tested whether it works at all. UNIXAddress addr(""); SA_UN* addrp = (SA_UN*) addr.getAddress(); addrp->sun_family = AF_UNSPEC; (void) connect(addr); } }
int ConUDPSocket::write | ( | const char * | buf_ = NULL , |
const unsigned int | size_ = 0 |
||
) | [virtual] |
Perform blocking write by writing packet of specified size.
buf_ | buffer to send |
size_ | packet size |
Reimplemented from ASSA::Socket.
Definition at line 80 of file ConUDPSocket.cpp.
References ASSA::UDPSocket::getHandler().
{ return ::write(getHandler(), (const void*) packet_, size_); }