@@ -63,7 +63,16 @@ void TCPLoop(void)
63
63
if ((server_tcp) && (server_tcp->hasClient ())) {
64
64
WiFiClient new_client = server_tcp->available ();
65
65
66
- AddLog (LOG_LEVEL_INFO, PSTR (D_LOG_TCP " Got connection from %s" ), new_client.remoteIP ().toString ().c_str ());
66
+ // count already connected ports
67
+ uint32_t connected = 0 ;
68
+ for (uint32_t i=0 ; i<nitems (client_tcp); i++) {
69
+ WiFiClient &client = client_tcp[i];
70
+ if (client.connected ()) {
71
+ connected++;
72
+ }
73
+ }
74
+
75
+ AddLog (LOG_LEVEL_INFO, PSTR (D_LOG_TCP " Got connection from %s (%i already connected)" ), new_client.remoteIP ().toString ().c_str (), connected);
67
76
// Check for IP filtering if it's enabled.
68
77
if (ip_filter_enabled) {
69
78
if (ip_filter != new_client.remoteIP ()) {
@@ -80,13 +89,17 @@ void TCPLoop(void)
80
89
WiFiClient &client = client_tcp[i];
81
90
if (!client) {
82
91
client = new_client;
92
+ AddLog (LOG_LEVEL_DEBUG, PSTR (D_LOG_TCP " Adding connection to slot %i" ), i);
83
93
break ;
84
94
}
85
95
}
86
96
if (i >= nitems (client_tcp)) {
87
97
i = client_next++ % nitems (client_tcp);
88
98
WiFiClient &client = client_tcp[i];
89
- client.stop ();
99
+ if (client.connected ()) {
100
+ AddLog (LOG_LEVEL_DEBUG, PSTR (D_LOG_TCP " Replacing connection in slot %i, closing connection from %s" ), i, client.remoteIP ().toString ().c_str ());
101
+ client.stop ();
102
+ }
90
103
client = new_client;
91
104
}
92
105
}
0 commit comments