EpcTools
An event based multi-threaded C++ development framework.
Classes | Public Member Functions | Friends | List of all members
ESocket::UDP< TQueue, TMessage > Class Template Reference

A UDP socket class capabile of sending and receiving data. More...

#include <esocket.h>

Inheritance diagram for ESocket::UDP< TQueue, TMessage >:
ESocket::Base< TQueue, TMessage >

Public Member Functions

 UDP (Thread< TQueue, TMessage > &thread, Int bufsize=2097152)
 Class constructor. More...
 
 UDP (Thread< TQueue, TMessage > &thread, UShort port, Int bufsize=2097152)
 Class constructor. More...
 
 UDP (Thread< TQueue, TMessage > &thread, cpStr ipaddr, UShort port, Int bufsize=2097152)
 Class constructor. More...
 
 UDP (Thread< TQueue, TMessage > &thread, Address &addr, Int bufsize=2097152)
 Class constructor. More...
 
virtual ~UDP ()
 Class destructor. More...
 
Address getLocal ()
 Retrieves the local address for this socket. More...
 
EString getLocalAddress ()
 Retrieves the IP address for this socket. More...
 
UShort getLocalPort ()
 Retrieves the port for this socket. More...
 
UDPsetLocal (cpStr addr, UShort port)
 Assigns the socket address for this socket. More...
 
UDPsetLocal (const Address &addr)
 Assigns the socket address for this socket. More...
 
Void write (const Address &to, pVoid src, Int len)
 Sends data to the specified recipient address. More...
 
Bool getSending ()
 Retrieves indication if this socket is in the process of sending data. More...
 
Void bind (UShort port)
 Binds this socket to a local port and IPADDR_ANY. More...
 
Void bind (cpStr ipaddr, UShort port)
 Binds this socket to a local address. More...
 
Void bind (const Address &addr)
 Binds this socket to a local address. More...
 
Void disconnect ()
 Disconnects the socket. More...
 
virtual Void onReceive (const Address &from, pVoid msg, Int len)
 Called for each message that is received. More...
 
virtual Void onError ()
 Called when an error is detected on this socket. More...
 
- Public Member Functions inherited from ESocket::Base< TQueue, TMessage >
virtual ~Base ()
 Virtual class destructor. More...
 
Thread< TQueue, TMessage > & getThread ()
 Retrieves the socket thread that this socket is associated with. More...
 
SocketType getSocketType ()
 Retrieves the socket type. More...
 
Int getFamily ()
 Retrieves the address family. More...
 
Int getType ()
 Retrieves the socket type. More...
 
Int getProtocol ()
 Retrieves the protocol. More...
 
Int getError ()
 Retrieves the last error value. More...
 
Void close ()
 Closes this socket. More...
 
Int getHandle ()
 Retrieves the socket file handle. More...
 
cpStr getStateDescription (SocketState state)
 Retrieves the description of the connection state. More...
 

Friends

class Thread< TQueue, TMessage >
 

Detailed Description

template<class TQueue, class TMessage>
class ESocket::UDP< TQueue, TMessage >

A UDP socket class capabile of sending and receiving data.

Constructor & Destructor Documentation

◆ UDP() [1/4]

template<class TQueue , class TMessage >
ESocket::UDP< TQueue, TMessage >::UDP ( Thread< TQueue, TMessage > &  thread,
Int  bufsize = 2097152 
)
inline

Class constructor.

Parameters
threadthe socket thread the talking socket will be associated with.
bufsizethe size of the send and receive circular buffers.

◆ UDP() [2/4]

template<class TQueue , class TMessage >
ESocket::UDP< TQueue, TMessage >::UDP ( Thread< TQueue, TMessage > &  thread,
UShort  port,
Int  bufsize = 2097152 
)
inline

Class constructor.

Parameters
threadthe socket thread the talking socket will be associated with.
portthe local port to listen on.
bufsizethe size of the send and receive circular buffers.

◆ UDP() [3/4]

template<class TQueue , class TMessage >
ESocket::UDP< TQueue, TMessage >::UDP ( Thread< TQueue, TMessage > &  thread,
cpStr  ipaddr,
UShort  port,
Int  bufsize = 2097152 
)
inline

Class constructor.

