MCPcopy Create free account
hub / github.com/SmingHub/Sming / try_connect

Method try_connect

Sming/Arch/Host/Components/hostlib/sockets.cpp:444–474  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

442}
443
444CSocket* CServerSocket::try_connect()
445{
446 // Initialised?
447 if(m_fd <= 0) {
448 return nullptr;
449 }
450
451 // Ignore further attempts until we're ready
452 if(m_clients.active() >= m_max_connections) {
453 return nullptr;
454 }
455
456 struct sockaddr sa {
457 };
458 host_socklen_t len = sizeof(sa);
459 int fd = ::accept(m_fd, &sa, &len);
460 if(fd < 0) {
461 return nullptr;
462 }
463
464 if(socket_blocking(fd, false)) {
465 CSocket* skt = new_connection(fd, CSockAddr(sa));
466 if(skt) {
467 m_clients.add(skt);
468 return skt;
469 }
470 }
471
472 socket_close(fd);
473 return nullptr;
474}

Callers

nothing calls this directly

Calls 5

socket_blockingFunction · 0.85
CSockAddrClass · 0.85
socket_closeFunction · 0.85
activeMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected