summaryrefslogtreecommitdiff
path: root/libphobos/libdruntime/core/sys/linux/epoll.d
blob: f5ff7dba0f803c06c71a3b212f8c1c65eed71d9b (plain)
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/**
 * D header file to interface with the Linux epoll API (http://man7.org/linux/man-pages/man7/epoll.7.html).
 * Available since Linux 2.6
 *
 * Copyright: Copyright Adil Baig 2012.
 * License : $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
 * Authors  : Adil Baig (github.com/adilbaig)
 */
module core.sys.linux.epoll;

version (linux):

import core.sys.posix.signal : sigset_t;

extern (C):
@system:
@nogc:
nothrow:
@system:

version (ARM)     version = ARM_Any;
version (AArch64) version = ARM_Any;
version (HPPA)    version = HPPA_Any;
version (MIPS32)  version = MIPS_Any;
version (MIPS64)  version = MIPS_Any;
version (PPC)     version = PPC_Any;
version (PPC64)   version = PPC_Any;
version (RISCV32) version = RISCV_Any;
version (RISCV64) version = RISCV_Any;
version (S390)    version = IBMZ_Any;
version (SPARC)   version = SPARC_Any;
version (SPARC64) version = SPARC_Any;
version (SystemZ) version = IBMZ_Any;
version (X86)     version = X86_Any;
version (X86_64)  version = X86_Any;

enum
{
    EPOLL_CLOEXEC  = 0x80000,
    EPOLL_NONBLOCK = 0x800
}

enum
{
    EPOLLIN     = 0x001,
    EPOLLPRI    = 0x002,
    EPOLLOUT    = 0x004,
    EPOLLRDNORM = 0x040,
    EPOLLRDBAND = 0x080,
    EPOLLWRNORM = 0x100,
    EPOLLWRBAND = 0x200,
    EPOLLMSG    = 0x400,
    EPOLLERR    = 0x008,
    EPOLLHUP    = 0x010,
    EPOLLRDHUP  = 0x2000, // since Linux 2.6.17
    EPOLLEXCLUSIVE = 1u << 28, // since Linux 4.5
    EPOLLWAKEUP = 1u << 29,
    EPOLLONESHOT = 1u << 30,
    EPOLLET     = 1u << 31
}

/**
 * Valid opcodes ( "op" parameter ) to issue to epoll_ctl().
 */
enum
{
    EPOLL_CTL_ADD = 1, /// Add a file descriptor to the interface.
    EPOLL_CTL_DEL = 2, /// Remove a file descriptor from the interface.
    EPOLL_CTL_MOD = 3, /// Change file descriptor epoll_event structure.
}

version (X86_Any)
{
    align(1) struct epoll_event
    {
    align(1):
        uint events;
        epoll_data_t data;
    }
}
else version (ARM_Any)
{
    struct epoll_event
    {
        uint events;
        epoll_data_t data;
    }
}
else version (PPC_Any)
{
    struct epoll_event
    {
        uint events;
        epoll_data_t data;
    }
}
else version (HPPA_Any)
{
    struct epoll_event
    {
        uint events;
        epoll_data_t data;
    }
}
else version (MIPS_Any)
{
    struct epoll_event
    {
        uint events;
        epoll_data_t data;
    }
}
else version (RISCV_Any)
{
    struct epoll_event
    {
        uint events;
        epoll_data_t data;
    }
}
else version (SPARC_Any)
{
    struct epoll_event
    {
        uint events;
        epoll_data_t data;
    }
}
else version (IBMZ_Any)
{
    struct epoll_event
    {
        uint events;
        epoll_data_t data;
    }
}
else
{
    static assert(false, "Platform not supported");
}

union epoll_data_t
{
    void *ptr;
    int fd;
    uint u32;
    ulong u64;
}

/**
 * Creates an epoll instance.
 *
 * Params:
 *   size = a hint specifying the number of file descriptors to be associated
 *          with the new instance.  T
 * Returns: an fd for the new instance. The fd returned by epoll_create() should
 *          be closed with close().
 * See_also: epoll_create1 (int flags)
 */
int epoll_create (int size);

/* Same as epoll_create but with an FLAGS parameter.  The unused SIZE
   parameter has been dropped.  */

/**
 * Creates an epoll instance.
 *
 * Params:
 *   flags = a specified flag. If flags is 0, then, other than the fact that the
 *           obsolete size argument is dropped, epoll_create1() is the same as
 *           epoll_create().
 * Returns: an fd for the new instance. The fd returned by epoll_create() should
 *          be closed with close().
 * See_also: epoll_create (int size)
 */
int epoll_create1 (int flags);

/**
 * Manipulate an epoll instance
 *
 * Params:
 *   epfd = an epoll file descriptor instance
 *   op = one of the EPOLL_CTL_* constants
 *   fd = target file descriptor of the operation
 *   event = describes which events the caller is interested in and any
 *           associated user dat
 * Returns: 0 in case of success, -1 in case of error ( the "errno" variable
 *          will contain the specific error code )
 */
int epoll_ctl (int epfd, int op, int fd, epoll_event *event);


/**
 * Wait for events on an epoll instance.
 *
 *
 * Params:
 *   epfd = an epoll file descriptor instance
 *   events = a buffer that will contain triggered events
 *   maxevents = the maximum number of events to be returned ( usually size of
 *               "events" )
 *   timeout = specifies the maximum wait time in milliseconds (-1 == infinite)
 *
 * Returns: the number of triggered events returned in "events" buffer. Or -1 in
 *          case of error with the "errno" variable set to the specific error
 *          code.
 */
int epoll_wait (int epfd, epoll_event *events, int maxevents, int timeout);

/**
 * Wait for events on an epoll instance
 *
 *
 * Params:
 *   epfd = an epoll file descriptor instance
 *   events = a buffer that will contain triggered events
 *   maxevents = the maximum number of events to be returned ( usually size of
 *               "events" )
 *   timeout = specifies the maximum wait time in milliseconds (-1 == infinite)
 *   ss = a signal set. May be specified as `null`, in which case epoll_pwait() is
 *        equivalent to epoll_wait().
 *
 * Returns: the number of triggered events returned in "events" buffer. Or -1 in
 *          case of error with the "errno" variable set to the specific error
 *          code.
 */
int epoll_pwait (int epfd, epoll_event *events, int maxevents, int timeout,
    const sigset_t *ss);