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

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

#include <esocket.h>

Inheritance diagram for ESocket::TCP::Talker< TQueue, TMessage >:
ESocket::Base< TQueue, TMessage >

Public Member Functions

 Talker (Thread< TQueue, TMessage > &thread, Int bufsize=2097152)
 Class constructor. More...
 
virtual ~Talker ()
 Class destrucor. More...
 
AddressgetLocal ()
 Retrieves the local socket address. More...
 
EString getLocalAddress () const
 Retrieves the IP address associated with the local socket. More...
 
UShort getLocalPort () const
 Retrieves the port associated with the local socket. More...
 
TalkersetLocal (cpStr addr, UShort port)
 Assigns the local socket address. More...
 
TalkersetLocal (const Address &addr)
 Assigns the local socket address. More...
 
AddressgetRemote ()
 Retrieves the remote socket address. More...
 
EString getRemoteAddress () const
 Retrieves the IP address associated with the remote socket. More...
 
UShort getRemotePort () const
 Retrieves the port associated with the remote socket. More...
 
TalkersetRemote (cpStr addr, UShort port)
 Assigns the remote socket address. More...
 
TalkersetRemote (const Address &addr)
 Assigns the remote socket address. More...
 
Void connect ()
 Initiates an IP connection with to the previously assigned remote socket address. More...
 
Void connect (Address &addr)
 Initiates an IP connection. More...
 
Void connect (cpStr addr, UShort port)
 Initiates an IP connection. More...
 
Int bytesPending ()
 Retrieves the number of bytes in the receive buffer. More...
 
Int peek (pUChar dest, Int len)
 Rtrieves the specified number of bytes from the receive buffer without updating the read position. More...
 
Int read (pUChar dest, Int len)
 Rtrieves the specified number of bytes from the receive buffer. More...
 
Void write (pUChar src, Int len)
 Writes data to the socket. This is a thread safe method. More...
 
Bool getSending ()
 Retrieves indication if this socket is in the process of sending data. More...
 
SocketState getState ()
 Retrieves the connection state. More...
 
cpStr getStateDescription ()
 Retrieves the description of the current connection state. More...
 
Void disconnect ()
 Disconnects this socket. More...
 
virtual Void onReceive ()
 Called when data has been received. More...
 
virtual Void onConnect ()
 Called when a connection has been established. More...
 
virtual Void onClose ()
 Called when the socket has been closed. More...
 
virtual Void onError ()
 Called when an error is detected on the 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::TCP::Talker< TQueue, TMessage >

A TCP socket class capabile of sending and receiving data.

Constructor & Destructor Documentation

◆ Talker()

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

Class constructor.

Parameters
threadthe socket thread that this socket is associated with.
bufsizethe size of the send and receive circular buffers.

◆ ~Talker()

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

Class destrucor.

Member Function Documentation

◆ bytesPending()

template<class TQueue , class TMessage >
Int ESocket::TCP::Talker< TQueue, TMessage >::bytesPending ( )
inline

Retrieves the number of bytes in the receive buffer.

Returns
the number of bytes in the receive buffer.

◆ connect() [1/3]

template<class TQueue , class TMessage >
Void ESocket::TCP::Talker< TQueue, TMessage >::connect ( )
inline

Initiates an IP connection with to the previously assigned remote socket address.

◆ connect() [2/3]

template<class TQueue , class TMessage >
Void ESocket::TCP::Talker< TQueue, TMessage >::connect ( Address addr)
inline

Initiates an IP connection.

Parameters
addrthe remote socket address.

◆ connect() [3/3]

template<class TQueue , class TMessage >
Void ESocket::TCP::Talker< TQueue, TMessage >::connect ( cpStr  addr,
UShort  port 
)
inline

Initiates an IP connection.

Parameters
addrthe remote socket IP address.
portthe remote socket port.

◆ disconnect()

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

Disconnects this socket.

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

◆ getLocal()

template<class TQueue , class TMessage >
Address& ESocket::TCP::Talker< TQueue, TMessage >::getLocal ( )
inline

Retrieves the local socket address.

Returns
the local socket address.

◆ getLocalAddress()

