root / trunk / code / projects / colonet / server / includes / ConnectionPool.h @ 501
History | View | Annotate | Download (1.72 KB)
1 |
/**
|
---|---|
2 |
* @author Jason Knichel
|
3 |
* @date 7/22/07
|
4 |
*/
|
5 |
|
6 |
#ifndef CONNECTION_POOL_H
|
7 |
#define CONNECTION_POOL_H
|
8 |
|
9 |
#include <sys/select.h> |
10 |
|
11 |
#include <colonet_wireless.h> |
12 |
#include <ColonetServer.h> |
13 |
|
14 |
#define MAX_TOKENS 15 |
15 |
#define MAX_TOKEN_SIZE 30 |
16 |
|
17 |
#define ROBOT_COMMAND_OFFSET 1 |
18 |
#define ROBOT_COMMAND_LEN 3 |
19 |
|
20 |
#define ERROR_INVALID_CLIENT_DESCRIPTOR -1 |
21 |
#define ERROR_TOO_MANY_CLIENTS -2 |
22 |
#define ERROR_ALLOCATING_MEMORY -3 |
23 |
#define ERROR_NOT_ENOUGH_ROOM -4 |
24 |
#define ERROR_INVALID_COMMAND -5 |
25 |
#define ERROR_INVALID_CLIENT_ID -6 |
26 |
#define ERROR_INVALID_MESSAGE -7 |
27 |
#define ERROR_INVALID_MESSAGE_LENGTH -8 |
28 |
|
29 |
#define DECREMENT_INDEX_COUNTER 1 |
30 |
|
31 |
#define MAX_CONNECTIONS 250 |
32 |
#define READ_BUFFER_SIZE 1024 |
33 |
#define WRITE_BUFFER_SIZE 4096 |
34 |
|
35 |
class ColonetServer; |
36 |
|
37 |
class ConnectionPool { |
38 |
|
39 |
public:
|
40 |
ConnectionPool(ColonetServer* cs); |
41 |
~ConnectionPool(); |
42 |
|
43 |
int add_client(int client_file_descriptor); |
44 |
int remove_client(int pool_index); |
45 |
int check_clients();
|
46 |
|
47 |
int write_to_client(int pool_index, char * message, int length); |
48 |
void add_new_socket_to_pool(int new_socket); |
49 |
int perform_select(int listen_socket); |
50 |
int is_socket_ready_to_read(int socket); |
51 |
int get_number_clients_ready();
|
52 |
|
53 |
private:
|
54 |
int max_file_descriptor;
|
55 |
int next_available_slot;
|
56 |
int number_clients_ready;
|
57 |
fd_set ready_set; |
58 |
fd_set read_set; |
59 |
fd_set write_set; |
60 |
int client_file_descriptor_array[MAX_CONNECTIONS];
|
61 |
char * read_buffer[MAX_CONNECTIONS];
|
62 |
int read_buffer_size[MAX_CONNECTIONS];
|
63 |
char * write_buffer[MAX_CONNECTIONS];
|
64 |
int write_buffer_size[MAX_CONNECTIONS];
|
65 |
ColonetServer* colonet_server; |
66 |
|
67 |
int read_data(int pool_index, int client_file_descriptor); |
68 |
int write_data(int pool_index, int client_file_descriptor); |
69 |
}; |
70 |
|
71 |
#endif
|