Skip to content
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

DTLSSocket - destruction while handshaking lead to error #15111

Merged
merged 1 commit into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions connectivity/netsocket/include/netsocket/DTLSSocketWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ class DTLSSocketWrapper : public TLSSocketWrapper {
* @param control Transport control mode. See @ref control_transport.
*/
DTLSSocketWrapper(Socket *transport, const char *hostname = NULL, control_transport control = TRANSPORT_CONNECT_AND_CLOSE);

/** Destroy a socket wrapper.
*
* Closes socket wrapper if the socket wrapper is still opened.
*/
~DTLSSocketWrapper();

nsapi_error_t close() override;
private:
static void timing_set_delay(void *ctx, uint32_t int_ms, uint32_t fin_ms);
static int timing_get_delay(void *ctx);
Expand Down
15 changes: 15 additions & 0 deletions connectivity/netsocket/source/DTLSSocketWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ DTLSSocketWrapper::DTLSSocketWrapper(Socket *transport, const char *hostname, co
#endif /* !defined(MBEDTLS_SSL_CONF_SET_TIMER) && !defined(MBEDTLS_SSL_CONF_GET_TIMER) */
}

DTLSSocketWrapper::~DTLSSocketWrapper()
{
close();
}

void DTLSSocketWrapper::timing_set_delay(void *ctx, uint32_t int_ms, uint32_t fin_ms)
{
DTLSSocketWrapper *context = static_cast<DTLSSocketWrapper *>(ctx);
Expand Down Expand Up @@ -74,6 +79,16 @@ int DTLSSocketWrapper::timing_get_delay(void *ctx)
}
}

nsapi_error_t DTLSSocketWrapper::close()
{
if (_timer_event_id != 0) {
mbed::mbed_event_queue()->cancel(_timer_event_id);
_timer_event_id = 0;
}

return TLSSocketWrapper::close();
}

void DTLSSocketWrapper::timer_event(void)
{
_timer_expired = true;
Expand Down