libassa 3.5.1
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | List of all members
ASSA::UDPSocket Class Reference

#include <UDPSocket.h>

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

Public Member Functions

 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.
 
virtual bool connect (const Address &address_)
 Make a connection.
 
virtual int write (const char *buf_, const u_int size_)
 Write specified number of bytes to the socket.
 
int getBytesAvail (void) const
 Return number of bytes available in socket receive buffer.
 
virtual int read (char *buf_, const u_int size_)
 Read expected number of bytes from the socket.
 
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 int in_avail () const =0
 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.
 
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.
 

Protected Member Functions

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.
 

Additional Inherited Members

- Public Types inherited from ASSA::Socket
enum  io_state_t { goodbit = 0 , eofbit = 1 , failbit = 2 , badbit = 4 }
 State bits: goodbit, eofbit, failbit, badbit. More...
 
enum  opt_t { reuseaddr , rcvlowat , sndlowat , nonblocking }
 Socket options. More...
 
typedef int iostate
 
typedef unsigned char IOState
 
- Static Public Member Functions inherited from ASSA::Socket
static size_t xdr_length (const std::string &s_)
 Give the true length of the XDR-encoded STL string.
 
static bool is_little_endian ()
 Determine the endianess of the platform we are on.
 
static void close_handler (handler_t &socket_)
 Close socket endpoint in a portable way.
 
static string decode_fcntl_flags (long mask_)
 Decipher flags packed into mask_ used in fcntl() call.
 
- Static Public Attributes inherited from ASSA::Socket
static const int PGSIZE = 4096
 Size of bytes of a kernel page.
 
- Protected Attributes inherited from ASSA::Socket
handler_t m_fd
 File descriptor.
 
int m_type
 Socket domain type.
 
IOState m_state
 Control state of the socket.
 

Detailed Description

Definition at line 28 of file UDPSocket.h.

Constructor & Destructor Documentation

◆ UDPSocket() [1/2]

ASSA::UDPSocket::UDPSocket ( )
inline

Default constructor.

Definition at line 31 of file UDPSocket.h.

32 {
33 trace("UDPSocket::UDPSocket()");
34 }
#define trace(s)
trace() is used to trace function call chain in C++ program.
Definition Logger.h:429

References trace.

◆ UDPSocket() [2/2]

ASSA::UDPSocket::UDPSocket ( const handler_t  fd_)
inline

Constructor.

Parameters
fd_file descriptor to use

Definition at line 39 of file UDPSocket.h.

40 {
41 trace("UDPSocket::UDPSocket(fd)");
42 m_fd = fd_;
43 }
handler_t m_fd
File descriptor.
Definition Socket.h:485

References ASSA::Socket::m_fd, and trace.

◆ ~UDPSocket()

virtual ASSA::UDPSocket::~UDPSocket ( )
inlinevirtual

Destructor will close connection.

Definition at line 46 of file UDPSocket.h.

47 {
48 trace("UDPSocket::~UDPSocket");
49 }

References trace.

Member Function Documentation

◆ bind()

bool UDPSocket::bind ( const Address my_address_)
virtual

Server in UDP client-server scenario has to bind socket to its local well-known port.

This is the same bind call as in IPv4 - maybe it should be generalized in parent class.

Parameters
my_address_address to bind to

Implements ASSA::Socket.

Definition at line 51 of file UDPSocket.cpp.

53{
54 trace("UDPSocket::bind");
55
56 int ret = ::bind (m_fd, (SA*) my_address_.getAddress(),
57 my_address_.getLength());
58 if (ret < 0) {
60 return false;
61 }
62 return true;
63}
A wrapper class to provide AutoPtr with reference semantics.
Definition AutoPtr.h:32
void setstate(iostate flag_)
Set socket state to flag_ by adding flag_ to the existing state.
Definition Socket.h:577
@ failbit
indicates that an input operation failed to read the expected characters, or that an output operation...
Definition Socket.h:84
bool bind(const Address &my_address_)
Server in UDP client-server scenario has to bind socket to its local well-known port.
Definition UDPSocket.cpp:52

References bind(), ASSA::Socket::failbit, ASSA::Socket::m_fd, ASSA::Socket::setstate(), and trace.

Referenced by bind().

◆ close()

bool UDPSocket::close ( )
virtual

Close socket connection.

Returns
true if success, fail if call to close() failed.

Implements ASSA::Socket.

Definition at line 38 of file UDPSocket.cpp.

40{
41 trace("UDPSocket::close()");
42 if ( m_fd >= 0 ) {
45 m_fd = -1;
46 }
47 return true;
48}
bool close()
Close socket connection.
Definition UDPSocket.cpp:39

References close(), ASSA::Socket::failbit, ASSA::Socket::m_fd, ASSA::Socket::setstate(), and trace.

Referenced by close().

◆ getDomain()

const int ASSA::UDPSocket::getDomain ( ) const
inlinevirtual

Get socket domain type.

Implements ASSA::Socket.

Definition at line 77 of file UDPSocket.h.

77{ return m_type; }
int m_type
Socket domain type.
Definition Socket.h:488

References ASSA::Socket::m_type.

Referenced by ASSA::ConUDPSocket::unconnect().

◆ getHandler()

handler_t ASSA::UDPSocket::getHandler ( ) const
inlinevirtual

Get socket file descriptor.

Implements ASSA::Socket.

Definition at line 74 of file UDPSocket.h.

74{ return m_fd; }

References ASSA::Socket::m_fd.

Referenced by ASSA::ConUDPSocket::connect(), ASSA::ConUDPSocket::read(), ASSA::UnConUDPSocket::recvfrom(), ASSA::UnConUDPSocket::sendto(), and ASSA::ConUDPSocket::write().

◆ open()

bool UDPSocket::open ( const int  domain_)
virtual

Create socket.

Socket domain type is specified as AF_INET for internet socket and AF_UNIX for UNIX domain socket (full duplex pipe).

Parameters
domain_domain
Returns
true if socket is created successfully, false otherwise

Implements ASSA::Socket.

Definition at line 21 of file UDPSocket.cpp.

23{
24 trace("UDPSocket::open");
25
28
29 if (m_fd < 0) {
31 return false;
32 }
33 clear ();
34 return true;
35}
void clear(iostate state_=Socket::goodbit)
Clear the socket state. Closed socket remains in bad state.
Definition Socket.h:571

References ASSA::Socket::clear(), ASSA::Socket::failbit, ASSA::Socket::m_fd, ASSA::Socket::m_type, ASSA::Socket::setstate(), and trace.

◆ setDomain()

void ASSA::UDPSocket::setDomain ( const int  type_)
inlineprotected

Set socket domain type.

Definition at line 84 of file UDPSocket.h.

84{ m_type = type_; }

References ASSA::Socket::m_type.

◆ setHandler()

void ASSA::UDPSocket::setHandler ( const int  fd_)
inlineprotected

Set file descriptor.

Definition at line 81 of file UDPSocket.h.

81{ m_fd = fd_; }

References ASSA::Socket::m_fd.


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