root / trunk / code / projects / colonet / ColonetServer / includes / ConnectionPool.h @ 11
History | View | Annotate | Download (1.94 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 |
#define MAX_TOKENS 15 |
12 |
#define MAX_TOKEN_SIZE 30 |
13 |
|
14 |
#define ROBOT_COMMAND_OFFSET 1 |
15 |
#define ROBOT_COMMAND_LEN 3 |
16 |
|
17 |
#define ERROR_INVALID_CLIENT_DESCRIPTOR -1 |
18 |
#define ERROR_TOO_MANY_CLIENTS -2 |
19 |
#define ERROR_ALLOCATING_MEMORY -3 |
20 |
|
21 |
#define MAX_CONNECTIONS 250 |
22 |
#define READ_BUFFER_SIZE 1024 |
23 |
#define WRITE_BUFFER_SIZE 1024 |
24 |
|
25 |
class ConnectionPool { |
26 |
|
27 |
public:
|
28 |
ConnectionPool(); |
29 |
~ConnectionPool(); |
30 |
|
31 |
int add_client(int client_file_descriptor); |
32 |
int remove_client(int client_file_descriptor); |
33 |
int check_clients();
|
34 |
void set_listen_socket_in_ready_set(int listen_socket); |
35 |
int perform_select(int listen_socket, struct timeval * select_timeout); |
36 |
int is_socket_ready_to_read(int socket); |
37 |
int is_socket_ready_to_write(int socket); |
38 |
|
39 |
|
40 |
int get_max_file_descriptor();
|
41 |
void set_max_file_descriptor(int new_max_file_descriptor); |
42 |
|
43 |
int get_next_available_slot();
|
44 |
|
45 |
int get_number_clients_ready();
|
46 |
void set_number_clients_ready(int new_number_clients_ready); |
47 |
|
48 |
fd_set get_ready_set(); |
49 |
|
50 |
fd_set get_read_set(); |
51 |
void set_read_set(fd_set new_set);
|
52 |
|
53 |
fd_set get_write_set(); |
54 |
void set_write_set(fd_set new_set);
|
55 |
|
56 |
int get_write_buffer_size(int pool_index); |
57 |
void set_write_buffer_size(int pool_index, int new_buffer_size); |
58 |
|
59 |
char * get_write_buffer(int pool_index); |
60 |
|
61 |
|
62 |
private:
|
63 |
int max_file_descriptor;
|
64 |
int next_available_slot;
|
65 |
int number_clients_ready;
|
66 |
fd_set ready_set; |
67 |
fd_set read_set; |
68 |
fd_set write_set; |
69 |
int client_file_descriptor_array[MAX_CONNECTIONS];
|
70 |
char * read_buffer[MAX_CONNECTIONS];
|
71 |
int read_buffer_size[MAX_CONNECTIONS];
|
72 |
char * write_buffer[MAX_CONNECTIONS];
|
73 |
int write_buffer_size[MAX_CONNECTIONS];
|
74 |
|
75 |
int parse_command(char* command, int pool_index); |
76 |
int tokenize_command(char* command, char tokens[MAX_TOKENS][MAX_TOKEN_SIZE]); |
77 |
int check_tokens(unsigned char* tokens, int numTokens); |
78 |
}; |
79 |
|
80 |
#endif
|