ASSA::ConUDPSocket Class Reference

#include <ConUDPSocket.h>

Inheritance diagram for ASSA::ConUDPSocket:

ASSA::UDPSocket ASSA::Socket List of all members.

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.

Detailed Description

Definition at line 24 of file ConUDPSocket.h.


Constructor & Destructor Documentation

ASSA::ConUDPSocket::ConUDPSocket  )  [inline]
 

Constructor.

Definition at line 27 of file ConUDPSocket.h.

References trace.

00027                     : UDPSocket() {
00028         char self[] = "ConUDPSocket::ConUDPSocket"; trace(self);
00029     }

virtual ASSA::ConUDPSocket::~ConUDPSocket  )  [inline, virtual]
 

Destructor.

Definition at line 32 of file ConUDPSocket.h.

References trace.

00032                              {
00033         char self[] = "ConUDPSocket::~ConUDPSocket"; trace(self);
00034     } 


Member Function Documentation

bool ConUDPSocket::connect const Address peer_addr_  )  [virtual]
 

Connect socket to the peer.

Parameters:
peer_addr_ peer address

Reimplemented from ASSA::Socket.

Definition at line 21 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().

00022 {
00023     char self[] = "ConUDPSocket::connect"; trace(self);
00024 
00025     if ( ::connect (getHandler(),peer_address_.getAddress(),
00026                     peer_address_.getLength()) < 0 ) {
00027         setstate (Socket::failbit);
00028         return false;
00029     }
00030     return true;
00031 }

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.

00063 { 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).

Parameters:
buf_ buffer to save received data into
size_ expected packet size
Returns:
number of bytes read or -1 on error, indicating the reason in errno. Packets of 0 size are possible.

Reimplemented from ASSA::Socket.

Definition at line 62 of file ConUDPSocket.cpp.

References ASSA::Socket::eofbit, ASSA::Socket::failbit, ASSA::UDPSocket::getHandler(), and ASSA::Socket::setstate().

00063 {
00064     int len;
00065     len = ::read(getHandler(), packet_, size_);
00066 
00067     if (len == -1) {
00068         setstate (Socket::failbit);
00069     }
00070     else if ( len == 0 ) {
00071         setstate (Socket::failbit | Socket::eofbit);
00072     }
00073     return len;
00074 }

void ConUDPSocket::unconnect  ) 
 

Unconnect connected socket.

Definition at line 35 of file ConUDPSocket.cpp.

References connect(), ASSA::UNIXAddress::getAddress(), ASSA::INETAddress::getAddress(), ASSA::UDPSocket::getDomain(), and trace.

00036 {
00037     // Ignore errors here. On some systems connect() might return
00038     // EAFNOSUPPORT error, on some might not, but it is OK.
00039     //
00040     char self[] = "ConUDPSocket::unconnect"; trace(self);
00041 
00042     if ( getDomain() == AF_INET ) {
00043         INETAddress addr;
00044         SA_IN* addrp = (SA_IN*) addr.getAddress();
00045 
00046         addrp->sin_family = AF_UNSPEC;
00047         (void) connect(addr);
00048     }
00049     else {          // AF_LOCAL
00050         // I haven't tested whether it works at all.
00051         
00052         UNIXAddress addr("");
00053         SA_UN* addrp = (SA_UN*) addr.getAddress();
00054 
00055         addrp->sun_family = AF_UNSPEC;
00056         (void) connect(addr);       
00057     }
00058 }

int ConUDPSocket::write const char *  buf_ = NULL,
const unsigned int  size_ = 0
[virtual]
 

Perform blocking write by writing packet of specified size.

Parameters:
buf_ buffer to send
size_ packet size

Reimplemented from ASSA::Socket.

Definition at line 78 of file ConUDPSocket.cpp.

References ASSA::UDPSocket::getHandler().

00079 {
00080     return  ::write(getHandler(), (const void*) packet_, size_);
00081 }


The documentation for this class was generated from the following files:
Generated on Sat Dec 31 19:52:13 2005 for libassa by  doxygen 1.4.5