Skip to content

Commit 6d57455

Browse files
committed
Merge pull request #94 from facchinm/sockets_close
Close sockets when physical link is disconnected
2 parents d9619a2 + 5734d86 commit 6d57455

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/WiFi.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ static void wifi_cb(uint8_t u8MsgType, void *pvMsg)
5353
WiFi._submask = 0;
5454
WiFi._gateway = 0;
5555
}
56+
// Close sockets to clean state
57+
// Clients will need to reconnect once the physical link will be re-established
58+
for (int i=0; i < TCP_SOCK_MAX; i++) {
59+
if (WiFi._client[i])
60+
WiFi._client[i]->stop();
61+
}
5662
} else if (WiFi._mode == WL_AP_MODE) {
5763
WiFi._status = WL_AP_LISTENING;
5864
}

src/WiFiClient.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ int WiFiClient::connect(IPAddress ip, uint16_t port, uint8_t opt, const uint8_t
152152
_socket = -1;
153153
return 0;
154154
}
155-
155+
156156
// Wait for connection or timeout:
157157
unsigned long start = millis();
158158
while (!IS_CONNECTED && millis() - start < 20000) {
@@ -164,6 +164,8 @@ int WiFiClient::connect(IPAddress ip, uint16_t port, uint8_t opt, const uint8_t
164164
return 0;
165165
}
166166

167+
WiFi._client[_socket] = this;
168+
167169
return 1;
168170
}
169171

0 commit comments

Comments
 (0)