Skip to content

DTLSSocketWrapper: Convert to Chrono #12429

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

Merged
merged 2 commits into from
May 13, 2020
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
5 changes: 5 additions & 0 deletions UNITTESTS/stubs/Kernel_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
namespace rtos {

uint64_t Kernel::get_ms_count()
{
return impl::get_tick_count();

}
uint64_t Kernel::impl::get_tick_count()
{
return 20;
}
Expand Down
9 changes: 6 additions & 3 deletions features/netsocket/DTLSSocketWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ void DTLSSocketWrapper::timing_set_delay(void *ctx, uint32_t int_ms, uint32_t fi
return;
}

context->_int_ms_tick = rtos::Kernel::get_ms_count() + int_ms;
context->_timer_event_id = mbed::mbed_event_queue()->call_in(fin_ms, context, &DTLSSocketWrapper::timer_event);
auto int_duration = std::chrono::duration<uint32_t, std::milli>(int_ms);
auto fin_duration = std::chrono::duration<uint32_t, std::milli>(fin_ms);

context->_int_time = rtos::Kernel::Clock::now() + int_duration;
context->_timer_event_id = mbed::mbed_event_queue()->call_in(fin_duration, context, &DTLSSocketWrapper::timer_event);
}

int DTLSSocketWrapper::timing_get_delay(void *ctx)
Expand All @@ -64,7 +67,7 @@ int DTLSSocketWrapper::timing_get_delay(void *ctx)
return -1;
} else if (context->_timer_expired) {
return 2;
} else if (context->_int_ms_tick < rtos::Kernel::get_ms_count()) {
} else if (context->_int_time < rtos::Kernel::Clock::now()) {
return 1;
} else {
return 0;
Expand Down
3 changes: 2 additions & 1 deletion features/netsocket/DTLSSocketWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define DTLSSOCKETWRAPPER_H

#include "TLSSocketWrapper.h"
#include "rtos/Kernel.h"

// This class requires Mbed TLS SSL/TLS client code
#if defined(MBEDTLS_SSL_CLI_C) || defined(DOXYGEN_ONLY)
Expand All @@ -43,7 +44,7 @@ class DTLSSocketWrapper : public TLSSocketWrapper {
static void timing_set_delay(void *ctx, uint32_t int_ms, uint32_t fin_ms);
static int timing_get_delay(void *ctx);
void timer_event();
uint64_t _int_ms_tick = 0;
rtos::Kernel::Clock::time_point _int_time;
int _timer_event_id = 0;
bool _timer_expired = false;
};
Expand Down