warden.uring.hpp

 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
#pragma once


#include <felspar/io/warden.hpp>


namespace felspar::io {


    class uring_warden : public warden {
        void run_until(felspar::coro::coroutine_handle<>) override;

        struct delivery;
        template<typename R>
        struct completion;
        struct impl;
        std::unique_ptr<impl> ring;

        struct close_completion;
        struct sleep_completion;
        struct read_some_completion;
        struct write_some_completion;
        struct accept_completion;
        struct connect_completion;
        struct poll_completion;

      public:
        uring_warden() : uring_warden{100, {}} {}
        explicit uring_warden(unsigned entries, unsigned flags = {});
        ~uring_warden();

        void run_batch() override;

      protected:

File descriptors

36
37
38
        iop<void> do_close(
                socket_descriptor fd,
                felspar::source_location const &) override;

Time management

41
42
43
        iop<void> do_sleep(
                std::chrono::nanoseconds,
                felspar::source_location const &) override;

Read & write

46
47
48
49
50
51
52
53
54
55
        iop<std::size_t> do_read_some(
                socket_descriptor fd,
                std::span<std::byte>,
                std::optional<std::chrono::nanoseconds>,
                felspar::source_location const &) override;
        iop<std::size_t> do_write_some(
                socket_descriptor fd,
                std::span<std::byte const>,
                std::optional<std::chrono::nanoseconds> timeout,
                felspar::source_location const &) override;

Sockets

58
59
60
61
62
63
64
65
66
67
        iop<socket_descriptor> do_accept(
                socket_descriptor fd,
                std::optional<std::chrono::nanoseconds> timeout,
                felspar::source_location const &) override;
        iop<void> do_connect(
                socket_descriptor fd,
                sockaddr const *,
                socklen_t,
                std::optional<std::chrono::nanoseconds> timeout,
                felspar::source_location const &) override;

File descriptor readiness

70
71
72
73
74
75
76
77
78
79
80
81
        iop<void> do_read_ready(
                socket_descriptor fd,
                std::optional<std::chrono::nanoseconds> timeout,
                felspar::source_location const &) override;
        iop<void> do_write_ready(
                socket_descriptor fd,
                std::optional<std::chrono::nanoseconds> timeout,
                felspar::source_location const &) override;
    };


}