TcpLib
Loading...
Searching...
No Matches
tcp::ServerReceiver Class Reference

Class that communicates with a Client via a SOCKET and delivers its receive result of type ServerMessage to its "owner", which must be a Server. You can use the method ServerReceiver::acceptMessage(AbstractMessage * pTcpMessage) to change the delivery to the "owner" in subclasses by overwriting the method. More...

#include <TcpServerReceiver.h>

Inheritance diagram for tcp::ServerReceiver:
Collaboration diagram for tcp::ServerReceiver:

Public Member Functions

 ServerReceiver (Server *pParent, SOCKET Socket, unsigned int uiDataSize)
 
virtual ~ServerReceiver ()
 
virtual void cancel () override
 
void setValid (bool bValid)
 
- Public Member Functions inherited from tcp::DataReceiver
 DataReceiver (TcpMain *pParent, SOCKET Socket, unsigned int uiDataSize)
 
virtual ~DataReceiver ()
 
void setDataSize (unsigned int uiDataSize)
 
unsigned int getDataSize () const
 
- Public Member Functions inherited from tcp::Receiver
 Receiver (TcpMain *pParent, SOCKET Socket)
 
virtual ~Receiver ()
 
- Public Member Functions inherited from tcp::ReceiverTransmitter
 ReceiverTransmitter (SOCKET Socket)
 
virtual ~ReceiverTransmitter ()
 
virtual void takeABreak () override
 
virtual void finishBreak () override
 
int getPeerName (std::string &rstrIPAdress, unsigned int &ruiPort) const
 
SOCKET Socket () const
 
- Public Member Functions inherited from eut::RepeatingThread
 RepeatingThread ()
 
virtual ~RepeatingThread ()
 
virtual int start ()
 
bool testCancel ()
 
RepeatingThread::STATUS status () const
 
bool isInExclusiveAccess () const
 
void setExclusiveAccess ()
 
void unsetExclusiveAccess ()
 
int getBreakCounter ()
 
void waitForInput ()
 
void signalInput ()
 

Protected Member Functions

 ServerReceiver ()
 
 ServerReceiver (SOCKET)
 
 ServerReceiver (TcpMain *, SOCKET)
 
 ServerReceiver (TcpMain *, SOCKET, unsigned int)
 
virtual void work () override
 
virtual int acceptMessage (AbstractMessage *pTcpServerMessage) override
 
virtual void generateNewTcpMessage (AbstractMessage *&prTcpServerMessage, char *pszTransmitData, unsigned int uiTransmitDataSize) const override
 
virtual void generateNewTcpMessage (AbstractMessage *&prTcpServerMessage, char *pszRawMsg, unsigned int uiRawMsgSize, unsigned int uiMessageID, int iActionCode, const std::string &rstrInfo) const override
 
- Protected Member Functions inherited from tcp::DataReceiver
 DataReceiver ()
 
 DataReceiver (SOCKET)
 
 DataReceiver (TcpMain *, SOCKET)
 
void initStreamData ()
 
int processReceivedData (char *pszSentBuffer, unsigned int t_uiSentBufferSize)
 
- Protected Member Functions inherited from tcp::Receiver
 Receiver ()
 
 Receiver (SOCKET Socket)
 
- Protected Member Functions inherited from tcp::ReceiverTransmitter
 ReceiverTransmitter ()
 
- Protected Member Functions inherited from eut::RepeatingThread
void threadWork ()
 
void setStatus (STATUS eStatus)
 
STATUS getStatus ()
 
void toOrder (ORDER eOrder)
 
ORDER getOrder ()
 

Protected Attributes

bool m_bValid
 
- Protected Attributes inherited from tcp::DataReceiver
unsigned int m_uiDataSize
 
unsigned int m_uiStreamSize
 
unsigned int m_uiStreamPosistion
 
char * m_szStreamBuffer
 
char * m_pszSentBuffer
 
- Protected Attributes inherited from tcp::Receiver
TcpMainm_pParentTcpMain
 
- Protected Attributes inherited from tcp::ReceiverTransmitter
SOCKET m_Socket
 

Private Member Functions

 ServerReceiver (const ServerReceiver &)
 
ServerReceiveroperator= (const ServerReceiver &)
 

Additional Inherited Members

- Public Types inherited from eut::RepeatingThread
enum  EuTHREADERROR { EuTHREAD_ERR_NO_THREAD = -10301 , EuTHREAD_ERR_THREAD_ALREADY_WORKING = -10302 , EuTHREAD_ERR_THREAD_BREAK_COUNT_LESS_THAN_ZERO = -10303 , EuTHREAD_ERR_UNKNOWN = -10400 }
 Error range = -10301 to -10400 More...
 
enum  STATUS {
  eAT_THE_START , eWORKING , ePAUSING , eENDING ,
  eCOMPLETED
}
 
enum  ORDER { eUNDEFINED , eDO_WORK , eEXIT }
 

Detailed Description