template<class TQueue , class TMessage >
EString ESocket::TCP::Talker< TQueue, TMessage >::getLocalAddress ( ) const
inline

Retrieves the IP address associated with the local socket.

Returns
the IP address associated with the local socket.

◆ getLocalPort()

template<class TQueue , class TMessage >
UShort ESocket::TCP::Talker< TQueue, TMessage >::getLocalPort ( ) const
inline

Retrieves the port associated with the local socket.

the port associated with the local socket.

◆ getRemote()

template<class TQueue , class TMessage >
Address& ESocket::TCP::Talker< TQueue, TMessage >::getRemote ( )
inline

Retrieves the remote socket address.

Returns
the remote socket address.

◆ getRemoteAddress()

template<class TQueue , class TMessage >
EString ESocket::TCP::Talker< TQueue, TMessage >::getRemoteAddress ( ) const
inline

Retrieves the IP address associated with the remote socket.

Returns
the IP address associated with the remote socket.

◆ getRemotePort()

template<class TQueue , class TMessage >
UShort ESocket::TCP::Talker< TQueue, TMessage >::getRemotePort ( ) const
inline

Retrieves the port associated with the remote socket.

the port associated with the remote socket.

◆ getSending()

template<class TQueue , class TMessage >
Bool ESocket::TCP::Talker< 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.

◆ getState()

template<class TQueue , class TMessage >
SocketState ESocket::TCP::Talker< TQueue, TMessage >::getState ( )
inline

Retrieves the connection state.

Returns
the connection state.

◆ getStateDescription()

template<class TQueue , class TMessage >
cpStr ESocket::TCP::Talker< TQueue, TMessage >::getStateDescription ( )
inline

Retrieves the description of the current connection state.

Returns
the description of the current connection state.

◆ onClose()

template<class TQueue , class TMessage >
virtual Void ESocket::TCP::Talker< TQueue, TMessage >::onClose ( )
inlinevirtual

Called when the socket has been closed.

◆ onConnect()

template<class TQueue , class TMessage >
virtual Void ESocket::TCP::Talker< TQueue, TMessage >::onConnect ( )
inlinevirtual

Called when a connection has been established.

◆ onError()

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

Called when an error is detected on the socket.

◆ onReceive()

template<class TQueue , class TMessage >
virtual Void ESocket::TCP::Talker< TQueue, TMessage >::onReceive ( )
inlinevirtual

Called when data has been received.

◆ peek()

template<class TQueue , class TMessage >
Int ESocket::TCP::Talker< TQueue, TMessage >::peek ( pUChar  dest,
Int  len 
)
inline

Rtrieves the specified number of bytes from the receive buffer without updating the read position.

Parameters
destthe location to write the data read.
lenthe desired number of bytes to read.
Returns
the number of actual bytes read.

◆ read()

template<class TQueue , class TMessage >
Int ESocket::TCP::Talker< TQueue, TMessage >::read ( pUChar  dest,
Int  len 
)
inline

Rtrieves the specified number of bytes from the receive buffer.

Parameters
destthe location to write the data read.
lenthe desired number of bytes to read.
Returns
the number of actual bytes read.

◆ setLocal() [1/2]

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

Assigns the local socket address.

Parameters
addrthe address object to copy.
Returns
a reference to this Talker object.

◆ setLocal() [2/2]

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

Assigns the local socket address.

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

◆ setRemote() [1/2]

template<class TQueue , class TMessage >
Talker& ESocket::TCP::Talker< TQueue, TMessage >::setRemote ( const Address addr)
inline

Assigns the remote socket address.

Parameters
addrthe address object to copy.
Returns
a reference to this Talker object.

◆ setRemote() [2/2]

template<class TQueue , class TMessage >
Talker& ESocket::TCP::Talker< TQueue, TMessage >::setRemote ( cpStr  addr,
UShort  port 
)
inline

Assigns the remote socket address.

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

◆ write()

template<class TQueue , class TMessage >
Void ESocket::TCP::Talker< TQueue, TMessage >::write ( pUChar  src,
Int  len 
)
inline

Writes data to the socket. This is a thread safe method.

Parameters
srcthe location to the data to write.
lenthe desired number of bytes to write.

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: