Revision 161
formatting stuff
ColonetServer.cpp | ||
---|---|---|
1 |
/**
|
|
1 |
/** |
|
2 | 2 |
* @file ColonetServer.cpp |
3 | 3 |
* |
4 | 4 |
* @brief colonet_server - primary server application for Colonet |
... | ... | |
117 | 117 |
} |
118 | 118 |
|
119 | 119 |
char log_buffer[LOG_BUFFER_LENGTH]; |
120 |
snprintf(log_buffer, LOG_BUFFER_LENGTH, "Client at address %s attempting to connect.",
|
|
120 |
snprintf(log_buffer, LOG_BUFFER_LENGTH, "Client at address %s attempting to connect.", |
|
121 | 121 |
inet_ntoa(client_addr.sin_addr)); |
122 | 122 |
logger.log_string(LOG_TYPE_CONNECT, log_buffer); |
123 | 123 |
|
... | ... | |
126 | 126 |
continue; |
127 | 127 |
} |
128 | 128 |
|
129 |
snprintf(log_buffer, LOG_BUFFER_LENGTH, "Client at address %s successfully added to connection pool.",
|
|
129 |
snprintf(log_buffer, LOG_BUFFER_LENGTH, "Client at address %s successfully added to connection pool.", |
|
130 | 130 |
inet_ntoa(client_addr.sin_addr)); |
131 | 131 |
logger.log_string(LOG_TYPE_CONNECT, log_buffer); |
132 | 132 |
} |
... | ... | |
146 | 146 |
printf("response\n"); |
147 | 147 |
|
148 | 148 |
char buffer[WRITE_BUFFER_SIZE]; |
149 |
|
|
149 |
|
|
150 | 150 |
int value = (int)(data[0]); |
151 | 151 |
snprintf(buffer, WRITE_BUFFER_SIZE, "%d\n", value); |
152 |
|
|
152 |
|
|
153 | 153 |
int buflen = strlen(buffer); |
154 | 154 |
if (connection_pool.write_to_client(dest, buffer, buflen) |
155 | 155 |
== ERROR_INVALID_CLIENT_ID) { |
... | ... | |
180 | 180 |
log_filename = optionsG.log_filename; |
181 | 181 |
} |
182 | 182 |
|
183 |
/* |
|
184 |
colonet_wl_init(optionsG.wireless_port, wirelessMessageHandler, |
|
185 |
log_filename); |
|
183 |
colonet_wl_init(optionsG.wireless_port, wirelessMessageHandler, |
|
184 |
log_filename); |
|
186 | 185 |
|
187 |
if (!colonet_wl_run_listener_thread()) {
|
|
186 |
if (!colonet_wl_run_listener_thread()) { |
|
188 | 187 |
fprintf(stderr, "%s: colonet_wl_run_listener_thread failed.\n", |
189 |
__FUNCTION__); |
|
188 |
__FUNCTION__);
|
|
190 | 189 |
return -1; |
191 |
} |
|
192 |
*/ |
|
190 |
} |
|
193 | 191 |
|
194 | 192 |
return 0; |
195 | 193 |
} |
... | ... | |
202 | 200 |
* @return 0 on success, negative error code on error |
203 | 201 |
*/ |
204 | 202 |
int ColonetServer::initialize_connection(int port) { |
205 |
printf("Initializing connection that will be used to listen for "
|
|
203 |
printf("Initializing connection that will be used to listen for " |
|
206 | 204 |
"clients...\n"); |
207 | 205 |
int options = 1; |
208 | 206 |
struct sockaddr_in my_address; |
... | ... | |
218 | 216 |
my_address.sin_family = AF_INET; |
219 | 217 |
my_address.sin_addr.s_addr = htonl(INADDR_ANY); |
220 | 218 |
my_address.sin_port = htons(port); |
221 |
|
|
219 |
|
|
222 | 220 |
setsockopt(listen_socket, SOL_SOCKET, SO_REUSEADDR, &options, sizeof(options)); |
223 | 221 |
|
224 | 222 |
//get the current socket options |
... | ... | |
233 | 231 |
printf("\tThere was an error setting the socket to be non blocking.\n"); |
234 | 232 |
return -1; |
235 | 233 |
} |
236 |
|
|
234 |
|
|
237 | 235 |
//bind the socket to listen on the specified port |
238 | 236 |
if (bind(listen_socket, (struct sockaddr *) &my_address, sizeof(my_address)) < 0) { |
239 | 237 |
printf("\tThere was an error binding the socket\n"); |
240 | 238 |
return -1; |
241 | 239 |
} |
242 |
|
|
240 |
|
|
243 | 241 |
return 0; |
244 | 242 |
} |
245 | 243 |
|
... | ... | |
263 | 261 |
if (colonet_server.start_listening() < 0) { |
264 | 262 |
return -1; |
265 | 263 |
} |
266 |
|
|
264 |
|
|
267 | 265 |
colonet_server.run_server(); |
268 | 266 |
|
269 | 267 |
return 0; |
Also available in: Unified diff