Parameters
threadthe socket thread the talking socket will be associated with.
ipaddrthe local IP address to listen on.
portthe local port to listen on.
bufsizethe size of the send and receive circular buffers.

◆ UDP() [4/4]

template<class TQueue , class TMessage >
ESocket::UDP< TQueue, TMessage >::UDP ( Thread< TQueue, TMessage > &  thread,
Address addr,
Int  bufsize = 2097152 
)
inline

Class constructor.

Parameters
threadthe socket thread the talking socket will be associated with.
addrthe local socket address to listen on.
bufsizethe size of the send and receive circular buffers.

◆ ~UDP()

template<class TQueue , class TMessage >
virtual ESocket::UDP< TQueue, TMessage >::~UDP ( )
inlinevirtual

Class destructor.

Member Function Documentation

◆ bind() [1/3]

template<class TQueue , class TMessage >
Void ESocket::UDP< TQueue, TMessage >::bind ( const Address addr)
inline

Binds this socket to a local address.

Parameters
addrthe local socket address.

◆ bind() [2/3]

template<class TQueue , class TMessage >
Void ESocket::UDP< TQueue, TMessage >::bind ( cpStr  ipaddr,
UShort  port 
)
inline

Binds this socket to a local address.

Parameters
ipaddrthe IP address.
portthe port.

◆ bind() [3/3]

template<class TQueue , class TMessage >
Void ESocket::UDP< TQueue, TMessage >::bind ( UShort  port)
inline

Binds this socket to a local port and IPADDR_ANY.

Parameters
portthe port.

◆ disconnect()

template<class TQueue , class TMessage >
Void ESocket::UDP< TQueue, TMessage >::disconnect ( )
inlinevirtual

Disconnects the socket.

Reimplemented from ESocket::Base< TQueue, TMessage >.

◆ getLocal()

template<class TQueue , class TMessage >
Address ESocket::UDP< TQueue, TMessage >::getLocal ( )
inline

Retrieves the local address for this socket.

Returns
the local address for this socket.

◆ getLocalAddress()

template<class TQueue , class TMessage >
EString ESocket::UDP< TQueue, TMessage >::getLocalAddress ( )
inline

Retrieves the IP address for this socket.

Returns
the IP address for this socket.

◆ getLocalPort()

template<class TQueue , class TMessage >
UShort ESocket::UDP< TQueue, TMessage >::getLocalPort ( )
inline

Retrieves the port for this socket.

Returns
the port for this socket.

◆ getSending()

template<class TQueue , class TMessage >
Bool ESocket::UDP< TQueue, TMessage >::getSending ( )
inline

Retrieves indication if this socket is in the process of sending data.

Returns
True indicates that data is being sent, otherwise False.

◆ onError()

template<class TQueue , class TMessage >
virtual Void ESocket::UDP< TQueue, TMessage >::onError ( )
inlinevirtual

Called when an error is detected on this socket.

◆ onReceive()

template<class TQueue , class TMessage >
virtual Void ESocket::UDP< TQueue, TMessage >::onReceive ( const Address from,
pVoid  msg,
Int  len 
)
inlinevirtual

Called for each message that is received.

Parameters
fromthe socket address that the data was received from.
msgpointer to the received data.
lennumber of bytes received.

◆ setLocal() [1/2]

template<class TQueue , class TMessage >
UDP& ESocket::UDP< TQueue, TMessage >::setLocal ( const Address addr)
inline

Assigns the socket address for this socket.

Parameters
addrthe socket address for this socket.
Returns
a reference to this object.

◆ setLocal() [2/2]

template<class TQueue , class TMessage >
UDP& ESocket::UDP< TQueue, TMessage >::setLocal ( cpStr  addr,
UShort  port 
)
inline

Assigns the socket address for this socket.

Parameters
addrthe IP address for this socket.
portthe port for this socket.
Returns
a reference to this object.

◆ write()

template<class TQueue , class TMessage >
Void ESocket::UDP< TQueue, TMessage >::write ( const Address to,
pVoid  src,
Int  len 
)
inline

Sends data to the specified recipient address.

Parameters
tothe address to send the data to.
srca pointer to the beginning of the data buffer to send.
lenthe number of bytes to send.

Friends And Related Function Documentation

◆ Thread< TQueue, TMessage >

template<class TQueue , class TMessage >
friend class Thread< TQueue, TMessage >
friend

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