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