summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_fd_event.h
blob: 3a8d946044d29e8ec32c0d182ca42d330128d832 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118

/*
 * Copyright (C) Igor Sysoev
 * Copyright (C) NGINX, Inc.
 */

#ifndef _NXT_FD_EVENT_H_INCLUDED_
#define _NXT_FD_EVENT_H_INCLUDED_


typedef enum {
    /* A completely inactive event. */
    NXT_EVENT_INACTIVE = 0,

    /*
     * An event presents in the kernel but disabled after oneshot.
     * Used by epoll.
     */
    NXT_EVENT_DISABLED,

    /*
     * An event is active in the kernel but blocked by application.
     * Used by kqueue, epoll, eventport, devpoll, and pollset.
     */
    NXT_EVENT_BLOCKED,

    /*
     * An active oneshot event.
     * Used by epoll, devpoll, pollset, poll, and select.
     */
    NXT_EVENT_ONESHOT,

    /* An active level-triggered event.  Used by eventport. */
    NXT_EVENT_LEVEL,

    /*
     * An active default event.  The event type depends on interface:
     *    edge-triggered for kqueue, and modern epoll;
     *    level-triggered for old epoll, devpoll, pollset, poll, and select;
     *    oneshot for kqueue and eventport.
     */
    NXT_EVENT_DEFAULT,
    NXT_EVENT_ACTIVE = NXT_EVENT_DEFAULT,
} nxt_fd_event_state_t;


#define nxt_fd_event_is_disabled(state)                                       \
    ((state) < NXT_EVENT_ONESHOT)


#define nxt_fd_event_is_active(state)                                         \
    ((state) >= NXT_EVENT_ONESHOT)


struct nxt_fd_event_s {
    void                    *data;

    /* Both are int's. */
    nxt_socket_t            fd;
    nxt_err_t               error;

    /* The flags should also be prefetched by nxt_work_queue_pop(). */

#if (NXT_64BIT)
    nxt_fd_event_state_t      read:8;       /* 3 bits. */
    nxt_fd_event_state_t      write:8;      /* 3 bits. */
    uint8_t                   read_ready;
    uint8_t                   write_ready;
    uint8_t                   changing;
    uint8_t                   closed;
    uint8_t                   timedout;
    uint8_t                   shutdown:1;
#if (NXT_HAVE_EPOLL)
    uint8_t                   epoll_eof:1;
    uint8_t                   epoll_error:1;
#endif
#if (NXT_HAVE_KQUEUE)
    uint8_t                   kq_eof:1;
#endif

#else /* NXT_32BIT */
    nxt_fd_event_state_t      read:3;
    nxt_fd_event_state_t      write:3;
    uint8_t                   read_ready:1;
    uint8_t                   write_ready:1;
    uint8_t                   changing:1;
    uint8_t                   closed:1;
    uint8_t                   timedout:1;
    uint8_t                   shutdown:1;
#if (NXT_HAVE_EPOLL)
    uint8_t                   epoll_eof:1;
    uint8_t                   epoll_error:1;
#endif
#if (NXT_HAVE_KQUEUE)
    uint8_t                   kq_eof:1;
#endif
#endif /* NXT_64BIT */

#if (NXT_HAVE_KQUEUE)
    /* nxt_err_t is int. */
    nxt_err_t               kq_errno;
    /* struct kevent.data is intptr_t, however int32_t is enough. */
    int32_t                 kq_available;
#endif

    nxt_task_t              *task;

    nxt_work_queue_t        *read_work_queue;
    nxt_work_handler_t      read_handler;
    nxt_work_queue_t        *write_work_queue;
    nxt_work_handler_t      write_handler;
    nxt_work_handler_t      error_handler;

    nxt_log_t               *log;
};


#endif /* _NXT_FD_EVENT_H_INCLUDED_ */