aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/coroutine/engine/poller.h
blob: 8ea012c0fc9191acb55761883e0e61d5ebbec640 (plain) (blame)
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
#pragma once

#include <util/generic/ptr.h>
#include <util/generic/vector.h>
#include <util/network/socket.h>
#include <util/network/pollerimpl.h>
#include <util/datetime/base.h>

enum class EContPoller {
    Default /* "default" */,
    Combined /* "combined" */,
    Select /* "select" */,
    Poll /* "poll" */,
    Epoll /* "epoll" */,
    Kqueue /* "kqueue" */
};

class IPollerFace {
public:
    struct TChange {
        SOCKET Fd;
        void* Data;
        ui16 Flags;
    };

    struct TEvent {
        void* Data;
        int Status;
        ui16 Filter;
    };

    using TEvents = TVector<TEvent>;

    virtual ~IPollerFace() {
    }

    void Set(void* ptr, SOCKET fd, ui16 flags) {
        const TChange c = {fd, ptr, flags};

        Set(c);
    }

    virtual void Set(const TChange& change) = 0;
    virtual void Wait(TEvents& events, TInstant deadLine) = 0;
    virtual EContPoller PollEngine() const = 0;

    static THolder<IPollerFace> Default();
    static THolder<IPollerFace> Construct(TStringBuf name);
    static THolder<IPollerFace> Construct(EContPoller poller);
};