Revision 29
added some doxygen comments
ConnectionPool.cpp | ||
---|---|---|
1 | 1 |
/** |
2 |
* @file ConnectionPool.cpp |
|
3 |
* |
|
2 | 4 |
* @author Jason Knichel |
3 | 5 |
* @date 7/22/07 |
4 | 6 |
*/ |
... | ... | |
15 | 17 |
#include "includes/client.h" |
16 | 18 |
#include "../lib/colonet_defs.h" |
17 | 19 |
|
20 |
/** |
|
21 |
* @brief The default constructor for ConnectionPool |
|
22 |
*/ |
|
18 | 23 |
ConnectionPool::ConnectionPool() { |
19 | 24 |
max_file_descriptor = 0; |
20 | 25 |
next_available_slot = 0; |
... | ... | |
31 | 36 |
memset(&write_buffer_size, 0, sizeof(int)*MAX_CONNECTIONS); |
32 | 37 |
} |
33 | 38 |
|
39 |
/** |
|
40 |
* @brief The destructor for ConnectionPool |
|
41 |
*/ |
|
34 | 42 |
ConnectionPool::~ConnectionPool() { |
35 | 43 |
} |
36 | 44 |
|
45 |
/** |
|
46 |
* @brief Adds a client to the connection pool |
|
47 |
* |
|
48 |
* @param client_file_descriptor The file descriptor to add to the connection pool |
|
49 |
* |
|
50 |
* @return 0 on success, negative error code on failure |
|
51 |
*/ |
|
37 | 52 |
int ConnectionPool::add_client(int client_file_descriptor) { |
38 | 53 |
if (client_file_descriptor < 0) { |
39 | 54 |
return ERROR_INVALID_CLIENT_DESCRIPTOR; |
... | ... | |
71 | 86 |
return 0; |
72 | 87 |
} |
73 | 88 |
|
89 |
/** |
|
90 |
* @brief Removes a client from the connection pool |
|
91 |
* |
|
92 |
* @param The index in the pool of the client to remove |
|
93 |
* |
|
94 |
* @return 0 on success, negative error code on failure |
|
95 |
*/ |
|
74 | 96 |
int ConnectionPool::remove_client(int pool_index) { |
75 | 97 |
if (pool_index < 0 || pool_index >= next_available_slot) { |
76 | 98 |
return ERROR_INVALID_CLIENT_DESCRIPTOR; |
... | ... | |
111 | 133 |
return 0; |
112 | 134 |
} |
113 | 135 |
|
136 |
/** |
|
137 |
* @brief Checks the status of the clients |
|
138 |
* |
|
139 |
* Sees is any clients are ready to read from their file descriptor or are |
|
140 |
* ready to write to their file descriptor. |
|
141 |
* |
|
142 |
* @param wireless A pointer to the wireless object |
|
143 |
* |
|
144 |
* @return 0 on success, negative error code on error |
|
145 |
*/ |
|
114 | 146 |
//TODO: test that it drops commands properly if it gets sent too much data |
115 | 147 |
// do we want it to drop the data or drop the connection? |
116 | 148 |
int ConnectionPool::check_clients(ColonetWireless * wireless) { |
... | ... | |
218 | 250 |
return 0; |
219 | 251 |
} |
220 | 252 |
|
253 |
/** |
|
254 |
* @brief Puts text into a write buffer that will be written to a client's file |
|
255 |
* descriptor sometime when the client is ready to write. |
|
256 |
* |
|
257 |
* @param pool_index Index in the pool of the client to write to |
|
258 |
* @param message The message to be written |
|
259 |
* @param length The length of the message |
|
260 |
* |
|
261 |
* @return 0 on success, negative error code on failure |
|
262 |
*/ |
|
221 | 263 |
int ConnectionPool::write_to_client(int pool_index, char * message, int length) { |
222 | 264 |
if (pool_index < 0 || pool_index >= next_available_slot) { |
223 | 265 |
return ERROR_INVALID_CLIENT_ID; |
... | ... | |
244 | 286 |
return 0; |
245 | 287 |
} |
246 | 288 |
|
247 |
|
|
289 |
/** |
|
290 |
* @brief Sets the socket to listen on |
|
291 |
* |
|
292 |
* @param listen_socket The socket to listen on |
|
293 |
* |
|
294 |
* @return void |
|
295 |
*/ |
|
248 | 296 |
//TODO: put error checking on listen_socket to make sure its a valid socket |
249 | 297 |
void ConnectionPool::set_listen_socket_in_ready_set(int listen_socket) { |
250 | 298 |
FD_SET(listen_socket, &ready_set); |
251 | 299 |
} |
252 | 300 |
|
301 |
/** |
|
302 |
* @todo Since the listen socket is now a member of the class, the first parameter can be removed |
|
303 |
* @todo Does the select timeout need to be passed in? or can it be specified in the method? |
|
304 |
* |
|
305 |
* @brief Find out what file descriptors are ready to write to and read from |
|
306 |
* |
|
307 |
* @param listen_socket The socket to listen on |
|
308 |
* @param select_timeout The timeout for the select statement |
|
309 |
* |
|
310 |
* @return 0 |
|
311 |
*/ |
|
253 | 312 |
int ConnectionPool::perform_select(int listen_socket, struct timeval * select_timeout) { |
254 | 313 |
read_set = ready_set; |
255 | 314 |
write_set = ready_set; |
... | ... | |
315 | 374 |
//TODO: fix names of variables to obey new style |
316 | 375 |
int ConnectionPool::parse_command(char* command, int pool_index, ColonetWireless * wireless) { |
317 | 376 |
char tokens[MAX_TOKENS][MAX_TOKEN_SIZE]; |
318 |
unsigned char int_tokens[MAX_TOKENS]; |
|
377 |
unsigned cnhar int_tokens[MAX_TOKENS];
|
|
319 | 378 |
int numTokens = 0; |
320 | 379 |
char* endptr = NULL; |
321 | 380 |
int commandID; |
Also available in: Unified diff