Loading...
Searching...
No Matches
ASSA::UnConUDPSocket Class Reference

`#include <UnConUDPSocket.h>`

Inheritance diagram for ASSA::UnConUDPSocket:

## Public Member Functions

| UnConUDPSocket ()
| Constructor.
| ~UnConUDPSocket ()
| Destructor.
int | recvfrom (char *buf_, int size_, Address *peer_addr_)
| recvfrom() function receives a message from connectionless-mode socket.
int | sendto (const char *buf_, const unsigned int size_, const Address *dest_addr_)
| sendto() function sends a message through connectionless-mode socket.
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.
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.
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 Streambuf * | rdbuf ()
| Return a pointer to the Streambuf associated with the stream.
virtual Streambuf * | rdbuf (Streambuf *)
| Virtual function that sets new socket buffer and returns the old one.
virtual Socket & | flush ()
| 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.
Socket & | operator>> (char &c)
| Input of built-in char type. The value will be XDR-decoded.
Socket & | operator>> (unsigned char &c_)
| Input of built-in u_char type. The value will be XDR-decoded.
Socket & | operator>> (signed char &c_)
| Input of built-in signed char type. The value will be XDR-decoded.
Socket & | operator>> (std::string &s_)
| Input of STL string type. The string content will be XDR-decoded.
Socket & | operator>> (short &n_)
| Input of built-in short type. The value will be XDR-decoded.
Socket & | operator>> (unsigned short &n_)
| Input of built-in u_short type. The value will be XDR-decoded.
Socket & | operator>> (int &n_)
| Input of built-in integer type. The value will be XDR-decoded.
Socket & | operator>> (unsigned int &n_)
| Input of built-in u_int type. The value will be XDR-decoded.
Socket & | operator>> (long &n_)
| Input of built-in long type. The value will be XDR-decoded.
Socket & | operator>> (unsigned long &n_)
| Input of built-in u_long type. The value will be XDR-decoded.
Socket & | operator>> (float &n_)
| Input of built-in float type. The value will be XDR-decoded.
Socket & | operator>> (double &n_)
| Input of built-in double type. The value will be XDR-decoded.
Socket & | operator<< (char c)
| Output of built-in char type. The value will be XDR-encoded.
Socket & | operator<< (unsigned char c_)
| Output of built-in u_char type. The value will be XDR-encoded.
Socket & | operator<< (signed char c_)
| Output of built-in signed char type. The value will be XDR-encoded.
Socket & | operator<< (const std::string &s_)
| Output of STL string type. The value will be XDR-encoded.
Socket & | operator<< (short n_)
| Output of built-in short type. The value will be XDR-encoded.
Socket & | operator<< (unsigned short n_)
| Output of built-in u_short type. The value will be XDR-encoded.
Socket & | operator<< (int n_)
| Output of built-in integer type. The value will be XDR-encoded.
Socket & | operator<< (unsigned int n_)
| Output of built-in u_int type. The value will be XDR-encoded.
Socket & | operator<< (long n_)
| Output of built-in long type. The value will be XDR-encoded.
Socket & | operator<< (unsigned long n_)
| Output of built-in u_long type. The value will be XDR-encoded.
Socket & | operator<< (float n_)
| Output of built-in float type. The value will be XDR-encoded.
Socket & | operator<< (double n_)
| Output of built-in double type. The value will be XDR-encoded.
Socket & | operator<< (Socket &(*f)(Socket &))
| Manipulators plug-in operator.

## 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 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.
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 26 of file UnConUDPSocket.h.

## Constructor & Destructor Documentation

## UnConUDPSocket()

ASSA::UnConUDPSocket::UnConUDPSocket | ( |  | ) |

Constructor.

Definition at line 69 of file UnConUDPSocket.h.

