Skip to content

Commit c9a7485

Browse files
andreagilardonifacchinm
authored andcommitted
WiFiS3: clients: restore socket on connection loss
When a client looses connection the client needs to be stopped before calling connect again
1 parent 113a524 commit c9a7485

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

Diff for: libraries/WiFiS3/src/WiFiClient.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ WiFiClient::WiFiClient(const WiFiClient& c) {
2828
/* -------------------------------------------------------------------------- */
2929
void WiFiClient::getSocket() {
3030
/* -------------------------------------------------------------------------- */
31+
if(_sock >= 0 && !connected()) {
32+
// if sock >= 0 -> it means we were connected, but something happened and we need
33+
// to reset this socket in order to be able to connect again
34+
stop();
35+
}
36+
3137
if(_sock == -1) {
3238
string res = "";
3339
modem.begin();

Diff for: libraries/WiFiS3/src/WiFiSSLClient.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ WiFiSSLClient::~WiFiSSLClient() {
1616
/* -------------------------------------------------------------------------- */
1717
void WiFiSSLClient::getSocket() {
1818
/* -------------------------------------------------------------------------- */
19+
if(_sock >= 0 && !connected()) {
20+
// if sock >= 0 -> it means we were connected, but something happened and we need
21+
// to reset this socket in order to be able to connect again
22+
stop();
23+
}
24+
1925
if(_sock == -1) {
2026
string res = "";
2127
modem.begin();

0 commit comments

Comments
 (0)