Skip to content

Commit 79def65

Browse files
committed
fix timeout event lead to OS error
1 parent f6e165f commit 79def65

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-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 open.
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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ 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+
close();
41+
}
42+
3943
void DTLSSocketWrapper::timing_set_delay(void *ctx, uint32_t int_ms, uint32_t fin_ms)
4044
{
4145
DTLSSocketWrapper *context = static_cast<DTLSSocketWrapper *>(ctx);
@@ -74,6 +78,15 @@ int DTLSSocketWrapper::timing_get_delay(void *ctx)
7478
}
7579
}
7680

81+
nsapi_error_t DTLSSocketWrapper::close() {
82+
if (_timer_event_id != 0) {
83+
mbed::mbed_event_queue()->cancel(_timer_event_id);
84+
_timer_event_id = 0;
85+
}
86+
87+
return TLSSocketWrapper::close();
88+
}
89+
7790
void DTLSSocketWrapper::timer_event(void)
7891
{
7992
_timer_expired = true;

0 commit comments

Comments
 (0)