Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / colonet / ColonetServer / includes / ConnectionPool.h @ 443

History | View | Annotate | Download (1.63 KB)

1 11 emarinel
/**
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 22 jknichel
#include <colonet_wireless.h>
12
13 11 emarinel
#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 22 jknichel
#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 11 emarinel
28 145 jknichel
#define DECREMENT_INDEX_COUNTER          1
29
30 11 emarinel
#define MAX_CONNECTIONS 250
31
#define READ_BUFFER_SIZE 1024
32 75 jknichel
#define WRITE_BUFFER_SIZE 4096
33 11 emarinel
34
class ConnectionPool {
35
36
public:
37
  ConnectionPool();
38
  ~ConnectionPool();
39
40
  int add_client(int client_file_descriptor);
41 27 jknichel
  int remove_client(int pool_index);
42 118 emarinel
  int check_clients();
43 143 jknichel
44 14 jknichel
  int write_to_client(int pool_index, char * message, int length);
45 143 jknichel
  void add_new_socket_to_pool(int new_socket);
46 58 jknichel
  int perform_select(int listen_socket);
47 11 emarinel
  int is_socket_ready_to_read(int socket);
48
  int get_number_clients_ready();
49
50
private:
51
  int max_file_descriptor;
52
  int next_available_slot;
53
  int number_clients_ready;
54
  fd_set ready_set;
55
  fd_set read_set;
56
  fd_set write_set;
57
  int client_file_descriptor_array[MAX_CONNECTIONS];
58
  char * read_buffer[MAX_CONNECTIONS];
59
  int read_buffer_size[MAX_CONNECTIONS];
60
  char * write_buffer[MAX_CONNECTIONS];
61
  int write_buffer_size[MAX_CONNECTIONS];
62
63 145 jknichel
  int read_data(int pool_index, int client_file_descriptor);
64
  int write_data(int pool_index, int client_file_descriptor);
65 11 emarinel
};
66
67
#endif