3a77e96a05
* introduce send fragment * can pass a fin frame * can send messages which are a perfect multiple of the chunk size * set fin only for last fragment * cleanup * last fragment should be of type CONTINUATION * Add simple send and receive programs * speedups receiving + better way to wait for thing * receive speedup by using linked list of chunks instead of large array * document bug * use chunks to receive data * trailing spaces
34 lines
936 B
C++
34 lines
936 B
C++
/*
|
|
* IXCancellationRequest.cpp
|
|
* Author: Benjamin Sergeant
|
|
* Copyright (c) 2019 Machine Zone, Inc. All rights reserved.
|
|
*/
|
|
|
|
#include "IXCancellationRequest.h"
|
|
|
|
#include <chrono>
|
|
|
|
namespace ix
|
|
{
|
|
CancellationRequest makeCancellationRequestWithTimeout(int secs,
|
|
std::atomic<bool>& requestInitCancellation)
|
|
{
|
|
auto start = std::chrono::system_clock::now();
|
|
auto timeout = std::chrono::seconds(secs);
|
|
|
|
auto isCancellationRequested = [&requestInitCancellation, start, timeout]() -> bool
|
|
{
|
|
// Was an explicit cancellation requested ?
|
|
if (requestInitCancellation) return true;
|
|
|
|
auto now = std::chrono::system_clock::now();
|
|
if ((now - start) > timeout) return true;
|
|
|
|
// No cancellation request
|
|
return false;
|
|
};
|
|
|
|
return isCancellationRequested;
|
|
}
|
|
}
|