TcpLib
Loading...
Searching...
No Matches
TcpMain.h
Go to the documentation of this file.
1#ifndef INC_TCPMAIN_H
2#define INC_TCPMAIN_H
3//-----------------------------------------------------------------------------
43//-----------------------------------------------------------------------------
44#include "TcpTypes.h"
45
46#if defined (__PTHREADS)
47 #include "EuEndlessPThread.h"
48 #include <semaphore.h>
49#else
50 #include "EuRepeatingThread.h"
51#endif
52
53#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
54 #include <winsock.h>
55#elif defined(__GNUC__)
56 /*
57 #include <stdio.h>
58 #include <stdlib.h>
59 #include <unistd.h>
60 */
61 #include <string.h>
62
63 #include <errno.h>
64 #include <sys/types.h>
65 #include <sys/socket.h>
66 #include <netinet/in.h>
67 #include <netdb.h>
68 #include <arpa/inet.h>
69 #define SOCKET uintptr_t
70 #define SOCKADDR_IN sockaddr_in
71 #define SOCKADDR sockaddr
72 #define HOSTENT hostent
73 #define INVALID_SOCKET (SOCKET)(~0)
74 #define SOCKET_ERROR (-1)
75#endif
76//-----------------------------------------------------------------------------
77namespace tcp
78{
79 //---------------------------------------------------------------------------
80 // Forwards
81 class Message;
82 //---------------------------------------------------------------------------
83 #ifdef _MSC_VER
84 /* 'Bezeichner': Klasse 'Typ' benötigt eine DLL-Schnittstelle, die von... */
85 #pragma warning( disable : 4251 )
86 /* class 'TYP' ist keine DLL-Schnittstelle und wurde als Basisklasse... */
87 #pragma warning( disable : 4275 )
88 #endif
89 //---------------------------------------------------------------------------
105 #if defined (__PTHREADS)
106 class __tcp_export_dll TcpMain : public EuEndlessPThread
107 #else
109 #endif
110 {
111 private:
112 //============== static-attributes
113 //-----------------------------------------------------------------------
127 static unsigned int m_uiTcpMainCounter;
128 //-----------------------------------------------------------------------
129
130 protected:
131 //============== attributes
132 //-----------------------------------------------------------------------
144 //-----------------------------------------------------------------------
156 unsigned int m_uiServerPort;
157 //-----------------------------------------------------------------------
169 unsigned int m_uiDataSize;
170 //-----------------------------------------------------------------------
181 //-----------------------------------------------------------------------
192 //-----------------------------------------------------------------------
203 //-----------------------------------------------------------------------
214 //-----------------------------------------------------------------------
215
216 //============== ctor
217 //-----------------------------------------------------------------------
228 //-----------------------------------------------------------------------
229
230 public:
231 //============== ctors
232 //-----------------------------------------------------------------------
264 TcpMain( unsigned int uiPort,
265 int iAdressFamily,
266 int iSocketType,
267 int iProtocol,
268 int iSecTimeOut );
269 //-----------------------------------------------------------------------
303 TcpMain( unsigned int uiPort,
304 int iAdressFamily,
305 int iSocketType,
306 int iProtocol,
307 unsigned int uiDataSize,
308 int iSecTimeOut );
309 //-----------------------------------------------------------------------
319 virtual ~TcpMain();
320 //-----------------------------------------------------------------------
321
322 private:
323 //============== copy-ctor
324 //-----------------------------------------------------------------------
334 TcpMain( const TcpMain & );
335 //-----------------------------------------------------------------------
336
337 public:
338 //============== methods
339 //-----------------------------------------------------------------------
349 unsigned int getPortNum() const;
350 //-----------------------------------------------------------------------
364 virtual void setDataSize( unsigned int uiDataSize );
365 //-----------------------------------------------------------------------
375 unsigned int getDataSize() const;
376 //-----------------------------------------------------------------------
386 SOCKET getMainSocket() const;
387 //-----------------------------------------------------------------------
413 virtual int send( Message * pTcpMessage ) = 0;
414 //-----------------------------------------------------------------------
426 void setTimeOutSec( int iSecTimeOut );
427 //-----------------------------------------------------------------------
440 //-----------------------------------------------------------------------
441
442 protected:
443 //============== methods
444 //-----------------------------------------------------------------------
456 void setWSACleanup() const;
457 //-----------------------------------------------------------------------
469 int startWinsock() const;
470 //-----------------------------------------------------------------------
471
472 private:
473 //============== operators
474 //-----------------------------------------------------------------------
484 TcpMain & operator= ( const TcpMain & );
485 //-----------------------------------------------------------------------
486 };
487 //---------------------------------------------------------------------------
488 #ifdef _MSC_VER
489 /* 'Bezeichner': Klasse 'Typ' benötigt eine DLL-Schnittstelle, die von... */
490 #pragma warning( default : 4251 )
491 /* class 'TYP' ist keine DLL-Schnittstelle und wurde als Basisklasse... */
492 #pragma warning( default : 4275 )
493 #endif
494 //---------------------------------------------------------------------------
495} // namespace tcp
496//-----------------------------------------------------------------------------
497#endif
Header for RepeatingThread
For each library, here 'TcpLib' there is a type file.
#define __tcp_export_dll
Definition TcpTypes.h:59
Base class for a thread that executes its work endlessly until aborted.
Definition EuRepeatingThread.h:93
Contains a data stream which can be sent and received by the Tcp classes.
Definition TcpMessage.h:168
Superclass for Client and Server, which 'learns' its know-how in the derived classes.
Definition TcpMain.h:110
unsigned int getPortNum() const
void setWSACleanup() const
SOCKET m_MainSocket
Definition TcpMain.h:213
virtual void setDataSize(unsigned int uiDataSize)
TcpMain(const TcpMain &)
SOCKET getMainSocket() const
int startWinsock() const
virtual ~TcpMain()
int m_iSecTimeOut
Definition TcpMain.h:143
virtual int send(Message *pTcpMessage)=0
unsigned int m_uiServerPort
Definition TcpMain.h:156
int m_iSocketType
Definition TcpMain.h:191
TcpMain(unsigned int uiPort, int iAdressFamily, int iSocketType, int iProtocol, int iSecTimeOut)
unsigned int m_uiDataSize
Definition TcpMain.h:169
int m_iAdressFamily
Definition TcpMain.h:180
int TimeOutSec()
static unsigned int m_uiTcpMainCounter
Definition TcpMain.h:127
unsigned int getDataSize() const
TcpMain(unsigned int uiPort, int iAdressFamily, int iSocketType, int iProtocol, unsigned int uiDataSize, int iSecTimeOut)
void setTimeOutSec(int iSecTimeOut)
int m_iProtocol
Definition TcpMain.h:202
Definition TcpClient.h:55