Revision 22
moved around some more code
ConnectionPool.cpp | ||
---|---|---|
114 | 114 |
//TODO: test that it drops commands properly if it gets sent too much data |
115 | 115 |
// do we want it to drop the data or drop the connection? |
116 | 116 |
//TODO: give variables a better name |
117 |
int ConnectionPool::check_clients() { |
|
117 |
int ConnectionPool::check_clients(ColonetWireless * wireless) {
|
|
118 | 118 |
char temp[READ_BUFFER_SIZE]; |
119 | 119 |
char tempCommand[READ_BUFFER_SIZE+1]; |
120 | 120 |
int i; |
... | ... | |
197 | 197 |
break; |
198 | 198 |
} |
199 | 199 |
|
200 |
if (parse_command(tempCommand, i) < 0) { |
|
200 |
if (parse_command(tempCommand, i, wireless) < 0) {
|
|
201 | 201 |
printf("There was an error parsing command\n"); |
202 | 202 |
break; |
203 | 203 |
} |
... | ... | |
220 | 220 |
} |
221 | 221 |
|
222 | 222 |
int ConnectionPool::write_to_client(int pool_index, char * message, int length) { |
223 |
//TODO: put error checking on pool_index, message, length |
|
223 |
if (pool_index < 0 || pool_index >= next_available_slot) { |
|
224 |
return ERROR_INVALID_CLIENT_ID; |
|
225 |
} |
|
226 |
|
|
227 |
if (!message) { |
|
228 |
return ERROR_INVALID_MESSAGE; |
|
229 |
} |
|
230 |
|
|
231 |
if (length < 0) { |
|
232 |
return ERROR_INVALID_MESSAGE_LENGTH; |
|
233 |
} |
|
234 |
|
|
224 | 235 |
if (length > (WRITE_BUFFER_SIZE-write_buffer_size[pool_index])) |
225 | 236 |
{ |
226 | 237 |
//TODO: make this a logging statement instead of a print statement |
227 | 238 |
printf("There is not enough room in the write buffer to send the data to the client.\n"); |
228 |
return -1;
|
|
239 |
return ERROR_NOT_ENOUGH_ROOM;
|
|
229 | 240 |
} |
230 | 241 |
|
231 | 242 |
memcpy(write_buffer[pool_index], message, length); |
... | ... | |
303 | 314 |
|
304 | 315 |
//TODO: write a function to write data into the write buffers |
305 | 316 |
//TODO: fix names of variables to obey new style |
306 |
int ConnectionPool::parse_command(char* command, int pool_index) { |
|
317 |
int ConnectionPool::parse_command(char* command, int pool_index, ColonetWireless * wireless) {
|
|
307 | 318 |
char tokens[MAX_TOKENS][MAX_TOKEN_SIZE]; |
308 | 319 |
unsigned char int_tokens[MAX_TOKENS]; |
309 | 320 |
int numTokens = 0; |
... | ... | |
373 | 384 |
/* Send packet to robot */ |
374 | 385 |
fprintf(stderr, "Calling wireless->send(%d, %d, %d, args)\n", |
375 | 386 |
int_tokens[0], int_tokens[1], int_tokens[2]); |
376 |
send_wireless_message(int_tokens[0], int_tokens[1], int_tokens[2], args);
|
|
387 |
wireless->send(int_tokens[0], int_tokens[1], int_tokens[2], args);
|
|
377 | 388 |
} |
378 | 389 |
|
379 | 390 |
return 0; |
Also available in: Unified diff