Skip to content

Commit 97b6f59

Browse files
enforcing stop() when calling connect a second time
1 parent 702daa0 commit 97b6f59

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

libraries/SocketWrapper/src/MbedClient.cpp

+5-8
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,8 @@ void arduino::MbedClient::configureSocket(Socket *_s) {
8080
}
8181

8282
int arduino::MbedClient::connect(SocketAddress socketAddress) {
83-
84-
if (sock && reader_th) {
85-
// trying to reuse a connection, let's call stop() to cleanup the state
86-
char c;
87-
if (sock->recv(&c, 1) < 0) {
88-
stop();
89-
}
90-
}
83+
// if a connection is aready ongoing, a disconnection must be enforced before starting another one
84+
stop();
9185

9286
if (sock == nullptr) {
9387
sock = new TCPSocket();
@@ -135,6 +129,9 @@ int arduino::MbedClient::connect(const char *host, uint16_t port) {
135129
}
136130

137131
int arduino::MbedClient::connectSSL(SocketAddress socketAddress) {
132+
// if a connection is aready ongoing, a disconnection must be enforced before starting another one
133+
stop();
134+
138135
if (sock == nullptr) {
139136
sock = new TLSSocket();
140137
_own_socket = true;

0 commit comments

Comments
 (0)