Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/network/tcp_socket.h @ 9850

Last change on this file since 9850 was 9406, checked in by bensch, 18 years ago

orxonox/trunk: merged the proxy back

merged with commandsvn merge -r9346:HEAD https://svn.orxonox.net/orxonox/branches/proxy .

no conflicts

File size: 2.2 KB
RevLine 
[7540]1/*!
[9406]2 * @file tcp_socket.h
3  *  tcp socket network interface
[7540]4
5*/
6
7#ifndef _TCP_SOCKET
8#define _TCP_SOCKET
9
[7541]10//TODO HACK else gdb will not work on server
11#define DONTEXITTHREADS
12
13//if you want to use outgoing buffer define _USE_OUTGOING_BUFFER
14#define _USE_OUTGOING_BUFFER
15
16#define _INCOMING_BUFFER_SIZE 2024000
17#define _OUTGOING_BUFFER_SIZE 2024000
[9406]18#define _LOCAL_BUFFER_SIZE 2048
[7541]19//sleep if incoming buffer is full
20#define _MSECONDS_SLEEP_FULL_BUFFER 10
21//sleep if outgoing buffer is empty
22#define _MSECONDS_SLEEP_EMPTY_BUFFER 10
23
24
25/* contains memmove and memcpy */
26#include <string.h>
27
28#ifdef HAVE_SDL_H
29#include <SDL_thread.h>
30#else
31#include <SDL/SDL_thread.h>
32#endif
[7540]33/* include this file, it contains some default definitions */
34#include "netdefs.h"
35
36
[7541]37/* include network_socket.h since all classes are derived from this one */
[7540]38#include "network_socket.h"
39
40class TcpSocket : public NetworkSocket
41{
42  public:
43    TcpSocket();
44    TcpSocket( std::string host, int port );
[7541]45    TcpSocket(TCPsocket sock);
[7540]46    virtual ~TcpSocket();
47
48    virtual void connectToServer( std::string host, int port );
[9406]49
[7540]50    virtual void disconnectServer();
[9406]51    virtual void reconnectToServer( std::string host, int port);
52    virtual void reconnectToServerSoft( std::string host, int port);
[7540]53
54    virtual bool writePacket(byte * data, int length);
55
56    virtual int readPacket(byte * data, int maxLength);
57
[7541]58  private:
59    TCPsocket tcpSocket;
[7540]60
[7541]61    byte incomingBuffer[_INCOMING_BUFFER_SIZE];
62#ifdef _USE_OUTGOING_BUFFER
63  byte outgoingBuffer[_OUTGOING_BUFFER_SIZE];
64#endif
65  int incomingBufferLength;
66#ifdef _USE_OUTGOING_BUFFER
67  int outgoingBufferLength;
68#endif
69
70  SDL_mutex * incomingBufferMutex;
71#ifdef _USE_OUTGOING_BUFFER
72  SDL_mutex * outgoingBufferMutex;
73#endif
74  SDL_mutex * socketMutex;
75  bool terminateThread;
76
77  SDL_mutex* threadTerminationMutex;
78  static int thread_read(void * data);
79  bool thread_read_running;
80  bool thread_write_running;
81
82  SDL_Thread*            readThread;
83  SDL_Thread*            writeThread;
84
85#ifdef _USE_OUTGOING_BUFFER
86  static int thread_write(void * data);
87#endif
88
89  int writeBytes(byte * data, int length);
90  int readBytes(byte * data, int length);
91  int readBlock(byte * data, int length);
92
93  void init();
94
[7540]95};
96
97
98
99#endif /* _NETWORK_SOCKET */
Note: See TracBrowser for help on using the repository browser.