-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.h
63 lines (40 loc) · 1.28 KB
/
context.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
//
// Created by bdbai on 22-8-14.
//
#include <cstdint>
#include <optional>
#include <span>
#ifdef WITH_URING
#include <liburing.h>
#endif // WITH_URING
#include "conn.h"
#ifndef MINIP_CONTEXT_H
#define MINIP_CONTEXT_H
namespace minip {
struct worker_set;
struct context {
std::optional<size_t> read(conn &c, std::span<uint8_t> data);
std::optional<size_t> write(conn &c, std::span<const uint8_t> data);
void shutdown(conn &c) const;
[[nodiscard]] void *get_task() const noexcept;
void set_task(void *task);
friend minip::worker_set;
private:
static uint32_t interest_to_epoll(uint8_t interest) noexcept;
context(int epfd, void *task) : epfd(epfd), task(task) {}
#ifdef WITH_URING
context(io_uring *ring, void *task) : ring(ring), task(task) {}
std::optional<size_t> uring_read(conn &c, std::span<uint8_t> data);
std::optional<size_t> uring_write(conn &c, std::span<uint8_t const> data);
#endif // WITH_URING
bool register_interest(conn &c, uint8_t new_interest) const;
int epfd{-1};
#ifdef WITH_URING
io_uring *ring{};
io_uring_cqe *cqe{};
bool retry_needed{};
#endif // WITH_URING
void *task;
};
} // minip
#endif //MINIP_CONTEXT_H