GlobalObjects
Loading...
Searching...
No Matches
tcp::TcpMain Class Referenceabstract

Superclass for Client and Server, which 'learns' its know-how in the derived classes. More...

#include <TcpMain.h>

Inheritance diagram for tcp::TcpMain:

Public Member Functions

 TcpMain (unsigned int uiPort, int iAdressFamily, int iSocketType, int iProtocol, int iSecTimeOut)
 
 TcpMain (unsigned int uiPort, int iAdressFamily, int iSocketType, int iProtocol, unsigned int uiDataSize, int iSecTimeOut)
 
virtual ~TcpMain ()
 
unsigned int getDataSize () const
 
SOCKET getMainSocket () const
 
unsigned int getPortNum () const
 
virtual int send (Message *pTcpMessage)=0
 
virtual void setDataSize (unsigned int uiDataSize)
 
void setTimeOutSec (int iSecTimeOut)
 
int TimeOutSec ()
 
- Public Member Functions inherited from eut::RepeatingThread
 RepeatingThread ()
 
virtual ~RepeatingThread ()
 
virtual void cancel ()
 
virtual void finishBreak ()
 
int getBreakCounter ()
 
bool isInExclusiveAccess () const
 
void setExclusiveAccess ()
 
void signalInput ()
 
virtual int start ()
 
RepeatingThread::STATUS status () const
 
virtual void takeABreak ()
 
bool testCancel ()
 
void unsetExclusiveAccess ()
 
void waitForInput ()
 

Protected Member Functions

 TcpMain ()
 
void setWSACleanup () const
 
int startWinsock () const
 
- Protected Member Functions inherited from eut::RepeatingThread
ORDER getOrder ()
 
STATUS getStatus ()
 
void setStatus (STATUS eStatus)
 
void threadWork ()
 
void toOrder (ORDER eOrder)
 
virtual void work ()=0
 

Protected Attributes

int m_iAdressFamily
 
int m_iProtocol
 
int m_iSecTimeOut
 
int m_iSocketType
 
SOCKET m_MainSocket
 
unsigned int m_uiDataSize
 
unsigned int m_uiServerPort
 

Private Member Functions

 TcpMain (const TcpMain &)
 
TcpMainoperator= (const TcpMain &)
 

Static Private Attributes

static unsigned int m_uiTcpMainCounter
 

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  ORDER { eUNDEFINED , eDO_WORK , eEXIT }
 
enum  STATUS {
  eAT_THE_START , eWORKING , ePAUSING , eENDING ,
  eCOMPLETED
}
 
- Public Attributes inherited from eut::RepeatingThread
std::string m_strDebugInfo
 

Detailed Description

Superclass for Client and Server, which 'learns' its know-how in the derived classes.

Author
Helmut Jakoby

Constructor & Destructor Documentation

◆ TcpMain() [1/4]

tcp::TcpMain::TcpMain ( )
protected

This constructor is not available.

◆ TcpMain() [2/4]

tcp::TcpMain::TcpMain ( unsigned int uiPort,
int iAdressFamily,
int iSocketType,
int iProtocol,
int iSecTimeOut )

Constructor with parameter passing.

Parameters
[in]uiPortThe port of the server.
[in]iAdressFamilyThe socket address family to instantiate a socket (usually AF_INET).
[in]iSocketTypeThe socket type (usually SOCK_STREAM).
[in]iProtocolThe socket protocol (usually 0).
[in]iSecTimeOutThe time until waiting for a connection or waiting for data is aborted.

It is started under Windows WSA.

Exceptions
eut::ErrorNExceptionAn exception is thrown if an error occurs.

◆ TcpMain() [3/4]

tcp::TcpMain::TcpMain ( unsigned int uiPort,
int iAdressFamily,
int iSocketType,
int iProtocol,
unsigned int uiDataSize,
int iSecTimeOut )

Constructor with parameter passing.

