Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5722 was 5722, checked in by bknecht, 18 years ago

set BufferSize in DataStream, patched NetworkSocket for SDL

File size: 1.9 KB
Line 
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
10//if you want to use outgoing buffer define _USE_OUTGOING_BUFFER
11#define _USE_OUTGOING_BUFFER
12
13#define _INCOMING_BUFFER_SIZE 10240
14#define _OUTGOING_BUFFER_SIZE 2024000
15#define _LOCAL_BUFFER_SIZE 1024
16//sleep if incoming buffer is full
17#define _MSECONDS_SLEEP_FULL_BUFFER 10
18//sleep if outgoing buffer is empty
19#define _MSECONDS_SLEEP_EMPTY_BUFFER 10
20
21/* contains memmove and memcpy */
22#include <string.h>
23
24#ifdef HAVE_SDL_H
25#include <SDL_Thread.h>
26#else
27#include <SDL/SDL_thread.h>
28#endif
29/* include this file, it contains some default definitions */
30#include "netdefs.h"
31
32
33/* include base_object.h since all classes are derived from this one */
34#include "base_object.h"
35
36/* using namespace std is default, this needs to be here */
37using namespace std;
38
39class NetworkSocket : public BaseObject
40{
41
42private:
43//  IPaddress serverAddress;
44//  unsigned int port;
45  TCPsocket tcpSocket;
46//  UDPsocket udpSocket;
47
48  byte incomingBuffer[_INCOMING_BUFFER_SIZE];
49#ifdef _USE_OUTGOING_BUFFER
50  byte outgoingBuffer[_OUTGOING_BUFFER_SIZE];
51#endif
52  int incomingBufferLength;
53#ifdef _USE_OUTGOING_BUFFER
54  int outgoingBufferLength;
55#endif
56
57  SDL_mutex * incomingBufferMutex;
58#ifdef _USE_OUTGOING_BUFFER
59  SDL_mutex * outgoingBufferMutex;
60#endif
61  SDL_mutex * socketMutex;
62  bool terminateThread;
63
64  static int thread_listen(void * data);
65  static int thread_read(void * data);
66#ifdef _USE_OUTGOING_BUFFER
67  static int thread_write(void * data);
68#endif
69
70  bool _isListening;
71
72public:
73
74  NetworkSocket();
75  ~NetworkSocket();
76
77  void connectToServer(IPaddress ip, unsigned int port);
78  void listen(unsigned int port);
79  void disconnectServer();
80  int writeBytes(byte * data, int length);
81  int readBytes(byte * data, int length);
82
83};
84
85
86
87#endif /* _NETWORK_SOCKET */
Note: See TracBrowser for help on using the repository browser.