MCPcopy Create free account
hub / github.com/davisking/dlib / start_accepting_connections

Method start_accepting_connections

dlib/server/server_kernel.cpp:259–466  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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 {

Callers

nothing calls this directly

Calls 12

thread_errorClass · 0.85
socket_errorClass · 0.85
removeMethod · 0.80
clearFunction · 0.50
create_new_threadFunction · 0.50
lockMethod · 0.45
get_listening_portMethod · 0.45
unlockMethod · 0.45
addMethod · 0.45
resetMethod · 0.45
broadcastMethod · 0.45
waitMethod · 0.45

Tested by

no test coverage detected