Last change
on this file since 5628 was
5628,
checked in by rennerc, 18 years ago
|
network_unit_test.cc: added test for much data
network_socket: added delay if input buffer is full
|
File size:
1.2 KB
|
Rev | Line | |
---|
[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 | |
---|
[5624] | 10 | #define _INCOMING_BUFFER_SIZE 10240 |
---|
| 11 | #define _LOCAL_BUFFER_SIZE 1024 |
---|
[5628] | 12 | #define _MSECONDS_SLEEP_FULL_BUFFER 10 |
---|
[5624] | 13 | |
---|
| 14 | /* contains memmove and memcpy */ |
---|
| 15 | #include <string.h> |
---|
| 16 | |
---|
| 17 | #include <SDL_thread.h> |
---|
| 18 | |
---|
[5565] | 19 | /* include this file, it contains some default definitions */ |
---|
| 20 | #include "netdefs.h" |
---|
[5531] | 21 | |
---|
[5565] | 22 | |
---|
[5592] | 23 | /* include base_object.h since all classes are derived from this one */ |
---|
| 24 | #include "base_object.h" |
---|
[5588] | 25 | |
---|
[5565] | 26 | /* using namespace std is default, this needs to be here */ |
---|
| 27 | using namespace std; |
---|
| 28 | |
---|
[5592] | 29 | class NetworkSocket : public BaseObject |
---|
[5531] | 30 | { |
---|
| 31 | |
---|
[5565] | 32 | private: |
---|
[5624] | 33 | // IPaddress serverAddress; |
---|
| 34 | // unsigned int port; |
---|
[5592] | 35 | TCPsocket tcpSocket; |
---|
[5624] | 36 | // UDPsocket udpSocket; |
---|
[5565] | 37 | |
---|
[5624] | 38 | byte buf[_INCOMING_BUFFER_SIZE]; |
---|
| 39 | int bufferlength; |
---|
| 40 | |
---|
| 41 | SDL_mutex * mutex; |
---|
[5625] | 42 | SDL_mutex * socketmutex; |
---|
[5624] | 43 | bool terminateThread; |
---|
| 44 | |
---|
| 45 | static int thread_listen(void * data); |
---|
| 46 | static int thread_read(void * data); |
---|
| 47 | |
---|
[5531] | 48 | public: |
---|
| 49 | |
---|
| 50 | NetworkSocket(); |
---|
| 51 | ~NetworkSocket(); |
---|
[5533] | 52 | |
---|
[5565] | 53 | void connectToServer(IPaddress ip, unsigned int port); |
---|
| 54 | void listen(unsigned int port); |
---|
[5531] | 55 | void disconnectServer(); |
---|
[5614] | 56 | int writeBytes(byte * data, int length); |
---|
| 57 | int readBytes(byte * data, int length); |
---|
[5533] | 58 | |
---|
[5531] | 59 | }; |
---|
| 60 | |
---|
| 61 | |
---|
| 62 | |
---|
[5532] | 63 | #endif /* _NETWORK_SOCKET */ |
---|
Note: See
TracBrowser
for help on using the repository browser.