]> git.proxmox.com Git - ceph.git/blame - ceph/src/arrow/cpp/src/plasma/thirdparty/ae/ae.h
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / cpp / src / plasma / thirdparty / ae / ae.h
CommitLineData
1d09f67e
TL
1/* A simple event-driven programming library. Originally I wrote this code
2 * for the Jim's event-loop (Jim is a Tcl interpreter) but later translated
3 * it in form of a library for easy reuse.
4 *
5 * Copyright (c) 2006-2012, Salvatore Sanfilippo <antirez at gmail dot com>
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * * Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * * Neither the name of Redis nor the names of its contributors may be used
17 * to endorse or promote products derived from this software without
18 * specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#pragma once
34
35#include <time.h>
36
37#define AE_OK 0
38#define AE_ERR -1
39
40#define AE_NONE 0
41#define AE_READABLE 1
42#define AE_WRITABLE 2
43
44#define AE_FILE_EVENTS 1
45#define AE_TIME_EVENTS 2
46#define AE_ALL_EVENTS (AE_FILE_EVENTS|AE_TIME_EVENTS)
47#define AE_DONT_WAIT 4
48
49#define AE_NOMORE -1
50#define AE_DELETED_EVENT_ID -1
51
52/* Macros */
53#define AE_NOTUSED(V) ((void) V)
54
55struct aeEventLoop;
56
57/* Types and data structures */
58typedef void aeFileProc(struct aeEventLoop *eventLoop, int fd, void *clientData, int mask);
59typedef int aeTimeProc(struct aeEventLoop *eventLoop, long long id, void *clientData);
60typedef void aeEventFinalizerProc(struct aeEventLoop *eventLoop, void *clientData);
61typedef void aeBeforeSleepProc(struct aeEventLoop *eventLoop);
62
63/* File event structure */
64typedef struct aeFileEvent {
65 int mask; /* one of AE_(READABLE|WRITABLE) */
66 aeFileProc *rfileProc;
67 aeFileProc *wfileProc;
68 void *clientData;
69} aeFileEvent;
70
71/* Time event structure */
72typedef struct aeTimeEvent {
73 long long id; /* time event identifier. */
74 long when_sec; /* seconds */
75 long when_ms; /* milliseconds */
76 aeTimeProc *timeProc;
77 aeEventFinalizerProc *finalizerProc;
78 void *clientData;
79 struct aeTimeEvent *next;
80} aeTimeEvent;
81
82/* A fired event */
83typedef struct aeFiredEvent {
84 int fd;
85 int mask;
86} aeFiredEvent;
87
88/* State of an event based program */
89typedef struct aeEventLoop {
90 int maxfd; /* highest file descriptor currently registered */
91 int setsize; /* max number of file descriptors tracked */
92 long long timeEventNextId;
93 time_t lastTime; /* Used to detect system clock skew */
94 aeFileEvent *events; /* Registered events */
95 aeFiredEvent *fired; /* Fired events */
96 aeTimeEvent *timeEventHead;
97 int stop;
98 void *apidata; /* This is used for polling API specific data */
99 aeBeforeSleepProc *beforesleep;
100} aeEventLoop;
101
102/* Prototypes */
103aeEventLoop *aeCreateEventLoop(int setsize);
104void aeDeleteEventLoop(aeEventLoop *eventLoop);
105void aeStop(aeEventLoop *eventLoop);
106int aeCreateFileEvent(aeEventLoop *eventLoop, int fd, int mask,
107 aeFileProc *proc, void *clientData);
108void aeDeleteFileEvent(aeEventLoop *eventLoop, int fd, int mask);
109int aeGetFileEvents(aeEventLoop *eventLoop, int fd);
110long long aeCreateTimeEvent(aeEventLoop *eventLoop, long long milliseconds,
111 aeTimeProc *proc, void *clientData,
112 aeEventFinalizerProc *finalizerProc);
113int aeDeleteTimeEvent(aeEventLoop *eventLoop, long long id);
114int aeProcessEvents(aeEventLoop *eventLoop, int flags);
115int aeWait(int fd, int mask, long long milliseconds);
116void aeMain(aeEventLoop *eventLoop);
117char *aeGetApiName(void);
118void aeSetBeforeSleepProc(aeEventLoop *eventLoop, aeBeforeSleepProc *beforesleep);
119int aeGetSetSize(aeEventLoop *eventLoop);
120int aeResizeSetSize(aeEventLoop *eventLoop, int setsize);
121