Revision 34
Small colonet cleanup.
trunk/code/projects/colonet/ColonetServer/client.cpp | ||
---|---|---|
26 | 26 |
int wirelessMessageHandler(ColonetPacket* pkt) |
27 | 27 |
{ |
28 | 28 |
printf("Received wireless message!!!\n"); |
29 |
if (!pkt) |
|
30 |
{ |
|
29 |
if (!pkt) { |
|
31 | 30 |
printf("The packet pointer was null.\n"); |
32 | 31 |
return -1; |
33 | 32 |
} |
34 | 33 |
|
35 |
if ((int)pkt->msg_type == COLONET_RESPONSE) |
|
36 |
{ |
|
34 |
if ((int)pkt->msg_type == COLONET_RESPONSE) { |
|
37 | 35 |
printf("response\n"); |
38 | 36 |
|
39 | 37 |
int dest = (int)(pkt->msg_dest); |
40 |
|
|
41 | 38 |
char buffer[WRITE_BUFFER_SIZE]; |
42 | 39 |
|
43 | 40 |
int value = (int)(pkt->data[0]); |
... | ... | |
50 | 47 |
} |
51 | 48 |
|
52 | 49 |
printf("Put data in write buffer for client.\n"); |
53 |
} |
|
54 |
else |
|
55 |
{ |
|
50 |
} else { |
|
56 | 51 |
printf("not a response\n"); |
57 | 52 |
} |
58 | 53 |
|
59 | 54 |
pkt = 0; |
60 | 55 |
return 0; |
61 | 56 |
} |
62 |
|
trunk/code/projects/colonet/ColonetServer/Logging.cpp | ||
---|---|---|
10 | 10 |
|
11 | 11 |
#include "includes/Logging.h" |
12 | 12 |
|
13 |
|
|
14 |
Log::Log(char * filename) |
|
15 |
{ |
|
16 |
|
|
13 |
Log::Log(char * filename) { |
|
17 | 14 |
printf("Creating log object\n"); |
18 | 15 |
|
19 |
if (!filename) |
|
20 |
{ |
|
21 |
fprintf(stderr, "Provided a null filename when trying to create a log.\n"); |
|
22 |
return; |
|
23 |
} |
|
16 |
if (!filename) { |
|
17 |
fprintf(stderr, "Provided a null filename when trying to create a log.\n"); |
|
18 |
return; |
|
19 |
} |
|
24 | 20 |
|
25 | 21 |
logFile = fopen(filename, "a"); //open file for appending |
26 |
if (!logFile) |
|
27 |
{ |
|
28 |
fprintf(stderr, "Error opening %s as log file.\n", filename); |
|
29 |
return; |
|
30 |
} |
|
22 |
if (!logFile) { |
|
23 |
fprintf(stderr, "Error opening %s as log file.\n", filename); |
|
24 |
return; |
|
25 |
} |
|
31 | 26 |
|
32 | 27 |
printf("About to log start message.\n"); |
33 | 28 |
logMessage(LOG_TYPE_START_LOG, "Starting server"); |
... | ... | |
52 | 47 |
|
53 | 48 |
int Log::logMessage(int type, char * message) |
54 | 49 |
{ |
55 |
if (!logFile) |
|
56 |
{ |
|
57 |
fprintf(stderr, "Tried to log a message but the file pointer was null.\n"); |
|
58 |
return -1; |
|
59 |
} |
|
60 |
if (!message) |
|
61 |
{ |
|
62 |
fprintf(stderr, "Tried to log a null message.\n"); |
|
63 |
return -1; |
|
64 |
} |
|
50 |
if (!logFile) { |
|
51 |
fprintf(stderr, "Tried to log a message but the file pointer was null.\n"); |
|
52 |
return -1; |
|
53 |
} |
|
54 |
|
|
55 |
if (!message) { |
|
56 |
fprintf(stderr, "Tried to log a null message.\n"); |
|
57 |
return -1; |
|
58 |
} |
|
65 | 59 |
|
66 | 60 |
static char * start_log = "Starting Log"; |
67 | 61 |
static char * connect = "Client Connecting"; |
... | ... | |
71 | 65 |
|
72 | 66 |
char * messageType; |
73 | 67 |
|
74 |
switch(type) |
|
75 |
{ |
|
76 |
case LOG_TYPE_START_LOG: |
|
77 |
messageType = start_log; |
|
78 |
break; |
|
79 |
case LOG_TYPE_CONNECT: |
|
80 |
messageType = connect; |
|
81 |
break; |
|
82 |
case LOG_TYPE_DISCONNECT: |
|
83 |
messageType = disconnect; |
|
84 |
break; |
|
85 |
case LOG_TYPE_ERROR: |
|
86 |
messageType = error; |
|
87 |
break; |
|
88 |
case LOG_TYPE_MESSAGE: |
|
89 |
messageType = logGenMessage; |
|
90 |
break; |
|
91 |
default: |
|
92 |
fprintf(stderr, "Tried to log a message with an invalid type.\n"); |
|
93 |
return -1; |
|
94 |
} |
|
68 |
switch(type) { |
|
69 |
case LOG_TYPE_START_LOG: |
|
70 |
messageType = start_log; |
|
71 |
break; |
|
72 |
case LOG_TYPE_CONNECT: |
|
73 |
messageType = connect; |
|
74 |
break; |
|
75 |
case LOG_TYPE_DISCONNECT: |
|
76 |
messageType = disconnect; |
|
77 |
break; |
|
78 |
case LOG_TYPE_ERROR: |
|
79 |
messageType = error; |
|
80 |
break; |
|
81 |
case LOG_TYPE_MESSAGE: |
|
82 |
messageType = logGenMessage; |
|
83 |
break; |
|
84 |
default: |
|
85 |
fprintf(stderr, "Tried to log a message with an invalid type.\n"); |
|
86 |
return -1; |
|
87 |
} |
|
95 | 88 |
|
96 | 89 |
struct tm currTime = getCurrentTime(); |
97 | 90 |
|
... | ... | |
101 | 94 |
buffer[len-1] = '\0'; //remove the newline that is put at the end by asctime_r |
102 | 95 |
fprintf(logFile, "%s %*s %s\n", buffer, LOG_MAX_TYPE_LENGTH, messageType, message); |
103 | 96 |
fflush(logFile); |
104 |
|
|
105 | 97 |
|
106 | 98 |
return 0; |
107 | 99 |
} |
108 |
|
trunk/code/projects/colonet/ColonetServer/ConnectionPool.cpp | ||
---|---|---|
273 | 273 |
return ERROR_INVALID_MESSAGE_LENGTH; |
274 | 274 |
} |
275 | 275 |
|
276 |
if (length > (WRITE_BUFFER_SIZE-write_buffer_size[pool_index])) |
|
277 |
{ |
|
278 |
//TODO: make this a logging statement instead of a print statement |
|
279 |
printf("There is not enough room in the write buffer to send the data to the client.\n"); |
|
280 |
return ERROR_NOT_ENOUGH_ROOM; |
|
281 |
} |
|
276 |
if (length > (WRITE_BUFFER_SIZE-write_buffer_size[pool_index])) { |
|
277 |
//TODO: make this a logging statement instead of a print statement |
|
278 |
printf("There is not enough room in the write buffer to send the data to the client.\n"); |
|
279 |
return ERROR_NOT_ENOUGH_ROOM; |
|
280 |
} |
|
282 | 281 |
|
283 | 282 |
memcpy(write_buffer[pool_index], message, length); |
284 | 283 |
write_buffer_size[pool_index] += length; |
trunk/code/projects/colonet/ColonetServer/ColonetServer.cpp | ||
---|---|---|
111 | 111 |
socklen_t client_addr_size = sizeof(client_addr); |
112 | 112 |
struct timeval select_timeout; |
113 | 113 |
|
114 |
memset(&select_timeout,0,sizeof(select_timeout));
|
|
114 |
memset(&select_timeout, 0, sizeof(select_timeout));
|
|
115 | 115 |
|
116 | 116 |
log_message("Server initialized. About to start listening for connections"); |
117 | 117 |
|
... | ... | |
193 | 193 |
//probably be false (changed for demo purposes) |
194 | 194 |
|
195 | 195 |
if (!wireless->run_listener_thread()) { |
196 |
return -1;
|
|
197 |
}
|
|
196 |
return -1;
|
|
197 |
}
|
|
198 | 198 |
|
199 |
return 0;
|
|
199 |
return 0;
|
|
200 | 200 |
} |
201 | 201 |
|
202 | 202 |
/** |
Also available in: Unified diff