Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/lib/network/network_socket.h @ 6944

Last change on this file since 6944 was 6944, checked in by rennerc, 18 years ago

networkSocket: hack for gdb

File size: 2.3 KB
RevLine 
[5531]1/*!
2 * @file network_socket.h
3  *  Main interface for the network module. Manages all the modules
4
5*/
6
7#ifndef _NETWORK_SOCKET
8#define _NETWORK_SOCKET
9
[6944]10//HACK else gdb will not work on server
11#define DONTEXITTHREADS
12
[5630]13//if you want to use outgoing buffer define _USE_OUTGOING_BUFFER
14#define _USE_OUTGOING_BUFFER
15
[6923]16#define _INCOMING_BUFFER_SIZE 2024000
[5631]17#define _OUTGOING_BUFFER_SIZE 2024000
[5624]18#define _LOCAL_BUFFER_SIZE 1024
[5630]19//sleep if incoming buffer is full
[5628]20#define _MSECONDS_SLEEP_FULL_BUFFER 10
[5630]21//sleep if outgoing buffer is empty
22#define _MSECONDS_SLEEP_EMPTY_BUFFER 10
[5624]23
[5996]24
[5624]25/* contains memmove and memcpy */
26#include <string.h>
27
[5722]28#ifdef HAVE_SDL_H
[5822]29 #include <SDL_thread.h>
[5732]30#else
[5822]31 #include <SDL/SDL_thread.h>
[5722]32#endif
[5565]33/* include this file, it contains some default definitions */
34#include "netdefs.h"
[5531]35
[5565]36
[5592]37/* include base_object.h since all classes are derived from this one */
38#include "base_object.h"
[5588]39
[5565]40/* using namespace std is default, this needs to be here */
41using namespace std;
42
[5592]43class NetworkSocket : public BaseObject
[5531]44{
45
[5565]46private:
[5624]47//  IPaddress serverAddress;
48//  unsigned int port;
[5592]49  TCPsocket tcpSocket;
[5624]50//  UDPsocket udpSocket;
[5565]51
[5630]52  byte incomingBuffer[_INCOMING_BUFFER_SIZE];
53#ifdef _USE_OUTGOING_BUFFER
54  byte outgoingBuffer[_OUTGOING_BUFFER_SIZE];
55#endif
56  int incomingBufferLength;
57#ifdef _USE_OUTGOING_BUFFER
58  int outgoingBufferLength;
59#endif
[5624]60
[5630]61  SDL_mutex * incomingBufferMutex;
62#ifdef _USE_OUTGOING_BUFFER
63  SDL_mutex * outgoingBufferMutex;
64#endif
65  SDL_mutex * socketMutex;
[5624]66  bool terminateThread;
67
[6139]68  SDL_mutex* threadTerminationMutex;
[5624]69  static int thread_read(void * data);
[6139]70  bool thread_read_running;
71  bool thread_write_running;
72
73  SDL_Thread*            readThread;
74  SDL_Thread*            writeThread;
75
[5630]76#ifdef _USE_OUTGOING_BUFFER
77  static int thread_write(void * data);
78#endif
[5624]79
[5996]80  int writeBytes(byte * data, int length);
81  int readBytes(byte * data, int length);
82  int readBlock(byte * data, int length);
[5630]83
[5996]84  void init();
85
[5531]86public:
87
88  NetworkSocket();
[6695]89  ~NetworkSocket();
[5804]90  NetworkSocket(IPaddress ip);
[5996]91  NetworkSocket(TCPsocket sock);
[6139]92  void destroy() { terminateThread = true; };
[5533]93
[6139]94
[5804]95  void connectToServer(IPaddress ip);
[5531]96  void disconnectServer();
[5533]97
[5996]98  bool writePacket(byte * data, int length);
99  int readPacket(byte * data, int maxLength);
[5808]100
[6139]101  inline bool isOk() { return tcpSocket!=NULL; }
102
[5531]103};
104
105
106
[5532]107#endif /* _NETWORK_SOCKET */
Note: See TracBrowser for help on using the repository browser.