Revision 29
added some doxygen comments
trunk/code/projects/colonet/ColonetServer/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; |
trunk/code/projects/colonet/ColonetServer/ColonetServer.cpp | ||
---|---|---|
1 |
/** @file ColonetServer.cpp |
|
1 |
/** |
|
2 |
* @file ColonetServer.cpp |
|
2 | 3 |
* |
3 | 4 |
* @brief colonet_server - primary server application for Colonet |
4 | 5 |
* |
... | ... | |
29 | 30 |
|
30 | 31 |
ConnectionPool * connection_pool; |
31 | 32 |
|
33 |
/** |
|
34 |
* @brief Default constructor for ColonetServer |
|
35 |
*/ |
|
32 | 36 |
ColonetServer::ColonetServer(): logger("logFile.txt") { |
33 | 37 |
listen_socket = 0; |
34 | 38 |
} |
35 | 39 |
|
40 |
/** |
|
41 |
* @brief Destructor for ColonetServer |
|
42 |
*/ |
|
36 | 43 |
ColonetServer::~ColonetServer() { |
37 | 44 |
} |
38 | 45 |
|
46 |
/** |
|
47 |
* @brief Initializes the various elements needed for the server to run |
|
48 |
* |
|
49 |
* @param argc The number of command line arguments passed to the program |
|
50 |
* @param argv The command line arguments passed to the program |
|
51 |
* |
|
52 |
* @return 0 on success, negative error code on failure |
|
53 |
*/ |
|
39 | 54 |
int ColonetServer::initialize_server(int argc, char * argv[]) { |
40 | 55 |
printf("Initializing Server...\n"); |
41 | 56 |
|
... | ... | |
53 | 68 |
return 0; |
54 | 69 |
} |
55 | 70 |
|
71 |
/** |
|
72 |
* @brief Starts the server listening on the socket that was opened for listening |
|
73 |
* |
|
74 |
* @return 0 on success, negative error code on failure |
|
75 |
*/ |
|
56 | 76 |
int ColonetServer::start_listening() { |
57 | 77 |
if (listen(listen_socket, LISTEN_BACKLOG) < 0) { |
58 | 78 |
log_error("\t\nThere was an error telling the socket to " |
... | ... | |
62 | 82 |
return 0; |
63 | 83 |
} |
64 | 84 |
|
85 |
/** |
|
86 |
* @brief Logs an error message to the log file |
|
87 |
*/ |
|
65 | 88 |
int ColonetServer::log_error(char * error_message) { |
66 | 89 |
return logger.logMessage(LOG_TYPE_ERROR, error_message); |
67 | 90 |
} |
68 | 91 |
|
92 |
/** |
|
93 |
* @brief Logs a message to the log file |
|
94 |
*/ |
|
69 | 95 |
int ColonetServer::log_message(char * message) { |
70 | 96 |
return logger.logMessage(LOG_TYPE_MESSAGE, message); |
71 | 97 |
} |
72 | 98 |
|
99 |
/** |
|
100 |
* @brief Starts the server running (starts an infinite loop) |
|
101 |
*/ |
|
73 | 102 |
int ColonetServer::run_server() { |
74 | 103 |
connection_pool.set_listen_socket_in_ready_set(listen_socket); |
75 | 104 |
|
... | ... | |
135 | 164 |
return 0; |
136 | 165 |
} |
137 | 166 |
|
167 |
/** |
|
168 |
* @todo This method is here because the wireless message handler has a dependency on the connection_pool |
|
169 |
* This should be removed when that dependency is broken |
|
170 |
* |
|
171 |
* @return A pointer to the connection pool |
|
172 |
*/ |
|
138 | 173 |
ConnectionPool * ColonetServer::get_connection_pool_pointer() { |
139 | 174 |
return &connection_pool; |
140 | 175 |
} |
141 | 176 |
|
177 |
/** |
|
178 |
* @brief Initializes the wireless |
|
179 |
* |
|
180 |
* @return 0 on success, negative error code on error |
|
181 |
*/ |
|
142 | 182 |
int ColonetServer::initialize_wireless() { |
143 | 183 |
char* log_filename = NULL; |
144 | 184 |
|
... | ... | |
159 | 199 |
return 0; |
160 | 200 |
} |
161 | 201 |
|
202 |
/** |
|
203 |
* @brief Initialize a connection to listen on |
|
204 |
* |
|
205 |
* @port The port to try to open to listen on |
|
206 |
* |
|
207 |
* @return 0 on success, negative error code on error |
|
208 |
*/ |
|
162 | 209 |
int ColonetServer::initialize_connection(int port) { |
163 | 210 |
printf("Initializing connection that will be used to listen for " |
164 | 211 |
"clients...\n"); |
... | ... | |
201 | 248 |
return 0; |
202 | 249 |
} |
203 | 250 |
|
251 |
/** |
|
252 |
* @brief The main function of the server |
|
253 |
* |
|
254 |
* @param argc The number of command line arguments passed to the program |
|
255 |
* @param argv The command line arguments passed to the program |
|
256 |
* |
|
257 |
* @return 0 on success, negative error code on error |
|
258 |
*/ |
|
204 | 259 |
int main(int argc, char** argv) { |
205 | 260 |
ColonetServer colonet_server; |
206 | 261 |
|
Also available in: Unified diff