- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

Public Member Functions | List of all members
GNet::DatagramSocket Class Reference

A derivation of Socket for a connectionless datagram socket. More...

`#include <gsocket.h>`

Inheritance diagram for GNet::DatagramSocket:

## Public Member Functions
| DatagramSocket ()
| Default constructor. More...
| DatagramSocket (const Address &address_hint)
| Constructor with a hint of a local address. More...
virtual | ~DatagramSocket ()
| Destructor. More...
ssize_type | read (void *buffer, size_type len, Address &src)
| Reads a datagram and returns the sender's address by reference. More...
ssize_type | write (const char *buffer, size_type len, const Address &dst)
| Sends a datagram to the given address. More...
ssize_type | write (const char *buffer, size_type len)
| See Socket::write(). More...
void | disconnect ()
| Releases the association between two datagram endpoints reversing the effect of the previous Socket::connect(). More...
Public Member Functions inherited from GNet::Socket
virtual | ~Socket ()
| Destructor. More...
bool | valid () const
| Returns true if the socket handle is valid (open). More...
std::pair< bool, Address > | getLocalAddress () const
| Retrieves local address of the socket. More...
std::pair< bool, Address > | getPeerAddress () const
| Retrieves address of socket's peer. More...
bool | hasPeer () const
| Returns true if the socket has a valid peer. More...
bool | bind (const Address &address)
| Binds the socket with an INADDR_ANY network address and the port number taken from the given address. More...
bool | canBindHint (const Address &address)
| Returns true if the socket can probably be bound with the given address. More...
bool | connect (const Address &addr, bool *done=NULL)
| Initiates a connection to (or association with) the given address. More...
bool | listen (int backlog=1)
| Starts the socket listening on the bound address for incoming connections or incoming datagrams. More...
bool | eWouldBlock ()
| Returns true if the previous socket operation failed with the EWOULDBLOCK or EGAIN error status. More...
bool | eInProgress ()
| Returns true if the previous socket operation failed with the EINPROGRESS error status. More...
bool | eMsgSize ()
| Returns true if the previous socket operation failed with the EMSGSIZE error status. More...
void | addReadHandler (EventHandler &handler)
| Adds this socket to the event source list so that the given handler receives read events. More...
void | dropReadHandler ()
| Reverses addReadHandler(). More...
void | addWriteHandler (EventHandler &handler)
| Adds this socket to the event source list so that the given handler receives write events when flow control is released. More...
void | dropWriteHandler ()
| Reverses addWriteHandler(). More...
void | addExceptionHandler (EventHandler &handler)
| Adds this socket to the event source list so that the given handler receives exception events. More...
void | dropExceptionHandler ()
| Reverses addExceptionHandler(). More...
std::string | asString () const
| Returns the socket handle as a string. More...
std::string | reasonString () const
| Returns the failure reason as a string. More...
void | shutdown (bool for_writing=true)
| Shuts the socket for writing (or reading). More...
int | fd (Credentials) const
| Returns the socket descriptor as an integer. More...

## Additional Inherited Members
Public Types inherited from GNet::Socket
typedef size_t | size_type
typedef ssize_t | ssize_type
Protected Member Functions inherited from GNet::Socket
| Socket (int domain, int type, int protocol)
| Constructor used by derived classes. More...
| Socket (Descriptor s)
| Constructor which creates a socket object from an existing socket handle. More...
void | prepare ()
void | setFault ()
void | setNoLinger ()
void | setReuse ()
void | setKeepAlive ()
std::pair< bool, Address > | getAddress (bool) const
Static Protected Member Functions inherited from GNet::Socket
static bool | valid (Descriptor s)
static int | reason ()
static bool | error (int rc)
static bool | sizeError (ssize_type size)
Protected Attributes inherited from GNet::Socket
int | m_reason
Descriptor | m_socket

## Detailed Description

A derivation of Socket for a connectionless datagram socket.

Definition at line 311 of file gsocket.h.

## Constructor & Destructor Documentation

GNet::DatagramSocket::DatagramSocket | ( |  | ) |

Default constructor.

Definition at line 378 of file gsocket.cpp.

GNet::DatagramSocket::DatagramSocket | ( | const Address & | address_hint | ) |
| explicit

Constructor with a hint of a local address.

Definition at line 383 of file gsocket.cpp.

GNet::DatagramSocket::~DatagramSocket | ( |  | ) |
| virtual

Destructor.

Definition at line 388 of file gsocket.cpp.

## Member Function Documentation

void GNet::DatagramSocket::disconnect | ( |  | ) |

Releases the association between two datagram endpoints reversing the effect of the previous Socket::connect().

Definition at line 392 of file gsocket.cpp.

GNet::Socket::ssize_type GNet::DatagramSocket::read | ( | void * | buffer,
|  | size_type | len,
|  | Address & | src
| ) |  |

Reads a datagram and returns the sender's address by reference.

If connect() has been used then only datagrams from the address specified in the connect() call will be received.

Definition at line 399 of file gsocket.cpp.

GNet::Socket::ssize_type GNet::DatagramSocket::write | ( | const char * | buffer,
|  | size_type | len,
|  | const Address & | dst
| ) |  |

Sends a datagram to the given address.

This form of write() should be used if there is no connect() assocation in effect.

Definition at line 414 of file gsocket.cpp.

References GNet::Address::address(), GNet::Address::displayString(), G_DEBUG, and GNet::Address::length().

GNet::Socket::ssize_type GNet::DatagramSocket::write | ( | const char * | buffer,
|  | size_type | len
| ) |  |
| inline virtual

See Socket::write().

Reimplemented from GNet::Socket.

Definition at line 351 of file gsocket.h.

References GNet::Socket::write().

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

- gsocket.h
- gsocket.cpp