: UDPSocket()
{
trace_with_mask ("UnConUDPSocket::UnConUDPSocket", SOCKTRACE);
}
trace_with_mask
#define trace_with_mask(s, m)
trace_with_mask() is used to trace function call chain in C++ program.
Definition Logger.h:437
ASSA::UDPSocket::UDPSocket
UDPSocket()
Default constructor.
Definition UDPSocket.h:31
ASSA::SOCKTRACE
@ SOCKTRACE
Extended Socket & friends messages
Definition LogMask.h:42

References ASSA::SOCKTRACE, and trace_with_mask.

## ~UnConUDPSocket()

ASSA::UnConUDPSocket::~UnConUDPSocket | ( |  | ) |

Destructor.

Definition at line 75 of file UnConUDPSocket.h.

{
trace_with_mask ("UnConUDPSocket::~UnConUDPSocket", SOCKTRACE);
}

References ASSA::SOCKTRACE, and trace_with_mask.

## Member Function Documentation

## in_avail()

virtual int ASSA::UnConUDPSocket::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.

Always return 0.

Implements ASSA::Socket.

Definition at line 66 of file UnConUDPSocket.h.

{ return 0; }

## recvfrom()

int UnConUDPSocket::recvfrom | ( | char * | buf_,
|  | int | size_,
|  | Address * | peer_addr_
| ) |  |

recvfrom() function receives a message from connectionless-mode socket.

It also permits the application to retrieve the source address of received data.

Parameters

  buf_ | points to buffer where the message should be stored
  size_ | buffer length is bytes
  peer_addr_ | pointer to the address structure where sending address is to be stored

Returns
  length of the peer address

Definition at line 24 of file UnConUDPSocket.cpp.

{
// ::recvfrom() can return 0 bytes which is not
// considered an eof. Peer can advertise its address to
// the server by sending 0 bytes length message.
//
// char self[] = "Socket::recvfro"; trace(self);
// Setting saddr_len is crucial to proper ::recvfrom() operation.
// If left improprely initialized, ::recvfrom() won't fill in peer's
// address and won't report an error either. If SA ptr is passed to
// recvfrom() along with uninitialized address len (or set to 0),
// recvfrom() returns zeroed out address structure!!!
int len;
socklen_t pa_len = peer_addr_->getLength();
SA* pa = peer_addr_->getAddress();
#if defined (__CYGWIN32__) || defined (WIN32)
len = ::recvfrom(getHandler(), buf_, size_, 0, pa, (int*)&pa_len);
#else // posix/unix
len = ::recvfrom(getHandler(), buf_, size_, 0, pa, &pa_len);
#endif
// Q: for UNIX domain socket, returned length will be essential to
// remember and probably should be set in peer_addr_ by calling
// setLength().....
return len;
}
ASSA::AutoPtrRef
A wrapper class to provide AutoPtr with reference semantics.
Definition AutoPtr.h:32
ASSA::UDPSocket::getHandler
handler_t getHandler() const
Get socket file descriptor.
Definition UDPSocket.h:74
ASSA::UnConUDPSocket::recvfrom
int recvfrom(char *buf_, int size_, Address *peer_addr_)
recvfrom() function receives a message from connectionless-mode socket.
Definition UnConUDPSocket.cpp:25

References ASSA::UDPSocket::getHandler(), and recvfrom().

Referenced by recvfrom().

## sendto()

int UnConUDPSocket::sendto | ( | const char * | buf_,
|  | const unsigned int | size_,
|  | const Address * | dest_addr_
| ) |  |

sendto() function sends a message through connectionless-mode socket.

The message will be sent to the address specified by dest_addr_.

Parameters

  buf_ | pointer to the buffer containing the message to be sent
  size_ | the size of the message in bytes
  dest_addr_ | contains destination address

Returns
  upon successful completion, number of bytes sent. Otherwise, -1.

Definition at line 59 of file UnConUDPSocket.cpp.

{
return ::sendto (getHandler(), buf_, size_, 0,
peer_addr_->getAddress(),
peer_addr_->getLength());
}

References ASSA::UDPSocket::getHandler().

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

- UnConUDPSocket.h
- UnConUDPSocket.cpp