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

Method onAccept

Sming/Components/Network/src/Network/TcpServer.cpp:53–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51}
52
53err_t TcpServer::onAccept(tcp_pcb* clientTcp, err_t err)
54{
55 // Anti DDoS :-)
56 if(system_get_free_heap_size() < minHeapSize) {
57 debug_w("\r\n\r\nCONNECTION DROPPED\r\n\t(free heap: %u)\r\n\r\n", system_get_free_heap_size());
58 return ERR_MEM;
59 }
60
61 // Obey any requested connection limit
62 if(maxConnections != 0 && connections.count() >= maxConnections) {
63 debug_w("\r\n\r\nCONNECTION DROPPED\r\n\t(Existing connections: %u)\r\n\r\n", connections.count());
64 return ERR_ABRT;
65 }
66
67#ifdef NETWORK_DEBUG
68 debug_d("onAccept, tcp: %p, state: %d K=%d, Free heap size=%u", clientTcp, err, connections.count(),
69 system_get_free_heap_size());
70#endif
71
72 if(err != ERR_OK) {
73 //closeTcpConnection(clientTcp, nullptr);
74 return err;
75 }
76
77 TcpConnection* client = createClient(clientTcp);
78 if(client == nullptr) {
79 return ERR_MEM;
80 }
81 client->setTimeOut(keepAlive);
82
83 if(useSsl) {
84 if(!sslCreateSession()) {
85 delete client;
86 return ERR_ABRT;
87 }
88 if(!ssl->onAccept(client, clientTcp)) {
89 delete client;
90 return ERR_ABRT;
91 }
92 }
93
94 client->setDestroyedDelegate(TcpConnectionDestroyedDelegate(&TcpServer::onClientDestroy, this));
95
96 connections.add(client);
97 debug_d("Opening connection. Total connections: %d", connections.count());
98
99 onClient(reinterpret_cast<TcpClient*>(client));
100
101 return ERR_OK;
102}
103
104void TcpServer::onClient(TcpClient* client)
105{

Callers 1

staticAcceptMethod · 0.45

Calls 6

onClientFunction · 0.85
setTimeOutMethod · 0.80
setDestroyedDelegateMethod · 0.80
countMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected