-
Notifications
You must be signed in to change notification settings - Fork 687
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Uri Yagelnik <[email protected]>
- Loading branch information
Showing
16 changed files
with
360 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,139 +1,7 @@ | ||
/* A simple event-driven programming library. Originally I wrote this code | ||
* for the Jim's event-loop (Jim is a Tcl interpreter) but later translated | ||
* it in form of a library for easy reuse. | ||
* | ||
* Copyright (c) 2006-2012, Salvatore Sanfilippo <antirez at gmail dot com> | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* * Neither the name of Redis nor the names of its contributors may be used | ||
* to endorse or promote products derived from this software without | ||
* specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#ifndef __AE_H__ | ||
#define __AE_H__ | ||
|
||
#include "monotonic.h" | ||
|
||
#define AE_OK 0 | ||
#define AE_ERR -1 | ||
|
||
#define AE_NONE 0 /* No events registered. */ | ||
#define AE_READABLE 1 /* Fire when descriptor is readable. */ | ||
#define AE_WRITABLE 2 /* Fire when descriptor is writable. */ | ||
#define AE_BARRIER \ | ||
4 /* With WRITABLE, never fire the event if the \ | ||
READABLE event already fired in the same event \ | ||
loop iteration. Useful when you want to persist \ | ||
things to disk before sending replies, and want \ | ||
to do that in a group fashion. */ | ||
|
||
#define AE_FILE_EVENTS (1 << 0) | ||
#define AE_TIME_EVENTS (1 << 1) | ||
#define AE_ALL_EVENTS (AE_FILE_EVENTS | AE_TIME_EVENTS) | ||
#define AE_DONT_WAIT (1 << 2) | ||
#define AE_CALL_BEFORE_SLEEP (1 << 3) | ||
#define AE_CALL_AFTER_SLEEP (1 << 4) | ||
|
||
#define AE_NOMORE -1 | ||
#define AE_DELETED_EVENT_ID -1 | ||
|
||
/* Macros */ | ||
#define AE_NOTUSED(V) ((void)V) | ||
|
||
struct aeEventLoop; | ||
|
||
/* Types and data structures */ | ||
typedef void aeFileProc(struct aeEventLoop *eventLoop, int fd, void *clientData, int mask); | ||
typedef int aeTimeProc(struct aeEventLoop *eventLoop, long long id, void *clientData); | ||
typedef void aeEventFinalizerProc(struct aeEventLoop *eventLoop, void *clientData); | ||
typedef void aeBeforeSleepProc(struct aeEventLoop *eventLoop); | ||
typedef void aeAfterSleepProc(struct aeEventLoop *eventLoop, int numevents); | ||
|
||
/* File event structure */ | ||
typedef struct aeFileEvent { | ||
int mask; /* one of AE_(READABLE|WRITABLE|BARRIER) */ | ||
aeFileProc *rfileProc; | ||
aeFileProc *wfileProc; | ||
void *clientData; | ||
} aeFileEvent; | ||
|
||
/* Time event structure */ | ||
typedef struct aeTimeEvent { | ||
long long id; /* time event identifier. */ | ||
monotime when; | ||
aeTimeProc *timeProc; | ||
aeEventFinalizerProc *finalizerProc; | ||
void *clientData; | ||
struct aeTimeEvent *prev; | ||
struct aeTimeEvent *next; | ||
int refcount; /* refcount to prevent timer events from being | ||
* freed in recursive time event calls. */ | ||
} aeTimeEvent; | ||
|
||
/* A fired event */ | ||
typedef struct aeFiredEvent { | ||
int fd; | ||
int mask; | ||
} aeFiredEvent; | ||
|
||
/* State of an event based program */ | ||
typedef struct aeEventLoop { | ||
int maxfd; /* highest file descriptor currently registered */ | ||
int setsize; /* max number of file descriptors tracked */ | ||
long long timeEventNextId; | ||
aeFileEvent *events; /* Registered events */ | ||
aeFiredEvent *fired; /* Fired events */ | ||
aeTimeEvent *timeEventHead; | ||
int stop; | ||
void *apidata; /* This is used for polling API specific data */ | ||
aeBeforeSleepProc *beforesleep; | ||
aeAfterSleepProc *aftersleep; | ||
int flags; | ||
} aeEventLoop; | ||
|
||
/* Prototypes */ | ||
aeEventLoop *aeCreateEventLoop(int setsize); | ||
void aeDeleteEventLoop(aeEventLoop *eventLoop); | ||
void aeStop(aeEventLoop *eventLoop); | ||
int aeCreateFileEvent(aeEventLoop *eventLoop, int fd, int mask, aeFileProc *proc, void *clientData); | ||
void aeDeleteFileEvent(aeEventLoop *eventLoop, int fd, int mask); | ||
int aeGetFileEvents(aeEventLoop *eventLoop, int fd); | ||
void *aeGetFileClientData(aeEventLoop *eventLoop, int fd); | ||
long long aeCreateTimeEvent(aeEventLoop *eventLoop, | ||
long long milliseconds, | ||
aeTimeProc *proc, | ||
void *clientData, | ||
aeEventFinalizerProc *finalizerProc); | ||
int aeDeleteTimeEvent(aeEventLoop *eventLoop, long long id); | ||
int aeProcessEvents(aeEventLoop *eventLoop, int flags); | ||
int aeWait(int fd, int mask, long long milliseconds); | ||
void aeMain(aeEventLoop *eventLoop); | ||
char *aeGetApiName(void); | ||
void aeSetBeforeSleepProc(aeEventLoop *eventLoop, aeBeforeSleepProc *beforesleep); | ||
void aeSetAfterSleepProc(aeEventLoop *eventLoop, aeAfterSleepProc *aftersleep); | ||
int aeGetSetSize(aeEventLoop *eventLoop); | ||
int aeResizeSetSize(aeEventLoop *eventLoop, int setsize); | ||
void aeSetDontWait(aeEventLoop *eventLoop, int noWait); | ||
#include "ae_eventloop.h" | ||
#include "ae_apidata.h" | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* ae_apidata.h - Header file for API data functions implemented in ae.c | ||
* | ||
* This header file declares functions that are implemented in ae.c. | ||
* These functions may alter the state of the underlying apidata , | ||
* which may require a mutex for modification in the case of the server | ||
* main event loop (`server.el`), as it may be accessed by IO threads. | ||
*/ | ||
|
||
#ifndef AE_APIDATA_H | ||
#define AE_APIDATA_H | ||
|
||
#include "ae_eventloop.h" | ||
|
||
int aeCreateFileEvent(aeEventLoop *eventLoop, int fd, int mask, aeFileProc *proc, void *clientData); | ||
void aeDeleteFileEvent(aeEventLoop *eventLoop, int fd, int mask); | ||
int aeResizeSetSize(aeEventLoop *eventLoop, int setsize); | ||
int aePoll(aeEventLoop *eventLoop, struct timeval *tvp); | ||
|
||
#endif /* AE_APIDATA_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
/* A simple event-driven programming library. Originally I wrote this code | ||
* for the Jim's event-loop (Jim is a Tcl interpreter) but later translated | ||
* it in form of a library for easy reuse. | ||
* | ||
* Copyright (c) 2006-2012, Salvatore Sanfilippo <antirez at gmail dot com> | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* * Neither the name of Redis nor the names of its contributors may be used | ||
* to endorse or promote products derived from this software without | ||
* specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#ifndef AE_EVENTLOOP_H | ||
#define AE_EVENTLOOP_H | ||
|
||
#include "monotonic.h" | ||
#include <time.h> | ||
|
||
#define AE_OK 0 | ||
#define AE_ERR -1 | ||
|
||
#define AE_NONE 0 /* No events registered. */ | ||
#define AE_READABLE 1 /* Fire when descriptor is readable. */ | ||
#define AE_WRITABLE 2 /* Fire when descriptor is writable. */ | ||
#define AE_BARRIER \ | ||
4 /* With WRITABLE, never fire the event if the \ | ||
READABLE event already fired in the same event \ | ||
loop iteration. Useful when you want to persist \ | ||
things to disk before sending replies, and want \ | ||
to do that in a group fashion. */ | ||
|
||
#define AE_FILE_EVENTS (1 << 0) | ||
#define AE_TIME_EVENTS (1 << 1) | ||
#define AE_ALL_EVENTS (AE_FILE_EVENTS | AE_TIME_EVENTS) | ||
#define AE_DONT_WAIT (1 << 2) | ||
#define AE_CALL_BEFORE_SLEEP (1 << 3) | ||
#define AE_CALL_AFTER_SLEEP (1 << 4) | ||
|
||
#define AE_NOMORE -1 | ||
#define AE_DELETED_EVENT_ID -1 | ||
|
||
/* Macros */ | ||
#define AE_NOTUSED(V) ((void)V) | ||
|
||
struct aeEventLoop; | ||
|
||
/* Types and data structures */ | ||
typedef void aeFileProc(struct aeEventLoop *eventLoop, int fd, void *clientData, int mask); | ||
typedef int aeTimeProc(struct aeEventLoop *eventLoop, long long id, void *clientData); | ||
typedef void aeEventFinalizerProc(struct aeEventLoop *eventLoop, void *clientData); | ||
typedef void aeBeforeSleepProc(struct aeEventLoop *eventLoop); | ||
typedef void aeAfterSleepProc(struct aeEventLoop *eventLoop, int numevents); | ||
typedef int aeCustomPollProc(struct aeEventLoop *eventLoop); | ||
|
||
/* File event structure */ | ||
typedef struct aeFileEvent { | ||
int mask; /* one of AE_(READABLE|WRITABLE|BARRIER) */ | ||
aeFileProc *rfileProc; | ||
aeFileProc *wfileProc; | ||
void *clientData; | ||
} aeFileEvent; | ||
|
||
/* Time event structure */ | ||
typedef struct aeTimeEvent { | ||
long long id; /* time event identifier. */ | ||
monotime when; | ||
aeTimeProc *timeProc; | ||
aeEventFinalizerProc *finalizerProc; | ||
void *clientData; | ||
struct aeTimeEvent *prev; | ||
struct aeTimeEvent *next; | ||
int refcount; /* refcount to prevent timer events from being | ||
* freed in recursive time event calls. */ | ||
} aeTimeEvent; | ||
|
||
/* A fired event */ | ||
typedef struct aeFiredEvent { | ||
int fd; | ||
int mask; | ||
} aeFiredEvent; | ||
|
||
/* State of an event based program */ | ||
typedef struct aeEventLoop { | ||
int maxfd; /* highest file descriptor currently registered */ | ||
int setsize; /* max number of file descriptors tracked */ | ||
long long timeEventNextId; | ||
aeFileEvent *events; /* Registered events */ | ||
aeFiredEvent *fired; /* Fired events */ | ||
aeTimeEvent *timeEventHead; | ||
int stop; | ||
void *apidata; /* This is used for polling API specific data */ | ||
aeBeforeSleepProc *beforesleep; | ||
aeAfterSleepProc *aftersleep; | ||
aeCustomPollProc *custompoll; | ||
int flags; | ||
} aeEventLoop; | ||
|
||
/* Prototypes */ | ||
aeEventLoop *aeCreateEventLoop(int setsize); | ||
void aeDeleteEventLoop(aeEventLoop *eventLoop); | ||
void aeStop(aeEventLoop *eventLoop); | ||
int aeGetFileEvents(aeEventLoop *eventLoop, int fd); | ||
void *aeGetFileClientData(aeEventLoop *eventLoop, int fd); | ||
long long aeCreateTimeEvent(aeEventLoop *eventLoop, | ||
long long milliseconds, | ||
aeTimeProc *proc, | ||
void *clientData, | ||
aeEventFinalizerProc *finalizerProc); | ||
int aeDeleteTimeEvent(aeEventLoop *eventLoop, long long id); | ||
int aeProcessEvents(aeEventLoop *eventLoop, int flags); | ||
int aeWait(int fd, int mask, long long milliseconds); | ||
void aeMain(aeEventLoop *eventLoop); | ||
char *aeGetApiName(void); | ||
void aeSetBeforeSleepProc(aeEventLoop *eventLoop, aeBeforeSleepProc *beforesleep); | ||
void aeSetAfterSleepProc(aeEventLoop *eventLoop, aeAfterSleepProc *aftersleep); | ||
void aeSetCustomPollProc(aeEventLoop *eventLoop, aeCustomPollProc *custompoll); | ||
int aeGetSetSize(aeEventLoop *eventLoop); | ||
void aeSetDontWait(aeEventLoop *eventLoop, int noWait); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.