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

Do not add std::chrono::milliseconds to std::chrono::time_point #40

Merged
merged 1 commit into from
Oct 10, 2017
Merged
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
19 changes: 12 additions & 7 deletions network/MbedTLS/MbedTLSConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ namespace awsiotsdk {
bool isErrorFlag = false;
int ret;

auto timeout = std::chrono::system_clock::now() + tls_write_timeout_;
auto now = std::chrono::system_clock::now();
const auto start = std::chrono::system_clock::now();
auto elapsed_time = std::chrono::duration<double>();

do {
ret = mbedtls_ssl_write(&ssl_, buf_cstr + total_written_length, bytes_to_write - total_written_length);
Expand All @@ -268,14 +268,16 @@ namespace awsiotsdk {
isErrorFlag = true;
break;
}
now = std::chrono::system_clock::now();
} while (now < timeout && total_written_length < bytes_to_write);
elapsed_time = std::chrono::system_clock::now() - start;
} while (tls_write_timeout_ > std::chrono::duration_cast<std::chrono::milliseconds>(elapsed_time) &&
total_written_length < bytes_to_write);

size_written_bytes_out = total_written_length;

if (isErrorFlag) {
rc = ResponseCode::NETWORK_SSL_WRITE_ERROR;
} else if (now < timeout && total_written_length != bytes_to_write) {
} else if (tls_write_timeout_ > std::chrono::duration_cast<std::chrono::milliseconds>(elapsed_time) &&
total_written_length != bytes_to_write) {
return ResponseCode::NETWORK_SSL_WRITE_TIMEOUT_ERROR;
}

Expand All @@ -287,7 +289,8 @@ namespace awsiotsdk {
int ret;
size_t total_read_length = 0;
size_t remaining_bytes_to_read = size_bytes_to_read;
auto timeout = std::chrono::system_clock::now() + tls_read_timeout_;
const auto start = std::chrono::system_clock::now();
auto elapsed_time = std::chrono::duration<double>();
do {
// This read will timeout after IOT_SSL_READ_TIMEOUT if there's no data to be read
ret = mbedtls_ssl_read(&ssl_, &buf[buf_read_offset], remaining_bytes_to_read);
Expand All @@ -300,7 +303,9 @@ namespace awsiotsdk {
&& ret != MBEDTLS_ERR_SSL_TIMEOUT) {
return ResponseCode::NETWORK_SSL_READ_ERROR;
}
} while (remaining_bytes_to_read > 0 && timeout < std::chrono::system_clock::now());
elapsed_time = std::chrono::system_clock::now() - start;
} while (remaining_bytes_to_read > 0 &&
tls_read_timeout_ > std::chrono::duration_cast<std::chrono::milliseconds>(elapsed_time));

if (0 == total_read_length) {
return ResponseCode::NETWORK_SSL_NOTHING_TO_READ;
Expand Down