libassa  3.5.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Member Functions
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.
- Public Member Functions inherited from ASSA::UDPSocket
 UDPSocket ()
 Default constructor.
 UDPSocket (const handler_t fd_)
 Constructor.
virtual ~UDPSocket ()
 Destructor will close connection.
bool open (const int domain_)
 Create socket.
bool close ()
 Close socket connection.
bool bind (const Address &my_address_)
 Server in UDP client-server scenario has to bind socket to its local well-known port.
handler_t getHandler () const
 Get socket file descriptor.
const int getDomain () const
 Get socket domain type.
- Public Member Functions inherited from ASSA::Socket
 Socket ()
 Constructor.
virtual ~Socket ()
 Destructor.
int getBytesAvail (void) const
 Return number of bytes available in socket receive buffer.
int ignore (int n_=INT_MAX, int delim_=EOF)
 Extracts bytes and discards them.
virtual Streambufrdbuf ()
 Return a pointer to the Streambuf associated with the stream.
virtual Streambufrdbuf (Streambuf *)
 Virtual function that sets new socket buffer and returns the old one.
virtual Socketflush ()
 This function simply calls the public "synchronizing" function rdbuf()->pubsync() (assuming the associated streambuf object is present).
bool turnOptionOn (opt_t opt_)
 Enable socket option.
bool turnOptionOff (opt_t opt_)
 Disable socket option.
bool setOption (opt_t opt_, int arg_)
 Set socket option to value required.
int getOption (opt_t opt_) const
 Get current value of a socket option.
 operator void * () const
 Convertion to void* (for testing where bool is required)
bool operator! () const
 Alias to fail()
iostate rdstate () const
 Retrieve state of the socket.
void clear (iostate state_=Socket::goodbit)
 Clear the socket state. Closed socket remains in bad state.
void setstate (iostate flag_)
 Set socket state to flag_ by adding flag_ to the existing state.
bool good () const
 Indicates no error on the socket.
bool eof () const
 An earlier extraction operation has encountered the end of file of the input stream (peer closed its socket).
bool fail () const
 Indicates that earlier extraction opeartion has failed to match the required pattern of input.
bool bad () const
 Socket fd == -1 or read/write error occured or some loss of integrity on assosiated stream buffer.
void dumpState () const
 Write state bits of the socket to the log file.
Socketoperator>> (char &c)
 Input of built-in char type. The value will be XDR-decoded.
Socketoperator>> (unsigned char &c_)
 Input of built-in u_char type. The value will be XDR-decoded.
Socketoperator>> (signed char &c_)
 Input of built-in signed char type. The value will be XDR-decoded.
Socketoperator>> (std::string &s_)
 Input of STL string type. The string content will be XDR-decoded.
Socketoperator>> (short &n_)
 Input of built-in short type. The value will be XDR-decoded.
Socketoperator>> (unsigned short &n_)
 Input of built-in u_short type. The value will be XDR-decoded.
Socketoperator>> (int &n_)
 Input of built-in integer type. The value will be XDR-decoded.
Socketoperator>> (unsigned int &n_)
 Input of built-in u_int type. The value will be XDR-decoded.
Socketoperator>> (long &n_)
 Input of built-in long type. The value will be XDR-decoded.
Socketoperator>> (unsigned long &n_)
 Input of built-in u_long type. The value will be XDR-decoded.
Socketoperator>> (float &n_)
 Input of built-in float type. The value will be XDR-decoded.
Socketoperator>> (double &n_)
 Input of built-in double type. The value will be XDR-decoded.
Socketoperator<< (char c)
 Output of built-in char type. The value will be XDR-encoded.
Socketoperator<< (unsigned char c_)
 Output of built-in u_char type. The value will be XDR-encoded.
Socketoperator<< (signed char c_)
 Output of built-in signed char type. The value will be XDR-encoded.
Socketoperator<< (const std::string &s_)
 Output of STL string type. The value will be XDR-encoded.
Socketoperator<< (short n_)
 Output of built-in short type. The value will be XDR-encoded.
Socketoperator<< (unsigned short n_)
 Output of built-in u_short type. The value will be XDR-encoded.
Socketoperator<< (int n_)
 Output of built-in integer type. The value will be XDR-encoded.
Socketoperator<< (unsigned int n_)
 Output of built-in u_int type. The value will be XDR-encoded.
Socketoperator<< (long n_)
 Output of built-in long type. The value will be XDR-encoded.
Socketoperator<< (unsigned long n_)
 Output of built-in u_long type. The value will be XDR-encoded.
Socketoperator<< (float n_)
 Output of built-in float type. The value will be XDR-encoded.
Socketoperator<< (double n_)
 Output of built-in double type. The value will be XDR-encoded.
Socketoperator<< (Socket &(*f)(Socket &))
 Manipulators plug-in operator.

Additional Inherited Members

- Protected Member Functions inherited from ASSA::UDPSocket
void setHandler (const int fd_)
 Set file descriptor.
void setDomain (const int type_)
 Set socket domain type.
- Protected Member Functions inherited from ASSA::Socket
int set_option (int level_, int optname_, int val_)
 Gateway method of setting socket options.
int set_fd_options (long flags_)
 Gateway method for setting file descriptor options.
int clear_fd_options (long flags_)
 Gateway method for clearing file descriptor options.

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.

: UDPSocket() {
char self[] = "ConUDPSocket::ConUDPSocket"; trace(self);
}
virtual ASSA::ConUDPSocket::~ConUDPSocket ( )
inlinevirtual

Destructor.

Definition at line 32 of file ConUDPSocket.h.

References trace.

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

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 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 ) {
return false;
}
return true;
}
virtual int ASSA::ConUDPSocket::in_avail ( ) const
inlinevirtual

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

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 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) {
}
else if ( len == 0 ) {
}
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 ) {
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.

Parameters:
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_);
}

The documentation for this class was generated from the following files: