#include <netmanager.h>
Inheritance diagram for NetManager:
Public Methods | |
NetManager () | |
Creates a NetManager. More... | |
void | keepSending (bool go_on=true) |
Starts/stops data sending. More... | |
virtual | ~NetManager () |
Destroys all the data structures. More... | |
void | waitForData () |
Waits until there is data ready. More... | |
bool | dataReady () |
Tells if there is data ready in the socket. More... | |
Static Public Attributes | |
const Uint16 | SERVER_PORT = 57570 |
Port the server will be listening at. | |
const int | PACKET_SIZE = 1600 |
Size of the UDP packets sent through the network. | |
Protected Methods | |
virtual void | onReception (unsigned client) |
Method called after reception of a packet from a certain client. More... | |
void | transmit (const UDPsocket &sock, const MessagePacket &msg) const |
Performs the actual transmission of the data through the socket. | |
virtual void | manageReception () |
Controls the data reception. More... | |
virtual bool | forwardMessage (const MessagePacket &msg, IPaddress *ip)=0 |
Determines whether the message should or not be forwarded to the user. More... | |
Protected Attributes | |
queue< MessagePacket > | inputBuffer |
Contains the unread packets received from the receiverSocket. | |
IPaddress | serverIP |
IP address for the server. More... | |
UDPsocket | receiverSocket |
Socket used for data reception. More... | |
Uint16 | actualPort |
Keeps the actual port through the data will be sent. | |
SDL_Thread * | receiver |
Controls the reception of data. More... | |
bool | exitControllers |
Tells the controller when to exit. More... | |
bool | keepSendingFlag |
Allows/forbids data sending. More... | |
SDL_mutex * | sendingMutex |
Controls the access to keepSendingFlag. | |
SDL_mutex * | exitMutex |
Controls the access to the exitController flag. More... | |
SDL_cond * | dataReadyCond |
The 'waitForData' method locks here to wait for data to be ready. | |
SDL_mutex * | dataReadyMutex |
Controls the access to dataReadyMutex. | |
SDLNet_SocketSet | receiverSet |
Used to control the arrival of new data. | |
SDL_mutex * | socketOpen |
Prevents the reception thread from accessing a not ready NetManager. More... | |
Friends | |
int | receiverCallback (void *data) |
Calls the receiver thread method. More... |
Network manager class for Perihelion, with capabilities to send and receive MessagePacket objects, and return them to the class' users.
Please be aware of methods that can throw exceptions when indicated.
Note: Unless we find an use for them, channels in UCP sockets will be ignored, and 0 will be used by default.
|
Creates a NetManager. Creates a NetManager object, although most of the work is done in the subclasses. |
|
Destroys all the data structures. Flushes the remaining data, closes the socket and destroys all the data structures. |
|
Tells if there is data ready in the socket. Tells if there is data ready to gather from the client socket. This method can raise exceptions if something goes wrong, so please catch the 'string'.
|
|
Determines whether the message should or not be forwarded to the user.
Implemented in NetManagerClient, and NetManagerServer. |
|
Starts/stops data sending. Starts/stops data sending, by constraining the behavior of the 'flush' method. |
|
Controls the data reception. Controls the network reception, offering the upper layer a simplified view. This code is run asinchronously, in the 'receiver' thread. |
|
Method called after reception of a packet from a certain client. This is intended to serve the inherited classes to manage events like this.
Reimplemented in NetManagerServer. |
|
Waits until there is data ready. Waits until there is data ready in the input buffers. If there is already some data, it just exits. It can be used to control the network activity from a separate thread without having to poll it constantly. |
|
Calls the receiver thread method. Calls the receiver thread method. It is needed to initialize the SDL_Thread that gets data from the connection (it cannot be a method, as long as I know). |
|
Tells the controller when to exit. Gently tells the controllers when to exit, instead of just killing the threads. When it is set to true and the controller threads are running (otherwise it would be nice to wake them up), it does its last loop and exit. |
|
Controls the access to the exitController flag. Controls the access to the exitController flag, and should be used anytime we enter/leave its critical section. |
|
Allows/forbids data sending. Allows/forbids data sending, by controlling the 'flush' method. |
|
Controls the reception of data. This thread controls the reception of data. MUST be running in order to actually get some transactions done, instead of endless buffering. This thread can only be stopped when destroying the NetManager. |
|
Socket used for data reception. Socket used for data reception and, in the case of clients, also for sending. |
|
IP address for the server. Keeps the IP address for the server, both in the server and the client. in the client it is more important because we need to know where to send the data. In the server it is still needed to open the connection and listen. |
|
Prevents the reception thread from accessing a not ready NetManager. Prevents the reception thread from accessing a not ready NetManager. Must be unlocked in the subclasses right after the receiver socket (maybe a few more) is created. |