| 257 | // ---------------------------------------------------------------------------------------- |
| 258 | |
| 259 | void server:: |
| 260 | start_accepting_connections ( |
| 261 | ) |
| 262 | { |
| 263 | open_listening_socket(); |
| 264 | |
| 265 | // determine the listening port |
| 266 | bool port_assigned = false; |
| 267 | listening_port_mutex.lock(); |
| 268 | if (listening_port == 0) |
| 269 | { |
| 270 | port_assigned = true; |
| 271 | listening_port = sock->get_listening_port(); |
| 272 | } |
| 273 | listening_port_mutex.unlock(); |
| 274 | if (port_assigned) |
| 275 | on_listening_port_assigned(); |
| 276 | |
| 277 | |
| 278 | |
| 279 | int status = 0; |
| 280 | |
| 281 | connection* client; |
| 282 | bool exit = false; |
| 283 | while ( true ) |
| 284 | { |
| 285 | |
| 286 | |
| 287 | // accept the next connection |
| 288 | status = sock->accept(client,1000); |
| 289 | |
| 290 | |
| 291 | // if there was an error then quit the loop |
| 292 | if (status == OTHER_ERROR) |
| 293 | { |
| 294 | break; |
| 295 | } |
| 296 | |
| 297 | shutting_down_mutex.lock(); |
| 298 | // if we are shutting down then signal that we should quit the loop |
| 299 | exit = shutting_down; |
| 300 | shutting_down_mutex.unlock(); |
| 301 | |
| 302 | |
| 303 | // if we should be shutting down |
| 304 | if (exit) |
| 305 | { |
| 306 | // if a connection was opened then close it |
| 307 | if (status == 0) |
| 308 | delete client; |
| 309 | break; |
| 310 | } |
| 311 | |
| 312 | |
| 313 | |
| 314 | // if the accept timed out |
| 315 | if (status == TIMEOUT) |
| 316 | { |
nothing calls this directly
no test coverage detected