Parameters
[in]uiPortThe port of the server.
[in]iAdressFamilyThe socket address family to instantiate a socket (usually AF_INET).
[in]iSocketTypeThe socket type (usually SOCK_STREAM).
[in]iProtocolThe socket protocol (usually 0).
[in]uiDataSizeThe packet size.
[in]iSecTimeOutThe time until waiting for a connection or waiting for data is aborted.

It is started under Windows WSA.

Exceptions
eut::ErrorNExceptionAn exception is thrown if an error occurs.

◆ ~TcpMain()

virtual tcp::TcpMain::~TcpMain ( )
virtual

Destructor. It is terminated under Windows WSA.

◆ TcpMain() [4/4]

tcp::TcpMain::TcpMain ( const TcpMain & )
private

The copy constructor is not available.

Member Function Documentation

◆ getDataSize()

unsigned int tcp::TcpMain::getDataSize ( ) const

Returns the packet size.

◆ getMainSocket()

SOCKET tcp::TcpMain::getMainSocket ( ) const

Returns the socket.

◆ getPortNum()

unsigned int tcp::TcpMain::getPortNum ( ) const

Returns the port number.

◆ operator=()

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

The assignment operator is not available.

◆ send()

virtual int tcp::TcpMain::send ( Message * pTcpMessage)
pure virtual

Sends transferred Message to the counterpart.

If This is a client, the counterpart is the server. If This is a server, the counterpart is the server. Sends transferred message to the counterpart socket referenced there.

The implementation is executed in the subclass.

Parameters
[in]pTcpMessageThe message to be sent.
Returns
A return < 0 indicates an error.

Implemented in tcp::Client, and tcp::Server.

◆ setDataSize()

virtual void tcp::TcpMain::setDataSize ( unsigned int uiDataSize)
virtual

Sets the packet size.

Parameters
[in]uiDataSizeThe package size must be greater than 0.
Exceptions
eut::ErrorNExceptionAn exception is thrown if an error occurs.

Reimplemented in tcp::Client.

◆ setTimeOutSec()

void tcp::TcpMain::setTimeOutSec ( int iSecTimeOut)

Sets the seconds to wait for responses.

Parameters
[in]iSecTimeOutThe maximum waiting time.

◆ setWSACleanup()

void tcp::TcpMain::setWSACleanup ( ) const
protected

It decrements m_uiTcpMainCounter and on Windows if 0, calls WSACleanup() (closes ALL connections)

◆ startWinsock()

int tcp::TcpMain::startWinsock ( ) const
protected

It is started under Windows WSA using WSAStartup().

Returns
A return value < 0 indicates an error.

◆ TimeOutSec()

int tcp::TcpMain::TimeOutSec ( )

Returns the seconds how long the system waits for answers.

Returns
The maximum waiting time.

Member Data Documentation

◆ m_iAdressFamily

int tcp::TcpMain::m_iAdressFamily
protected

The Socket AddressFamily (usually AF_INET) to instantiate a socket.

◆ m_iProtocol

int tcp::TcpMain::m_iProtocol
protected

The socket protocol (usually 0) to instantiate a socket.

◆ m_iSecTimeOut

int tcp::TcpMain::m_iSecTimeOut
protected

Waiting time for connection responses. if not set, the wait may be eternal!

◆ m_iSocketType

int tcp::TcpMain::m_iSocketType
protected

The socket type (usually SOCK_STREAM) to instantiate a socket.

◆ m_MainSocket

SOCKET tcp::TcpMain::m_MainSocket
protected

The socket.

◆ m_uiDataSize

unsigned int tcp::TcpMain::m_uiDataSize
protected

Packets are made from the data stream; here the packet size (default is DEFAULT_DATASIZE).

◆ m_uiServerPort

unsigned int tcp::TcpMain::m_uiServerPort
protected

The port of the socket.
Further information under en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers

◆ m_uiTcpMainCounter

unsigned int tcp::TcpMain::m_uiTcpMainCounter
staticprivate

This counter is incremented each time an object of this class or subclass is instantiated. With each call to setWSACleanup() it is decremented again.

See also
setWSACleanup()

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