MCPcopy Create free account
hub / github.com/catboost/catboost / TPooledSocket

Class TPooledSocket

library/cpp/coroutine/engine/sockpool.h:14–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12class TSocketPool;
13
14class TPooledSocket {
15 class TImpl: public TIntrusiveListItem<TImpl>, public TSimpleRefCount<TImpl, TImpl> {
16 public:
17 TImpl(SOCKET fd, TSocketPool* pool) noexcept
18 : Pool_(pool)
19 , IsKeepAlive_(false)
20 , Fd_(fd)
21 {
22 Touch();
23 }
24
25 static void Destroy(TImpl* impl) noexcept {
26 impl->DoDestroy();
27 }
28
29 void DoDestroy() noexcept {
30 if (!Closed() && IsKeepAlive() && IsInGoodState()) {
31 ReturnToPool();
32 } else {
33 delete this;
34 }
35 }
36
37 bool IsKeepAlive() const noexcept {
38 return IsKeepAlive_;
39 }
40
41 void SetKeepAlive(bool ka) {
42 ::SetKeepAlive(Fd_, ka);
43 IsKeepAlive_ = ka;
44 }
45
46 SOCKET Socket() const noexcept {
47 return Fd_;
48 }
49
50 bool Closed() const noexcept {
51 return Fd_.Closed();
52 }
53
54 void Close() noexcept {
55 Fd_.Close();
56 }
57
58 bool IsInGoodState() const noexcept {
59 int err = 0;
60 socklen_t len = sizeof(err);
61
62 getsockopt(Fd_, SOL_SOCKET, SO_ERROR, (char*)&err, &len);
63
64 return !err;
65 }
66
67 bool IsOpen() const noexcept {
68 return IsInGoodState() && IsNotSocketClosedByOtherSide(Fd_);
69 }
70
71 void Touch() noexcept {

Callers 2

GetMethod · 0.85
GetAliveMethod · 0.85

Calls 1

SocketMethod · 0.45

Tested by

no test coverage detected