Class that communicates with a Client via a SOCKET and delivers its receive result of type ServerMessage to its "owner", which must be a Server. You can use the method ServerReceiver::acceptMessage(AbstractMessage * pTcpMessage) to change the delivery to the "owner" in subclasses by overwriting the method.

Author
Helmut Jakoby

Constructor & Destructor Documentation

◆ ServerReceiver() [1/6]

tcp::ServerReceiver::ServerReceiver ( )
protected

This constructor is not available.

◆ ServerReceiver() [2/6]

tcp::ServerReceiver::ServerReceiver ( SOCKET )
protected

This constructor is not available.

◆ ServerReceiver() [3/6]

tcp::ServerReceiver::ServerReceiver ( TcpMain * ,
SOCKET  )
protected

This constructor is not available.

◆ ServerReceiver() [4/6]

tcp::ServerReceiver::ServerReceiver ( TcpMain * ,
SOCKET ,
unsigned int  )
protected

This constructor is not available.

◆ ServerReceiver() [5/6]

tcp::ServerReceiver::ServerReceiver ( Server * pParent,
SOCKET Socket,
unsigned int uiDataSize )

Constructor with parameter passing.

Parameters
[in]pParentThe owning parent object.
[in]SocketThe socket through which communication takes place.
[in]uiDataSizeThe package size.
Exceptions
eut::ErrorNExceptionAn exception is thrown if an error occurs.

◆ ~ServerReceiver()

virtual tcp::ServerReceiver::~ServerReceiver ( )
virtual

Destructor.

◆ ServerReceiver() [6/6]

tcp::ServerReceiver::ServerReceiver ( const ServerReceiver & )
private

The copy constructor is not available.

Member Function Documentation

◆ acceptMessage()

virtual int tcp::ServerReceiver::acceptMessage ( AbstractMessage * pTcpServerMessage)
overrideprotectedvirtual

Forwards the transferred message to its Server, which also deletes the message after processing.
The Server can then process these further in subclasses if necessary. If processing in a subclass of ClientReceiver is required, this method can also be overwritten.

Parameters
[in]pTcpServerMessageThe received message.
Returns
A return < 0 indicates an error.
Attention
The passed object must not be removed from memory by the calling instance.
See also
ServerMessage

Implements tcp::DataReceiver.

◆ cancel()

virtual void tcp::ServerReceiver::cancel ( )
overridevirtual

Terminates the thread.

Reimplemented from eut::RepeatingThread.

◆ generateNewTcpMessage() [1/2]

virtual void tcp::ServerReceiver::generateNewTcpMessage ( AbstractMessage *& prTcpServerMessage,
char * pszRawMsg,
unsigned int uiRawMsgSize,
unsigned int uiMessageID,
int iActionCode,
const std::string & rstrInfo ) const
overrideprotectedvirtual

Generates a ServerMessage from transferred parameters.

Parameters
[in,out]prTcpServerMessagePointer to newly generated ServerMessage. This object takes over the removal of the pszRawMsg from the memory.
[in]pszRawMsgThe message data.
[in]uiRawMsgSizeThe size or length of the message data.
[in]uiMessageIDA unique ID.
[in]iActionCodeThe ActionCode.
[in]rstrInfoAn additional text info
Attention
The supplied object must be removed from memory by the calling instance.
Exceptions
eut::ErrorNExceptionIf no ServerMessage can be instantiated from the parameters, an exception is thrown.
See also
ServerMessage

Implements tcp::DataReceiver.

◆ generateNewTcpMessage() [2/2]

virtual void tcp::ServerReceiver::generateNewTcpMessage ( AbstractMessage *& prTcpServerMessage,
char * pszTransmitData,
unsigned int uiTransmitDataSize ) const
overrideprotectedvirtual

Generates a ServerMessage from the transferred data buffer and its size.

Parameters
[in,out]prTcpServerMessagePointer to newly generated ServerMessage. This object takes care of removing the pszTransmitData from the memory.
[in]pszTransmitDataThe data buffer including all required information.
[in]uiTransmitDataSizeThe size or length of the data buffer to be sent.
Attention
The supplied object must be removed from memory by the calling instance.
Exceptions
eut::ErrorNExceptionIf no ServerMessage can be instantiated from the data (because, for example, the header is incorrect), an exception is thrown.
See also
ServerMessage

Implements tcp::DataReceiver.

◆ operator=()

ServerReceiver & tcp::ServerReceiver::operator= ( const ServerReceiver & )
private

The assignment operator is not available.

◆ setValid()

void tcp::ServerReceiver::setValid ( bool bValid)

Called when socket is no longer ok.

Parameters
[in]bValidIf there is a SOCKET error, false is passed here.

◆ work()

virtual void tcp::ServerReceiver::work ( )
overrideprotectedvirtual

Accepts streams from its socket (is blocked until received), turns the data into a ServerMessage which is further processed in ServerReceiver::acceptMessage(AbstractMessage * pTcpMessage).

Implements eut::RepeatingThread.

Member Data Documentation

◆ m_bValid

bool tcp::ServerReceiver::m_bValid
protected

Set to false if socket is no longer ok.


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