Commit 48aad66d authored by Artem Prilutskiy's avatar Artem Prilutskiy

Fixes

parent 18186deb
......@@ -208,7 +208,8 @@ int ConnectRewindClient(struct RewindContext* context, const char* location, con
ssize_t length;
size_t attempt = 0;
time_t threshold = time(NULL) + CONNECT_TIMEOUT;
struct timeval now;
struct timeval threshold;
uint8_t* digest = (uint8_t*)alloca(SHA256_DIGEST_LENGTH);
......@@ -238,11 +239,17 @@ int ConnectRewindClient(struct RewindContext* context, const char* location, con
// Do login procedure
while (threshold > time(NULL))
gettimeofday(&now, NULL);
threshold.tv_sec = now.tv_sec + CONNECT_TIMEOUT;
threshold.tv_usec = now.tv_usec;
while (timercmp(&now, &threshold, <))
{
TransmitRewindData(context, REWIND_TYPE_KEEP_ALIVE, REWIND_FLAG_NONE, context->data, context->length);
length = ReceiveRewindData(context, buffer, BUFFER_SIZE);
gettimeofday(&now, NULL);
if ((length == CLIENT_ERROR_WRONG_ADDRESS) ||
(length == CLIENT_ERROR_SOCKET_IO) &&
((errno == EWOULDBLOCK) ||
......@@ -292,16 +299,19 @@ int WaitForRewindSessionEnd(struct RewindContext* context, struct RewindSessionP
struct timeval now;
struct timeval threshold;
gettimeofday(&threshold, NULL);
threshold.tv_sec += interval;
gettimeofday(&now, NULL);
threshold.tv_sec = now.tv_sec + CONNECT_TIMEOUT;
threshold.tv_usec = now.tv_usec;
do
while (timercmp(&now, &threshold, <))
{
TransmitRewindData(context, REWIND_TYPE_KEEP_ALIVE, REWIND_FLAG_NONE, context->data, context->length);
TransmitRewindData(context, REWIND_TYPE_SESSION_POLL, REWIND_FLAG_NONE, request, sizeof(struct RewindSessionPollData));
length = ReceiveRewindData(context, buffer, BUFFER_SIZE);
gettimeofday(&now, NULL);
if ((length == CLIENT_ERROR_WRONG_ADDRESS) ||
(length == CLIENT_ERROR_SOCKET_IO) &&
((errno == EWOULDBLOCK) ||
......@@ -334,10 +344,7 @@ int WaitForRewindSessionEnd(struct RewindContext* context, struct RewindSessionP
sleep(RECEIVE_TIMEOUT);
state = 0b00;
}
gettimeofday(&now, NULL);
}
while (timercmp(&now, &threshold, <));
return CLIENT_ERROR_RESPONSE_TIMEOUT;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment