-
-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enforcing stop() when calling connect a second time #949
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,14 +80,8 @@ void arduino::MbedClient::configureSocket(Socket *_s) { | |
} | ||
|
||
int arduino::MbedClient::connect(SocketAddress socketAddress) { | ||
|
||
if (sock && reader_th) { | ||
// trying to reuse a connection, let's call stop() to cleanup the state | ||
char c; | ||
if (sock->recv(&c, 1) < 0) { | ||
stop(); | ||
} | ||
} | ||
// if a connection is aready ongoing, a disconnection must be enforced before starting another one | ||
stop(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok. I don't know the reason why the the socker->recv was there... Do you know why? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know why it was there, but I suppose that if someone calls connect he wants to reset the connection before connecting, since I could connect to a new host |
||
|
||
if (sock == nullptr) { | ||
sock = new TCPSocket(); | ||
|
@@ -135,6 +129,9 @@ int arduino::MbedClient::connect(const char *host, uint16_t port) { | |
} | ||
|
||
int arduino::MbedClient::connectSSL(SocketAddress socketAddress) { | ||
// if a connection is aready ongoing, a disconnection must be enforced before starting another one | ||
stop(); | ||
|
||
if (sock == nullptr) { | ||
sock = new TLSSocket(); | ||
_own_socket = true; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In connect and connectSSL I see a discrepancy in how timesout are set.
Can you please take a look and make them uniform?
Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as stated here
TLSSocketWrapper
requires the timeout to be set before the connect is called. In the plain TCP version we callset_timeout
before write, I think the reason for this is to update the timeout value internally if the user changes it. I would not touch it for the time being. @pennam can you confirm that?ArduinoCore-mbed/libraries/SocketWrapper/src/MbedClient.cpp
Lines 154 to 157 in 702daa0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we can add a
sock-> set_timeout()
also inarduino::MbedClient::connect(SocketAddress socketAddress)
just beforensapi_error_t returnCode = static_cast<TCPSocket *>(sock)->connect(socketAddress);
since alsoTCPSocket::connect(const SocketAddress &address)
is using the_timeout
value, but i would do it in a separate PR.