#include <ConUDPSocket.h>
Inheritance diagram for ASSA::ConUDPSocket:
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.
|
Constructor.
Definition at line 27 of file ConUDPSocket.h. References trace.
|
|
Destructor.
Definition at line 32 of file ConUDPSocket.h. References trace. 00032 { 00033 char self[] = "ConUDPSocket::~ConUDPSocket"; trace(self); 00034 }
|
|
Connect socket to the peer.
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(). 00024 { 00025 char self[] = "ConUDPSocket::connect"; trace(self); 00026 00027 if ( ::connect (getHandler(),peer_address_.getAddress(), 00028 peer_address_.getLength()) < 0 ) { 00029 setstate (Socket::failbit); 00030 return false; 00031 } 00032 return true; 00033 }
|
|
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.
|
|
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).
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(). 00065 { 00066 int len; 00067 len = ::read(getHandler(), packet_, size_); 00068 00069 if (len == -1) { 00070 setstate (Socket::failbit); 00071 } 00072 else if ( len == 0 ) { 00073 setstate (Socket::failbit | Socket::eofbit); 00074 } 00075 return len; 00076 }
|
|
Unconnect connected socket.
Definition at line 37 of file ConUDPSocket.cpp. References connect(), ASSA::UNIXAddress::getAddress(), ASSA::INETAddress::getAddress(), ASSA::UDPSocket::getDomain(), and trace. 00038 { 00039 // Ignore errors here. On some systems connect() might return 00040 // EAFNOSUPPORT error, on some might not, but it is OK. 00041 // 00042 char self[] = "ConUDPSocket::unconnect"; trace(self); 00043 00044 if ( getDomain() == AF_INET ) { 00045 INETAddress addr; 00046 SA_IN* addrp = (SA_IN*) addr.getAddress(); 00047 00048 addrp->sin_family = AF_UNSPEC; 00049 (void) connect(addr); 00050 } 00051 else { // AF_LOCAL 00052 // I haven't tested whether it works at all. 00053 00054 UNIXAddress addr(""); 00055 SA_UN* addrp = (SA_UN*) addr.getAddress(); 00056 00057 addrp->sun_family = AF_UNSPEC; 00058 (void) connect(addr); 00059 } 00060 }
|
|
Perform blocking write by writing packet of specified size.
Reimplemented from ASSA::Socket. Definition at line 80 of file ConUDPSocket.cpp. References ASSA::UDPSocket::getHandler(). 00081 { 00082 return ::write(getHandler(), (const void*) packet_, size_); 00083 }
|