diff --git a/wpoll.gyp b/epoll.gyp
similarity index 85%
rename from wpoll.gyp
rename to epoll.gyp
index 8029a95..22d308f 100644
--- a/wpoll.gyp
+++ b/epoll.gyp
@@ -4,7 +4,7 @@
'targets': [
{
- 'target_name': 'wpoll',
+ 'target_name': 'epoll',
'type': '<(library)',
'libraries': ['-lws2_32.lib' ],
@@ -17,13 +17,13 @@
'sources': [
'common.gypi',
- 'include/wpoll.h',
+ 'include/epoll.h',
'src/msafd.c',
'src/msafd.h',
'src/ntapi.c',
'src/ntapi.h',
'src/tree.h',
- 'src/wpoll.c',
+ 'src/epoll.c',
]
},
@@ -31,7 +31,7 @@
'target_name': 'test',
'type': 'executable',
- 'dependencies': [ 'wpoll' ],
+ 'dependencies': [ 'epoll' ],
'libraries': ['-lws2_32.lib' ],
'include_dirs': [ 'include', 'src' ],
diff --git a/wpoll.sln b/epoll.sln
similarity index 69%
rename from wpoll.sln
rename to epoll.sln
index 395f515..9e076a2 100644
--- a/wpoll.sln
+++ b/epoll.sln
@@ -1,26 +1,26 @@
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "epoll", "epoll.vcxproj", "{2CF47921-4CCE-ADEA-4A82-BC6521983261}"
+EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test", "test.vcxproj", "{58F32AFA-FCBB-2A4D-DCB4-242324A2FAC4}"
ProjectSection(ProjectDependencies) = postProject
- {9221E672-D419-F7D7-9259-A7D2BE1D177A} = {9221E672-D419-F7D7-9259-A7D2BE1D177A}
+ {2CF47921-4CCE-ADEA-4A82-BC6521983261} = {2CF47921-4CCE-ADEA-4A82-BC6521983261}
EndProjectSection
EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wpoll", "wpoll.vcxproj", "{9221E672-D419-F7D7-9259-A7D2BE1D177A}"
-EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {2CF47921-4CCE-ADEA-4A82-BC6521983261}.Debug|Win32.ActiveCfg = Debug|Win32
+ {2CF47921-4CCE-ADEA-4A82-BC6521983261}.Debug|Win32.Build.0 = Debug|Win32
+ {2CF47921-4CCE-ADEA-4A82-BC6521983261}.Release|Win32.ActiveCfg = Release|Win32
+ {2CF47921-4CCE-ADEA-4A82-BC6521983261}.Release|Win32.Build.0 = Release|Win32
{58F32AFA-FCBB-2A4D-DCB4-242324A2FAC4}.Debug|Win32.ActiveCfg = Debug|Win32
{58F32AFA-FCBB-2A4D-DCB4-242324A2FAC4}.Debug|Win32.Build.0 = Debug|Win32
{58F32AFA-FCBB-2A4D-DCB4-242324A2FAC4}.Release|Win32.ActiveCfg = Release|Win32
{58F32AFA-FCBB-2A4D-DCB4-242324A2FAC4}.Release|Win32.Build.0 = Release|Win32
- {9221E672-D419-F7D7-9259-A7D2BE1D177A}.Debug|Win32.ActiveCfg = Debug|Win32
- {9221E672-D419-F7D7-9259-A7D2BE1D177A}.Debug|Win32.Build.0 = Debug|Win32
- {9221E672-D419-F7D7-9259-A7D2BE1D177A}.Release|Win32.ActiveCfg = Release|Win32
- {9221E672-D419-F7D7-9259-A7D2BE1D177A}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/epoll.vcxproj b/epoll.vcxproj
new file mode 100644
index 0000000..88f82fe
--- /dev/null
+++ b/epoll.vcxproj
@@ -0,0 +1 @@
+DebugWin32ReleaseWin32{2CF47921-4CCE-ADEA-4A82-BC6521983261}Win32ProjepollStaticLibrary$(ExecutablePath);$(MSBuildProjectDirectory)\.\bin\;$(MSBuildProjectDirectory)\.\bin\$(Configuration)\obj\$(ProjectName)\falsetrue$(SolutionDir)$(Configuration)\$(ProjectName)$(OutDir)\lib\$(ProjectName).libinclude;src;%(AdditionalIncludeDirectories)/MP %(AdditionalOptions)EnableFastCheckstrueProgramDatabaseSyncfalsefalseDisabledWIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;DEBUG;_DEBUG;%(PreprocessorDefinitions)MultiThreadedDebugtruetruefalseLevel3$(OutDir)lib\$(ProjectName).libws2_32.lib;%(AdditionalDependencies)truetruetruetruetrueinclude;src;%(AdditionalIncludeDirectories)WIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;DEBUG;_DEBUG;%(PreprocessorDefinitions);%(PreprocessorDefinitions)include;src;%(AdditionalIncludeDirectories)/MP %(AdditionalOptions)trueProgramDatabaseSyncSpeedtrueAnySuitabletruetrueFullWIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;NDEBUG;%(PreprocessorDefinitions)MultiThreadedtruetruefalseLevel3true/LTCG %(AdditionalOptions)$(OutDir)lib\$(ProjectName).libws2_32.lib;%(AdditionalDependencies)truetruetruetrueUseLinkTimeCodeGenerationtruetruetrueinclude;src;%(AdditionalIncludeDirectories)WIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;NDEBUG;%(PreprocessorDefinitions);%(PreprocessorDefinitions)
\ No newline at end of file
diff --git a/gen.bat b/gen.bat
index 07247b3..6e139e0 100644
--- a/gen.bat
+++ b/gen.bat
@@ -1 +1 @@
-python \gyp\gyp -Dlibrary=static_library -Icommon.gypi wpoll.gyp --depth=.
+python \gyp\gyp -Dlibrary=static_library -Icommon.gypi epoll.gyp --depth=.
diff --git a/include/epoll.h b/include/epoll.h
new file mode 100644
index 0000000..45b495e
--- /dev/null
+++ b/include/epoll.h
@@ -0,0 +1,61 @@
+
+#ifndef EPOLL_H_
+#define EPOLL_H_
+
+#include
+#include
+
+#include
+
+
+#define EPOLLIN 0x001
+#define EPOLLPRI 0x002
+#define EPOLLOUT 0x004
+#define EPOLLERR 0x008
+#define EPOLLHUP 0x010
+#define EPOLLRDNORM 0x040
+#define EPOLLRDBAND 0x080
+#define EPOLLWRNORM 0x100
+#define EPOLLMSG 0x400
+#define EPOLLWRBAND 0x200
+#define EPOLLRDHUP 0x2000
+
+#define EPOLL_EVENT_MASK 0xffff
+
+/* #define EPOLLET (1 << 30) Not supported */
+#define EPOLLONESHOT (1 << 31)
+
+
+#define EPOLL_CTL_ADD 1
+#define EPOLL_CTL_MOD 2
+#define EPOLL_CTL_DEL 3
+
+typedef void* epoll_t;
+
+typedef union epoll_data {
+ void *ptr;
+ int fd;
+ uint32_t u32;
+ uint64_t u64;
+ /* Windows-specific extensions. */
+ SOCKET sock;
+ HANDLE hnd;
+} epoll_data_t;
+
+struct epoll_event {
+ uint32_t events; /* Epoll events */
+ epoll_data_t data; /* User data variable */
+};
+
+epoll_t epoll_create();
+
+int epoll_close(epoll_t epoll_hnd);
+
+int epoll_ctl(epoll_t epoll_hnd, int op, SOCKET sock, struct epoll_event* event);
+
+int epoll_wait(epoll_t epoll_hnd, struct epoll_event* events, int maxevents, int timeout);
+
+int afd_init();
+
+
+#endif /* EPOLL_H_ */
\ No newline at end of file
diff --git a/include/wpoll.h b/include/wpoll.h
deleted file mode 100644
index 5a3ccd4..0000000
--- a/include/wpoll.h
+++ /dev/null
@@ -1,61 +0,0 @@
-
-#ifndef WPOLL_H_
-#define WPOLL_H_
-
-#include
-#include
-
-#include
-
-
-#define WPOLLIN 0x001
-#define WPOLLPRI 0x002
-#define WPOLLOUT 0x004
-#define WPOLLERR 0x008
-#define WPOLLHUP 0x010
-#define WPOLLRDNORM 0x040
-#define WPOLLRDBAND 0x080
-#define WPOLLWRNORM 0x100
-#define WPOLLMSG 0x400
-#define WPOLLWRBAND 0x200
-#define WPOLLRDHUP 0x2000
-
-#define WPOLL_EVENT_MASK 0xffff
-
-/* #define WPOLLET (1 << 30) Not supported */
-#define WPOLLONESHOT (1 << 31)
-
-
-#define WPOLL_CTL_ADD 1
-#define WPOLL_CTL_MOD 2
-#define WPOLL_CTL_DEL 3
-
-typedef void* wpoll_t;
-
-typedef union wpoll_data {
- void *ptr;
- int fd;
- uint32_t u32;
- uint64_t u64;
- /* Windows-specific extensions. */
- SOCKET sock;
- HANDLE hnd;
-} wpoll_data_t;
-
-struct wpoll_event {
- uint32_t events; /* Epoll events */
- wpoll_data_t data; /* User data variable */
-};
-
-wpoll_t wpoll_create();
-
-int wpoll_close(wpoll_t wpoll_hnd);
-
-int wpoll_ctl(wpoll_t wpoll_hnd, int op, SOCKET sock, struct wpoll_event* event);
-
-int wpoll_wait(wpoll_t wpoll_hnd, struct wpoll_event* events, int maxevents, int timeout);
-
-int afd_init();
-
-
-#endif /* WPOLL_H_ */
\ No newline at end of file
diff --git a/src/wpoll.c b/src/epoll.c
similarity index 76%
rename from src/wpoll.c
rename to src/epoll.c
index 3a7ba63..9df9f40 100644
--- a/src/wpoll.c
+++ b/src/epoll.c
@@ -2,30 +2,30 @@
#include
#include
-#include
+#include
#include "msafd.h"
#include "tree.h"
#define ARRAY_COUNT(a) (sizeof(a) / (sizeof((a)[0])))
-#define WPOLL_KEY 0xE9011
+#define EPOLL_KEY 0xE9011
-typedef struct wpoll_port_data_s wpoll_port_data_t;
-typedef struct wpoll_op_s wpoll_op_t;
-typedef struct wpoll_sock_data_s wpoll_sock_data_t;
+typedef struct epoll_port_data_s epoll_port_data_t;
+typedef struct epoll_op_s epoll_op_t;
+typedef struct epoll_sock_data_s epoll_sock_data_t;
-/* State associated with a wpoll handle. */
-struct wpoll_port_data_s {
+/* State associated with a epoll handle. */
+struct epoll_port_data_s {
HANDLE iocp;
SOCKET peer_sockets[ARRAY_COUNT(AFD_PROVIDER_IDS)];
- RB_HEAD(wpoll_sock_data_tree, wpoll_sock_data_s) sock_data_tree;
- wpoll_sock_data_t* attn;
+ RB_HEAD(epoll_sock_data_tree, epoll_sock_data_s) sock_data_tree;
+ epoll_sock_data_t* attn;
size_t pending_ops_count;
};
-/* State associated with a socket that is registered to the wpoll port. */
-typedef struct wpoll_sock_data_s {
+/* State associated with a socket that is registered to the epoll port. */
+typedef struct epoll_sock_data_s {
SOCKET sock;
SOCKET base_sock;
SOCKET peer_sock;
@@ -34,33 +34,33 @@ typedef struct wpoll_sock_data_s {
int events;
int attn;
uint64_t user_data;
- wpoll_op_t* free_op;
- wpoll_sock_data_t* attn_prev;
- wpoll_sock_data_t* attn_next;
- RB_ENTRY(wpoll_sock_data_s) tree_entry;
+ epoll_op_t* free_op;
+ epoll_sock_data_t* attn_prev;
+ epoll_sock_data_t* attn_next;
+ RB_ENTRY(epoll_sock_data_s) tree_entry;
};
/* State associated with a AFD_POLL request. */
-struct wpoll_op_s {
+struct epoll_op_s {
OVERLAPPED overlapped;
AFD_POLL_INFO poll_info;
int generation;
- wpoll_sock_data_t* sock_data;
+ epoll_sock_data_t* sock_data;
};
-int wpoll_socket_compare(wpoll_sock_data_t* a, wpoll_sock_data_t* b) {
+int epoll_socket_compare(epoll_sock_data_t* a, epoll_sock_data_t* b) {
return a->sock - b->sock;
}
-RB_GENERATE_STATIC(wpoll_sock_data_tree, wpoll_sock_data_s, tree_entry, wpoll_socket_compare)
+RB_GENERATE_STATIC(epoll_sock_data_tree, epoll_sock_data_s, tree_entry, epoll_socket_compare)
-wpoll_t wpoll_create() {
+epoll_t epoll_create() {
HANDLE iocp;
- wpoll_port_data_t* port_data = malloc(sizeof *port_data);
+ epoll_port_data_t* port_data = malloc(sizeof *port_data);
if (port_data == NULL) {
SetLastError(ERROR_OUTOFMEMORY);
return NULL;
@@ -82,10 +82,10 @@ wpoll_t wpoll_create() {
memset(&port_data->peer_sockets, 0, sizeof port_data->peer_sockets);
RB_INIT(&port_data->sock_data_tree);
- return (wpoll_t) port_data;
+ return (epoll_t) port_data;
}
-static SOCKET wpoll__create_peer_socket(HANDLE iocp,
+static SOCKET epoll__create_peer_socket(HANDLE iocp,
WSAPROTOCOL_INFOW* protocol_info) {
SOCKET sock = 0;
@@ -105,7 +105,7 @@ static SOCKET wpoll__create_peer_socket(HANDLE iocp,
if (CreateIoCompletionPort((HANDLE) sock,
iocp,
- WPOLL_KEY,
+ EPOLL_KEY,
0) == NULL) {
goto error;
}
@@ -118,7 +118,7 @@ static SOCKET wpoll__create_peer_socket(HANDLE iocp,
}
-static SOCKET wpoll__get_peer_socket(wpoll_port_data_t* port_data,
+static SOCKET epoll__get_peer_socket(epoll_port_data_t* port_data,
WSAPROTOCOL_INFOW* protocol_info) {
int index, i;
SOCKET peer_socket;
@@ -143,7 +143,7 @@ static SOCKET wpoll__get_peer_socket(wpoll_port_data_t* port_data,
/* protocol. */
peer_socket = port_data->peer_sockets[index];
if (peer_socket == 0) {
- peer_socket = wpoll__create_peer_socket(port_data->iocp, protocol_info);
+ peer_socket = epoll__create_peer_socket(port_data->iocp, protocol_info);
port_data->peer_sockets[index] = peer_socket;
}
@@ -151,27 +151,27 @@ static SOCKET wpoll__get_peer_socket(wpoll_port_data_t* port_data,
}
-int wpoll__submit_poll_op(wpoll_port_data_t* port_data, wpoll_sock_data_t* sock_data) {
- wpoll_op_t* op;
+int epoll__submit_poll_op(epoll_port_data_t* port_data, epoll_sock_data_t* sock_data) {
+ epoll_op_t* op;
int events;
DWORD result, afd_events;
op = sock_data->free_op;
events = sock_data->events;
- /* wpoll_ctl should ensure that there is a free op struct. */
+ /* epoll_ctl should ensure that there is a free op struct. */
assert(op != NULL);
/* These events should always be registered. */
- assert(events & WPOLLERR);
- assert(events & WPOLLHUP);
+ assert(events & EPOLLERR);
+ assert(events & EPOLLHUP);
afd_events = AFD_POLL_ABORT | AFD_POLL_CONNECT_FAIL | AFD_POLL_LOCAL_CLOSE;
- if (events & (WPOLLIN | WPOLLRDNORM))
+ if (events & (EPOLLIN | EPOLLRDNORM))
afd_events |= AFD_POLL_RECEIVE | AFD_POLL_ACCEPT;
- if (events & (WPOLLIN | WPOLLRDBAND))
+ if (events & (EPOLLIN | EPOLLRDBAND))
afd_events |= AFD_POLL_RECEIVE_EXPEDITED;
- if (events & (WPOLLOUT | WPOLLWRNORM | WPOLLRDBAND))
+ if (events & (EPOLLOUT | EPOLLWRNORM | EPOLLRDBAND))
afd_events |= AFD_POLL_SEND | AFD_POLL_CONNECT;
op->generation = ++sock_data->op_generation;
@@ -205,16 +205,16 @@ int wpoll__submit_poll_op(wpoll_port_data_t* port_data, wpoll_sock_data_t* sock_
}
-int wpoll_ctl(wpoll_t port_handle, int op, SOCKET sock,
- struct wpoll_event* event) {
- wpoll_port_data_t* port_data;
+int epoll_ctl(epoll_t port_handle, int op, SOCKET sock,
+ struct epoll_event* event) {
+ epoll_port_data_t* port_data;
- port_data = (wpoll_port_data_t*) port_handle;
+ port_data = (epoll_port_data_t*) port_handle;
switch (op) {
- case WPOLL_CTL_ADD: {
- wpoll_sock_data_t* sock_data;
- wpoll_op_t* op;
+ case EPOLL_CTL_ADD: {
+ epoll_sock_data_t* sock_data;
+ epoll_op_t* op;
SOCKET peer_sock;
WSAPROTOCOL_INFOW protocol_info;
int len;
@@ -229,7 +229,7 @@ int wpoll_ctl(wpoll_t port_handle, int op, SOCKET sock,
return -1;
}
- peer_sock = wpoll__get_peer_socket(port_data, &protocol_info);
+ peer_sock = epoll__get_peer_socket(port_data, &protocol_info);
if (peer_sock == INVALID_SOCKET) {
return -1;
}
@@ -252,12 +252,12 @@ int wpoll_ctl(wpoll_t port_handle, int op, SOCKET sock,
sock_data->base_sock = sock;
sock_data->op_generation = 0;
sock_data->submitted_events = 0;
- sock_data->events = event->events | WPOLLERR | WPOLLHUP;
+ sock_data->events = event->events | EPOLLERR | EPOLLHUP;
sock_data->user_data = event->data.u64;
sock_data->peer_sock = peer_sock;
sock_data->free_op = op;
- if (RB_INSERT(wpoll_sock_data_tree, &port_data->sock_data_tree, sock_data) != NULL) {
+ if (RB_INSERT(epoll_sock_data_tree, &port_data->sock_data_tree, sock_data) != NULL) {
/* Socket was already added. */
free(sock_data);
free(op);
@@ -276,21 +276,21 @@ int wpoll_ctl(wpoll_t port_handle, int op, SOCKET sock,
return 0;
}
- case WPOLL_CTL_MOD: {
- wpoll_sock_data_t lookup;
- wpoll_sock_data_t* sock_data;
+ case EPOLL_CTL_MOD: {
+ epoll_sock_data_t lookup;
+ epoll_sock_data_t* sock_data;
lookup.sock = sock;
- sock_data = RB_FIND(wpoll_sock_data_tree, &port_data->sock_data_tree, &lookup);
+ sock_data = RB_FIND(epoll_sock_data_tree, &port_data->sock_data_tree, &lookup);
if (sock_data == NULL) {
- /* Socket has not been registered with wpoll instance. */
+ /* Socket has not been registered with epoll instance. */
SetLastError(ERROR_NOT_FOUND);
return -1;
}
if (event->events & ~sock_data->submitted_events) {
if (sock_data->free_op == NULL) {
- wpoll_op_t* op = malloc(sizeof *op);
+ epoll_op_t* op = malloc(sizeof *op);
if (op == NULL) {
SetLastError(ERROR_OUTOFMEMORY);
return -1;
@@ -310,24 +310,24 @@ int wpoll_ctl(wpoll_t port_handle, int op, SOCKET sock,
}
}
- sock_data->events = event->events | WPOLLERR | WPOLLHUP;
+ sock_data->events = event->events | EPOLLERR | EPOLLHUP;
sock_data->user_data = event->data.u64;
return 0;
}
- case WPOLL_CTL_DEL: {
- wpoll_sock_data_t lookup;
- wpoll_sock_data_t* sock_data;
+ case EPOLL_CTL_DEL: {
+ epoll_sock_data_t lookup;
+ epoll_sock_data_t* sock_data;
lookup.sock = sock;
- sock_data = RB_FIND(wpoll_sock_data_tree, &port_data->sock_data_tree, &lookup);
+ sock_data = RB_FIND(epoll_sock_data_tree, &port_data->sock_data_tree, &lookup);
if (sock_data == NULL) {
- /* Socket has not been registered with wpoll instance. */
+ /* Socket has not been registered with epoll instance. */
SetLastError(ERROR_NOT_FOUND);
return -1;
}
- RB_REMOVE(wpoll_sock_data_tree, &port_data->sock_data_tree, sock_data);
+ RB_REMOVE(epoll_sock_data_tree, &port_data->sock_data_tree, sock_data);
free(sock_data->free_op);
sock_data->events = -1;
@@ -363,21 +363,21 @@ int wpoll_ctl(wpoll_t port_handle, int op, SOCKET sock,
}
-int wpoll_wait(wpoll_t port_handle, struct wpoll_event* events, int maxevents, int timeout) {
- wpoll_port_data_t* port_data;
+int epoll_wait(epoll_t port_handle, struct epoll_event* events, int maxevents, int timeout) {
+ epoll_port_data_t* port_data;
DWORD due;
DWORD gqcs_timeout;
- port_data = (wpoll_port_data_t*) port_handle;
+ port_data = (epoll_port_data_t*) port_handle;
/* Create overlapped poll operations for all sockets on the attention list. */
while (port_data->attn != NULL) {
- wpoll_sock_data_t* sock_data = port_data->attn;
+ epoll_sock_data_t* sock_data = port_data->attn;
assert(sock_data->attn);
/* Check if we need to submit another req. */
- if (sock_data->events & WPOLL_EVENT_MASK & ~sock_data->submitted_events) {
- int r = wpoll__submit_poll_op(port_data, sock_data);
+ if (sock_data->events & EPOLL_EVENT_MASK & ~sock_data->submitted_events) {
+ int r = epoll__submit_poll_op(port_data, sock_data);
/* TODO: handle error. */
}
@@ -433,13 +433,13 @@ int wpoll_wait(wpoll_t port_handle, struct wpoll_event* events, int maxevents, i
/* Successfully dequeued overlappeds. */
for (i = 0; i < count; i++) {
OVERLAPPED* overlapped;
- wpoll_op_t* op;
- wpoll_sock_data_t* sock_data;
+ epoll_op_t* op;
+ epoll_sock_data_t* sock_data;
DWORD afd_events;
int registered_events, reported_events;
overlapped = entries[i].lpOverlapped;
- op = CONTAINING_RECORD(overlapped, wpoll_op_t, overlapped);
+ op = CONTAINING_RECORD(overlapped, epoll_op_t, overlapped);
sock_data = op->sock_data;
if (op->generation < sock_data->op_generation) {
@@ -466,9 +466,9 @@ int wpoll_wait(wpoll_t port_handle, struct wpoll_event* events, int maxevents, i
/* Check for error. */
if (!NT_SUCCESS(overlapped->Internal)) {
- struct wpoll_event* ev = events + (num_events++);
+ struct epoll_event* ev = events + (num_events++);
ev->data.u64 = sock_data->user_data;
- ev->events = WPOLLERR;
+ ev->events = EPOLLERR;
continue;
}
@@ -489,26 +489,26 @@ int wpoll_wait(wpoll_t port_handle, struct wpoll_event* events, int maxevents, i
/* Convert afd events to epoll events. */
if (afd_events & (AFD_POLL_RECEIVE | AFD_POLL_ACCEPT))
- reported_events |= (WPOLLIN | WPOLLRDNORM);
+ reported_events |= (EPOLLIN | EPOLLRDNORM);
if (afd_events & AFD_POLL_RECEIVE_EXPEDITED)
- reported_events |= (WPOLLIN | WPOLLRDBAND);
+ reported_events |= (EPOLLIN | EPOLLRDBAND);
if (afd_events & AFD_POLL_SEND)
- reported_events |= (WPOLLOUT | WPOLLWRNORM | WPOLLWRBAND);
+ reported_events |= (EPOLLOUT | EPOLLWRNORM | EPOLLWRBAND);
if ((afd_events & AFD_POLL_DISCONNECT) && !(afd_events & AFD_POLL_ABORT))
- reported_events |= (WPOLLRDHUP | WPOLLIN | WPOLLRDNORM | WPOLLRDBAND);
+ reported_events |= (EPOLLRDHUP | EPOLLIN | EPOLLRDNORM | EPOLLRDBAND);
if (afd_events & AFD_POLL_ABORT)
- reported_events |= WPOLLHUP | WPOLLERR;
+ reported_events |= EPOLLHUP | EPOLLERR;
if (afd_events & AFD_POLL_CONNECT)
- reported_events |= (WPOLLOUT | WPOLLWRNORM | WPOLLWRBAND);
+ reported_events |= (EPOLLOUT | EPOLLWRNORM | EPOLLWRBAND);
if (afd_events & AFD_POLL_CONNECT_FAIL)
- reported_events |= WPOLLERR;
+ reported_events |= EPOLLERR;
/* Don't report events that the user didn't specify. */
reported_events &= registered_events;
- /* Unless WPOLLONESHOT is used or no events were reported that the */
+ /* Unless EPOLLONESHOT is used or no events were reported that the */
/* user is interested in, add the socket back to the attention list. */
- if (!registered_events & WPOLLONESHOT || reported_events == 0) {
+ if (!registered_events & EPOLLONESHOT || reported_events == 0) {
assert(!sock_data->attn);
if (port_data->attn == NULL) {
sock_data->attn_next = sock_data->attn_prev = NULL;
@@ -522,7 +522,7 @@ int wpoll_wait(wpoll_t port_handle, struct wpoll_event* events, int maxevents, i
}
if (reported_events) {
- struct wpoll_event* ev = events + (num_events++);
+ struct epoll_event* ev = events + (num_events++);
ev->data.u64 = sock_data->user_data;
ev->events = reported_events;
}
@@ -541,12 +541,12 @@ int wpoll_wait(wpoll_t port_handle, struct wpoll_event* events, int maxevents, i
}
-int wpoll_close(wpoll_t port_handle) {
- wpoll_port_data_t* port_data;
- wpoll_sock_data_t* sock_data;
+int epoll_close(epoll_t port_handle) {
+ epoll_port_data_t* port_data;
+ epoll_sock_data_t* sock_data;
int i;
- port_data = (wpoll_port_data_t*) port_handle;
+ port_data = (epoll_port_data_t*) port_handle;
/* Close all peer sockets. This will make all pending ops return. */
for (i = 0; i < ARRAY_COUNT(port_data->peer_sockets); i++) {
@@ -559,7 +559,7 @@ int wpoll_close(wpoll_t port_handle) {
}
}
- /* There is no list of wpoll_ops the free. And even if there was, just */
+ /* There is no list of epoll_ops the free. And even if there was, just */
/* freeing them would be dangerous since the kernel might still alter */
/* the overlapped status contained in them. But since we are sure that */
/* all ops will soon return, just await them all. */
@@ -568,8 +568,6 @@ int wpoll_close(wpoll_t port_handle) {
DWORD result;
ULONG count, i;
- printf("ops: %d\n", port_data->pending_ops_count);
-
result = GetQueuedCompletionStatusEx(port_data->iocp,
entries,
ARRAY_COUNT(entries),
@@ -585,8 +583,8 @@ int wpoll_close(wpoll_t port_handle) {
port_data->pending_ops_count -= count;
for (i = 0; i < count; i++) {
- wpoll_op_t* op = CONTAINING_RECORD(entries[i].lpOverlapped,
- wpoll_op_t,
+ epoll_op_t* op = CONTAINING_RECORD(entries[i].lpOverlapped,
+ epoll_op_t,
overlapped);
free(op);
}
@@ -594,7 +592,7 @@ int wpoll_close(wpoll_t port_handle) {
/* Remove all entries from the socket_state tree. */
while (sock_data = RB_ROOT(&port_data->sock_data_tree)) {
- RB_REMOVE(wpoll_sock_data_tree, &port_data->sock_data_tree, sock_data);
+ RB_REMOVE(epoll_sock_data_tree, &port_data->sock_data_tree, sock_data);
if (sock_data->free_op != NULL)
free(sock_data->free_op);
diff --git a/src/msafd.h b/src/msafd.h
index 680df03..e15e16a 100644
--- a/src/msafd.h
+++ b/src/msafd.h
@@ -1,6 +1,6 @@
-#ifndef WPOLL_MSAFD_H_
-#define WPOLL_MSAFD_H_
+#ifndef EPOLL_MSAFD_H_
+#define EPOLL_MSAFD_H_
#include
#include "ntapi.h"
@@ -74,4 +74,4 @@ int afd_init();
int WSAAPI afd_poll(SOCKET socket, AFD_POLL_INFO* info,
OVERLAPPED* overlapped);
-#endif /* WPOLL_MSAFD_H_ */
\ No newline at end of file
+#endif /* EPOLL_MSAFD_H_ */
\ No newline at end of file
diff --git a/src/ntapi.h b/src/ntapi.h
index b59b414..45a6251 100644
--- a/src/ntapi.h
+++ b/src/ntapi.h
@@ -1,6 +1,6 @@
-#ifndef WPOLL_NTAPI_H_
-#define WPOLL_NTAPI_H_
+#ifndef EPOLL_NTAPI_H_
+#define EPOLL_NTAPI_H_
#include
@@ -4085,4 +4085,4 @@ typedef NTSTATUS (NTAPI *sNtDeviceIoControlFile)
PVOID OutputBuffer,
ULONG OutputBufferLength);
-#endif /* WPOLL_NTAPI_H_ */
+#endif /* EPOLL_NTAPI_H_ */
diff --git a/src/test.c b/src/test.c
index 3bc094c..64f2960 100644
--- a/src/test.c
+++ b/src/test.c
@@ -5,14 +5,14 @@
#include
#include
-#include
+#include
static const char PING[] = "PING";
static const int NUM_PINGERS = 10000;
static const int RUN_TIME = 10000;
int main(int argc, char* argv[]) {
- wpoll_t wpoll_hnd;
+ epoll_t epoll_hnd;
WSADATA wsa_data;
int r;
u_long one = 1;
@@ -28,8 +28,8 @@ int main(int argc, char* argv[]) {
afd_init();
- wpoll_hnd = wpoll_create();
- assert(wpoll_hnd);
+ epoll_hnd = epoll_create();
+ assert(epoll_hnd);
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_INET;
@@ -57,7 +57,7 @@ int main(int argc, char* argv[]) {
for (i = 0; i < NUM_PINGERS; i++) {
SOCKET sock;
- struct wpoll_event ev;
+ struct epoll_event ev;
sock = socket(AF_INET, SOCK_STREAM, 0);
@@ -69,24 +69,24 @@ int main(int argc, char* argv[]) {
/* is being established in the background. */
assert(r == 0 || WSAGetLastError() == WSAEWOULDBLOCK);
- ev.events = WPOLLOUT | WPOLLERR;
+ ev.events = EPOLLOUT | EPOLLERR;
ev.data.sock = sock;
- r = wpoll_ctl(wpoll_hnd, WPOLL_CTL_ADD, sock, &ev);
+ r = epoll_ctl(epoll_hnd, EPOLL_CTL_ADD, sock, &ev);
assert(r == 0);
}
{
SOCKET sock;
- struct wpoll_event ev;
+ struct epoll_event ev;
sock = socket(AF_INET, SOCK_STREAM, 0);
r = ioctlsocket(sock, FIONBIO, &one);
assert(r == 0);
- ev.events = WPOLLOUT | WPOLLERR;
+ ev.events = EPOLLOUT | EPOLLERR;
ev.data.sock = sock;
- r = wpoll_ctl(wpoll_hnd, WPOLL_CTL_ADD, sock, &ev);
+ r = epoll_ctl(epoll_hnd, EPOLL_CTL_ADD, sock, &ev);
assert(r == 0);
}
@@ -96,7 +96,7 @@ int main(int argc, char* argv[]) {
for (;;) {
int i, count;
- struct wpoll_event events[16];
+ struct epoll_event events[16];
DWORD ticks;
ticks = GetTickCount();
@@ -108,14 +108,14 @@ int main(int argc, char* argv[]) {
break;
}
- count = wpoll_wait(wpoll_hnd, events, 16, 1000);
+ count = epoll_wait(epoll_hnd, events, 16, 1000);
assert(count >= 0);
for (i = 0; i < count; i++) {
SOCKET sock = events[i].data.sock;
int revents = events[i].events;
- if (revents & WPOLLERR) {
+ if (revents & EPOLLERR) {
int r;
int err = -1;
int err_len = sizeof err;
@@ -124,16 +124,16 @@ int main(int argc, char* argv[]) {
assert(r == 0);
fprintf(stderr, "Socket error: %d\n", err);
- r = wpoll_ctl(wpoll_hnd, WPOLL_CTL_DEL, sock, NULL);
+ r = epoll_ctl(epoll_hnd, EPOLL_CTL_DEL, sock, NULL);
assert(r == 0);
continue;
}
- if (revents & WPOLLIN) {
+ if (revents & EPOLLIN) {
char buf[1024];
WSABUF wsa_buf;
DWORD flags, bytes;
- struct wpoll_event ev;
+ struct epoll_event ev;
int r;
wsa_buf.buf = buf;
@@ -146,11 +146,11 @@ int main(int argc, char* argv[]) {
assert(bytes == sizeof PING);
ev.data.sock = sock;
- ev.events = WPOLLOUT;
+ ev.events = EPOLLOUT;
- r = wpoll_ctl(wpoll_hnd, WPOLL_CTL_DEL, sock, &ev);
- assert(r == 0);
- r = wpoll_ctl(wpoll_hnd, WPOLL_CTL_ADD, sock, &ev);
+ //r = epoll_ctl(epoll_hnd, EPOLL_CTL_DEL, sock, &ev);
+ //assert(r == 0);
+ r = epoll_ctl(epoll_hnd, EPOLL_CTL_MOD, sock, &ev);
assert(r == 0);
pings++;
@@ -158,11 +158,11 @@ int main(int argc, char* argv[]) {
continue;
}
- if (revents & WPOLLOUT) {
+ if (revents & EPOLLOUT) {
WSABUF wsa_buf;
DWORD bytes;
int r;
- struct wpoll_event ev;
+ struct epoll_event ev;
wsa_buf.buf = PING;
wsa_buf.len = sizeof PING;
@@ -171,9 +171,9 @@ int main(int argc, char* argv[]) {
assert(bytes == sizeof PING);
ev.data.sock = sock;
- ev.events = WPOLLIN;
+ ev.events = EPOLLIN;
- r = wpoll_ctl(wpoll_hnd, WPOLL_CTL_MOD, sock, &ev);
+ r = epoll_ctl(epoll_hnd, EPOLL_CTL_MOD, sock, &ev);
assert(r == 0);
pings_sent++;
@@ -185,7 +185,7 @@ int main(int argc, char* argv[]) {
}
}
- r = wpoll_close(wpoll_hnd);
+ r = epoll_close(epoll_hnd);
assert(r == 0);
}
diff --git a/src/tree.h b/src/tree.h
index ee7bcf9..4d7ea1b 100644
--- a/src/tree.h
+++ b/src/tree.h
@@ -50,8 +50,8 @@
* The maximum height of a red-black tree is 2lg (n+1).
*/
-#ifndef WPOLL_TREE_H_
-#define WPOLL_TREE_H_
+#ifndef EPOLL_TREE_H_
+#define EPOLL_TREE_H_
#define SPLAY_HEAD(name, type) \
struct name { \
@@ -757,4 +757,4 @@ name##_RB_MINMAX(struct name *head, int val) \
((x) != NULL) && ((y) = name##_RB_PREV(x), (x) != NULL); \
(x) = (y))
-#endif /* WPOLL_TREE_H_ */
+#endif /* EPOLL_TREE_H_ */
diff --git a/test.vcxproj b/test.vcxproj
index ef7426b..3e8aaf9 100644
--- a/test.vcxproj
+++ b/test.vcxproj
@@ -1,126 +1 @@
-
-
-
-
- Debug
- Win32
-
-
- Release
- Win32
-
-
-
- {58F32AFA-FCBB-2A4D-DCB4-242324A2FAC4}
- Win32Proj
- test
-
-
-
- Application
-
-
-
-
-
-
-
-
- $(ExecutablePath);$(MSBuildProjectDirectory)\.\bin\;$(MSBuildProjectDirectory)\.\bin\
- $(Configuration)\obj\$(ProjectName)\
- false
- true
- $(SolutionDir)$(Configuration)\
- $(ProjectName)
- $(OutDir)\$(ProjectName).exe
-
-
-
- include;src;%(AdditionalIncludeDirectories)
- /MP %(AdditionalOptions)
- EnableFastChecks
- true
- ProgramDatabase
- false
- false
- false
- Disabled
- WIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;DEBUG;_DEBUG;%(PreprocessorDefinitions)
- MultiThreadedDebug
- true
- true
- false
- Level3
-
-
- ws2_32.lib;%(AdditionalDependencies)
- true
- true
- true
- $(OutDir)$(ProjectName).exe
- true
- Console
- true
-
-
- include;src;%(AdditionalIncludeDirectories)
- WIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;DEBUG;_DEBUG;%(PreprocessorDefinitions);%(PreprocessorDefinitions)
-
-
-
-
- include;src;%(AdditionalIncludeDirectories)
- /MP %(AdditionalOptions)
- true
- ProgramDatabase
- Sync
- Speed
- true
- AnySuitable
- true
- true
- Full
- WIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;NDEBUG;%(PreprocessorDefinitions)
- MultiThreaded
- true
- true
- false
- Level3
- true
-
-
- /LTCG %(AdditionalOptions)
-
-
- ws2_32.lib;%(AdditionalDependencies)
- true
- true
- true
- true
- UseLinkTimeCodeGeneration
- true
- $(OutDir)$(ProjectName).exe
- true
- Console
- true
-
-
- include;src;%(AdditionalIncludeDirectories)
- WIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;NDEBUG;%(PreprocessorDefinitions);%(PreprocessorDefinitions)
-
-
-
-
-
-
-
-
-
-
- {9221E672-D419-F7D7-9259-A7D2BE1D177A}
- false
-
-
-
-
-
\ No newline at end of file
+DebugWin32ReleaseWin32{58F32AFA-FCBB-2A4D-DCB4-242324A2FAC4}Win32ProjtestApplication$(ExecutablePath);$(MSBuildProjectDirectory)\.\bin\;$(MSBuildProjectDirectory)\.\bin\$(Configuration)\obj\$(ProjectName)\falsetrue$(SolutionDir)$(Configuration)\$(ProjectName)$(OutDir)\$(ProjectName).exeinclude;src;%(AdditionalIncludeDirectories)/MP %(AdditionalOptions)EnableFastCheckstrueProgramDatabaseSyncfalsefalseDisabledWIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;DEBUG;_DEBUG;%(PreprocessorDefinitions)MultiThreadedDebugtruetruefalseLevel3ws2_32.lib;%(AdditionalDependencies)truetruetrue$(OutDir)$(ProjectName).exetrueConsoletrueinclude;src;%(AdditionalIncludeDirectories)WIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;DEBUG;_DEBUG;%(PreprocessorDefinitions);%(PreprocessorDefinitions)include;src;%(AdditionalIncludeDirectories)/MP %(AdditionalOptions)trueProgramDatabaseSyncSpeedtrueAnySuitabletruetrueFullWIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;NDEBUG;%(PreprocessorDefinitions)MultiThreadedtruetruefalseLevel3true/LTCG %(AdditionalOptions)ws2_32.lib;%(AdditionalDependencies)truetruetruetrueUseLinkTimeCodeGenerationtrue$(OutDir)$(ProjectName).exetrueConsoletrueinclude;src;%(AdditionalIncludeDirectories)WIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;NDEBUG;%(PreprocessorDefinitions);%(PreprocessorDefinitions){2CF47921-4CCE-ADEA-4A82-BC6521983261}false
\ No newline at end of file
diff --git a/wpoll.vcxproj b/wpoll.vcxproj
deleted file mode 100644
index 618df75..0000000
--- a/wpoll.vcxproj
+++ /dev/null
@@ -1,129 +0,0 @@
-
-
-
-
- Debug
- Win32
-
-
- Release
- Win32
-
-
-
- {9221E672-D419-F7D7-9259-A7D2BE1D177A}
- Win32Proj
- wpoll
-
-
-
- StaticLibrary
-
-
-
-
-
-
-
-
- $(ExecutablePath);$(MSBuildProjectDirectory)\.\bin\;$(MSBuildProjectDirectory)\.\bin\
- $(Configuration)\obj\$(ProjectName)\
- false
- true
- $(SolutionDir)$(Configuration)\
- $(ProjectName)
- $(OutDir)\lib\$(ProjectName).lib
-
-
-
- include;src;%(AdditionalIncludeDirectories)
- /MP %(AdditionalOptions)
- EnableFastChecks
- true
- ProgramDatabase
- false
- false
- false
- Disabled
- WIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;DEBUG;_DEBUG;%(PreprocessorDefinitions)
- MultiThreadedDebug
- true
- true
- false
- Level3
-
-
- $(OutDir)lib\$(ProjectName).lib
-
-
- ws2_32.lib;%(AdditionalDependencies)
- true
- true
- true
- true
- true
-
-
- include;src;%(AdditionalIncludeDirectories)
- WIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;DEBUG;_DEBUG;%(PreprocessorDefinitions);%(PreprocessorDefinitions)
-
-
-
-
- include;src;%(AdditionalIncludeDirectories)
- /MP %(AdditionalOptions)
- true
- ProgramDatabase
- Sync
- Speed
- true
- AnySuitable
- true
- true
- Full
- WIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;NDEBUG;%(PreprocessorDefinitions)
- MultiThreaded
- true
- true
- false
- Level3
- true
-
-
- /LTCG %(AdditionalOptions)
- $(OutDir)lib\$(ProjectName).lib
-
-
- ws2_32.lib;%(AdditionalDependencies)
- true
- true
- true
- true
- UseLinkTimeCodeGeneration
- true
- true
- true
-
-
- include;src;%(AdditionalIncludeDirectories)
- WIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;NDEBUG;%(PreprocessorDefinitions);%(PreprocessorDefinitions)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file