-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathepoll_socket.h
66 lines (46 loc) · 1.86 KB
/
epoll_socket.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2023, Roman Gershman. All rights reserved.
// See LICENSE for licensing terms.
//
#pragma once
#include "util/fiber_socket_base.h"
#include "util/fibers/epoll_proactor.h"
namespace util {
namespace fb2 {
class EpollSocket : public LinuxSocketBase {
public:
template <typename T> using Result = io::Result<T>;
EpollSocket(int fd = -1);
virtual ~EpollSocket();
ABSL_MUST_USE_RESULT AcceptResult Accept() final;
ABSL_MUST_USE_RESULT error_code Connect(const endpoint_type& ep,
std::function<void(int)> on_pre_connect) final;
ABSL_MUST_USE_RESULT error_code Close() final;
// Really need here expected.
Result<size_t> WriteSome(const iovec* ptr, uint32_t len) override;
void AsyncWriteSome(const iovec* v, uint32_t len, AsyncProgressCb cb) override;
Result<size_t> RecvMsg(const msghdr& msg, int flags) override;
Result<size_t> Recv(const io::MutableBytes& mb, int flags = 0) override;
error_code Shutdown(int how) override;
void RegisterOnErrorCb(std::function<void(uint32_t)> cb) final;
void CancelOnErrorCb() final;
using FiberSocketBase::IsConnClosed;
private:
EpollProactor* GetProactor() {
return static_cast<EpollProactor*>(proactor());
}
void OnSetProactor() final;
void OnResetProactor() final;
// returns true if the operation has completed.
bool SuspendMyself(detail::FiberInterface* cntx, std::error_code* ec);
// kevent pass error code together with completion event.
void Wakey(uint32_t event_flags, int error, EpollProactor* cntr);
detail::FiberInterface* write_context_ = nullptr;
detail::FiberInterface* read_context_ = nullptr;
int32_t arm_index_ = -1;
uint16_t epoll_mask_ = 0;
uint16_t kev_error_ = 0;
std::function<void(uint32_t)> error_cb_;
};
constexpr size_t kSizeofEpollSocket = sizeof(EpollSocket);
} // namespace fb2
} // namespace util