some chrono

Signed-off-by: Rosen Penev <rosenp@gmail.com>
main
Rosen Penev 3 years ago
parent b25e75dd7b
commit 3298fcf656

@ -12,6 +12,7 @@
#include <array> #include <array>
#include <chrono> #include <chrono>
#include <cinttypes>
#include <thread> #include <thread>
//////////////////////////////////////// ////////////////////////////////////////
@ -65,8 +66,8 @@ static constexpr std::array<const char*, 2> blankLines{
"\n\n", // this is commonly sent by CGI scripts "\n\n", // this is commonly sent by CGI scripts
}; };
static constexpr int snooze = 0; static constexpr auto snooze = std::chrono::milliseconds::zero();
static int sleep_ = 1000; static auto sleep_ = std::chrono::milliseconds(1000);
static int forgive(int n, int& err) { static int forgive(int n, int& err) {
err = WSAGetLastError(); err = WSAGetLastError();
@ -240,12 +241,13 @@ int Exiv2::http(Exiv2::Dictionary& request, Exiv2::Dictionary& response, std::st
//////////////////////////////////// ////////////////////////////////////
// send the header (we'll have to wait for the connection by the non-blocking socket) // send the header (we'll have to wait for the connection by the non-blocking socket)
while (sleep_ >= 0 && send(sockfd, buffer, n, 0) == SOCKET_ERROR /* && WSAGetLastError() == WSAENOTCONN */) { while (sleep_ >= std::chrono::milliseconds::zero() &&
std::this_thread::sleep_for(std::chrono::milliseconds(snooze)); send(sockfd, buffer, n, 0) == SOCKET_ERROR /* && WSAGetLastError() == WSAENOTCONN */) {
std::this_thread::sleep_for(snooze);
sleep_ -= snooze; sleep_ -= snooze;
} }
if (sleep_ < 0) if (sleep_ < std::chrono::milliseconds::zero())
return error(errors, "error - timeout connecting to server = %s port = %s wsa_error = %d", servername, port, return error(errors, "error - timeout connecting to server = %s port = %s wsa_error = %d", servername, port,
WSAGetLastError()); WSAGetLastError());
@ -325,16 +327,16 @@ int Exiv2::http(Exiv2::Dictionary& request, Exiv2::Dictionary& response, std::st
} }
n = forgive(recv(sockfd, buffer + end, static_cast<int>(buff_l - end), 0), err); n = forgive(recv(sockfd, buffer + end, static_cast<int>(buff_l - end), 0), err);
if (!n) { if (!n) {
std::this_thread::sleep_for(std::chrono::milliseconds(snooze)); std::this_thread::sleep_for(snooze);
sleep_ -= snooze; sleep_ -= snooze;
if (sleep_ < 0) if (sleep_ < std::chrono::milliseconds::zero())
n = FINISH; n = FINISH;
} }
} }
if (n != FINISH || !OK(status)) { if (n != FINISH || !OK(status)) {
snprintf(buffer, sizeof buffer, "wsa_error = %d,n = %d,sleep_ = %d status = %d", WSAGetLastError(), n, sleep_, snprintf(buffer, sizeof buffer, "wsa_error = %d,n = %d,sleep_ = %d status = %d", WSAGetLastError(), n,
status); int(sleep_.count()), status);
error(errors, buffer, nullptr, nullptr, 0); error(errors, buffer, nullptr, nullptr, 0);
} else if (bSearching && OK(status)) { } else if (bSearching && OK(status)) {
if (end) { if (end) {

Loading…
Cancel
Save