Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

fixed some bugs

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