forked from ydb-platform/nbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcont_io_with_timeout.h
47 lines (37 loc) · 1.05 KB
/
cont_io_with_timeout.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#pragma once
#include <library/cpp/coroutine/engine/sockpool.h>
#include <util/stream/input.h>
#include <util/stream/output.h>
namespace NCloud::NBlockStore::NServer {
///////////////////////////////////////////////////////////////////////////////
// Similar to TContIO, but DoWrite() and DoRead() operations are executed with a
// timeout.
class TContIOWithTimeout
: public IInputStream
, public IOutputStream
{
SOCKET Fd_;
TCont* Cont_;
TDuration Timeout;
public:
TContIOWithTimeout(SOCKET fd, TCont* cont, TDuration timeout)
: Fd_(fd)
, Cont_(cont)
, Timeout(timeout)
{}
void DoWrite(const void* buf, size_t len) override
{
NCoro::WriteD(Cont_, Fd_, buf, len, TInstant::Now() + Timeout)
.Checked();
}
size_t DoRead(void* buf, size_t len) override
{
return NCoro::ReadD(Cont_, Fd_, buf, len, TInstant::Now() + Timeout)
.Checked();
}
SOCKET Fd() const noexcept
{
return Fd_;
}
};
} // namespace NCloud::NBlockStore::NServer