Skip to content

Commit 0db0445

Browse files
authored
Merge pull request #15111 from world-direct/feature/dtlserror
DTLSSocket - destruction while handshaking lead to error
2 parents ae5c9ec + 16afca3 commit 0db0445

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

connectivity/netsocket/include/netsocket/DTLSSocketWrapper.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ class DTLSSocketWrapper : public TLSSocketWrapper {
4040
* @param control Transport control mode. See @ref control_transport.
4141
*/
4242
DTLSSocketWrapper(Socket *transport, const char *hostname = NULL, control_transport control = TRANSPORT_CONNECT_AND_CLOSE);
43+
44+
/** Destroy a socket wrapper.
45+
*
46+
* Closes socket wrapper if the socket wrapper is still opened.
47+
*/
48+
~DTLSSocketWrapper();
49+
50+
nsapi_error_t close() override;
4351
private:
4452
static void timing_set_delay(void *ctx, uint32_t int_ms, uint32_t fin_ms);
4553
static int timing_get_delay(void *ctx);

connectivity/netsocket/source/DTLSSocketWrapper.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ DTLSSocketWrapper::DTLSSocketWrapper(Socket *transport, const char *hostname, co
3636
#endif /* !defined(MBEDTLS_SSL_CONF_SET_TIMER) && !defined(MBEDTLS_SSL_CONF_GET_TIMER) */
3737
}
3838

39+
DTLSSocketWrapper::~DTLSSocketWrapper()
40+
{
41+
close();
42+
}
43+
3944
void DTLSSocketWrapper::timing_set_delay(void *ctx, uint32_t int_ms, uint32_t fin_ms)
4045
{
4146
DTLSSocketWrapper *context = static_cast<DTLSSocketWrapper *>(ctx);
@@ -74,6 +79,16 @@ int DTLSSocketWrapper::timing_get_delay(void *ctx)
7479
}
7580
}
7681

82+
nsapi_error_t DTLSSocketWrapper::close()
83+
{
84+
if (_timer_event_id != 0) {
85+
mbed::mbed_event_queue()->cancel(_timer_event_id);
86+
_timer_event_id = 0;
87+
}
88+
89+
return TLSSocketWrapper::close();
90+
}
91+
7792
void DTLSSocketWrapper::timer_event(void)
7893
{
7994
_timer_expired = true;

0 commit comments

Comments
 (0)