2 * Copyright © 2016 Keith Packard
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
26 /* Forward declaration */
30 * ospoll_wait trigger mode
32 * @ospoll_trigger_edge
33 * Trigger only when going from no data available
36 * @ospoll_trigger_level
37 * Trigger whenever there is data available
45 * Create a new ospoll structure
51 * Destroy an ospoll structure
53 * @param ospoll ospoll to destroy
56 ospoll_destroy(struct ospoll
*ospoll
);
59 * Add a file descriptor to monitor
61 * @param ospoll ospoll to add to
62 * @param fd File descriptor to monitor
63 * @param trigger Trigger mode for ospoll_wait
64 * @param callback Function to call when triggered
65 * @param data Extra data to pass callback
68 ospoll_add(struct ospoll
*ospoll
, int fd
,
69 enum ospoll_trigger trigger
,
70 void (*callback
)(int fd
, int xevents
, void *data
),
74 * Remove a monitored file descriptor
76 * @param ospoll ospoll to remove from
77 * @param fd File descriptor to stop monitoring
80 ospoll_remove(struct ospoll
*ospoll
, int fd
);
83 * Listen on additional events
85 * @param ospoll ospoll monitoring fd
86 * @param fd File descriptor to change
87 * @param events Additional events to trigger on
90 ospoll_listen(struct ospoll
*ospoll
, int fd
, int xevents
);
93 * Stop listening on events
95 * @param ospoll ospoll monitoring fd
96 * @param fd File descriptor to change
97 * @param events events to stop triggering on
100 ospoll_mute(struct ospoll
*ospoll
, int fd
, int xevents
);
105 * @param ospoll ospoll to wait on
106 * @param timeout < 0 wait forever
107 * = 0 check and return
108 * > 0 timeout in milliseconds
111 * > 0 number of events delivered
114 ospoll_wait(struct ospoll
*ospoll
, int timeout
);
117 * Reset edge trigger status
119 * @param ospoll ospoll monitoring fd
120 * @param fd file descriptor
122 * ospoll_reset_events resets the state of an edge-triggered
123 * fd so that ospoll_wait calls will report events again.
125 * Call this after a read/recv operation reports no more data available.
128 ospoll_reset_events(struct ospoll
*ospoll
, int fd
);
131 * Fetch the data associated with an fd
133 * @param ospoll ospoll monitoring fd
134 * @param fd file descriptor
136 * @return data parameter passed to ospoll_add call on
137 * this file descriptor
140 ospoll_data(struct ospoll
*ospoll
, int fd
);
142 #endif /* _OSPOLL_H_ */