s/wpoll/epoll/g

This commit is contained in:
Bert Belder 2012-09-06 02:36:03 +02:00
parent a1aa2c7d80
commit 4c2fb9914a
13 changed files with 195 additions and 450 deletions

View File

@ -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' ],

View File

@ -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

1
epoll.vcxproj Normal file

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
python \gyp\gyp -Dlibrary=static_library -Icommon.gypi wpoll.gyp --depth=.
python \gyp\gyp -Dlibrary=static_library -Icommon.gypi epoll.gyp --depth=.

61
include/epoll.h Normal file
View File

@ -0,0 +1,61 @@
#ifndef EPOLL_H_
#define EPOLL_H_
#include <WinSock2.h>
#include <Windows.h>
#include <stdint.h>
#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_ */

View File

@ -1,61 +0,0 @@
#ifndef WPOLL_H_
#define WPOLL_H_
#include <WinSock2.h>
#include <Windows.h>
#include <stdint.h>
#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_ */

View File

@ -2,30 +2,30 @@
#include <stdio.h>
#include <assert.h>
#include <wpoll.h>
#include <epoll.h>
#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);

View File

@ -1,6 +1,6 @@
#ifndef WPOLL_MSAFD_H_
#define WPOLL_MSAFD_H_
#ifndef EPOLL_MSAFD_H_
#define EPOLL_MSAFD_H_
#include <windows.h>
#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_ */
#endif /* EPOLL_MSAFD_H_ */

View File

@ -1,6 +1,6 @@
#ifndef WPOLL_NTAPI_H_
#define WPOLL_NTAPI_H_
#ifndef EPOLL_NTAPI_H_
#define EPOLL_NTAPI_H_
#include <windows.h>
@ -4085,4 +4085,4 @@ typedef NTSTATUS (NTAPI *sNtDeviceIoControlFile)
PVOID OutputBuffer,
ULONG OutputBufferLength);
#endif /* WPOLL_NTAPI_H_ */
#endif /* EPOLL_NTAPI_H_ */

View File

@ -5,14 +5,14 @@
#include <assert.h>
#include <stdio.h>
#include <wpoll.h>
#include <epoll.h>
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);
}

View File

@ -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_ */

File diff suppressed because one or more lines are too long

View File

@ -1,129 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{9221E672-D419-F7D7-9259-A7D2BE1D177A}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>wpoll</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings" />
<ImportGroup Label="PropertySheets">
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<ExecutablePath>$(ExecutablePath);$(MSBuildProjectDirectory)\.\bin\;$(MSBuildProjectDirectory)\.\bin\</ExecutablePath>
<IntDir>$(Configuration)\obj\$(ProjectName)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
<TargetName>$(ProjectName)</TargetName>
<TargetPath>$(OutDir)\lib\$(ProjectName).lib</TargetPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>include;src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions>/MP %(AdditionalOptions)</AdditionalOptions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<BufferSecurityCheck>true</BufferSecurityCheck>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<ExceptionHandling>false</ExceptionHandling>
<MinimalRebuild>false</MinimalRebuild>
<OmitFramePointers>false</OmitFramePointers>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;DEBUG;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<StringPooling>true</StringPooling>
<SuppressStartupBanner>true</SuppressStartupBanner>
<TreatWarningAsError>false</TreatWarningAsError>
<WarningLevel>Level3</WarningLevel>
</ClCompile>
<Lib>
<OutputFile>$(OutDir)lib\$(ProjectName).lib</OutputFile>
</Lib>
<Link>
<AdditionalDependencies>ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AllowIsolation>true</AllowIsolation>
<DataExecutionPrevention>true</DataExecutionPrevention>
<GenerateDebugInformation>true</GenerateDebugInformation>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<SuppressStartupBanner>true</SuppressStartupBanner>
</Link>
<ResourceCompile>
<AdditionalIncludeDirectories>include;src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;DEBUG;_DEBUG;%(PreprocessorDefinitions);%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>include;src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions>/MP %(AdditionalOptions)</AdditionalOptions>
<BufferSecurityCheck>true</BufferSecurityCheck>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<ExceptionHandling>Sync</ExceptionHandling>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<FunctionLevelLinking>true</FunctionLevelLinking>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<IntrinsicFunctions>true</IntrinsicFunctions>
<OmitFramePointers>true</OmitFramePointers>
<Optimization>Full</Optimization>
<PreprocessorDefinitions>WIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<StringPooling>true</StringPooling>
<SuppressStartupBanner>true</SuppressStartupBanner>
<TreatWarningAsError>false</TreatWarningAsError>
<WarningLevel>Level3</WarningLevel>
<WholeProgramOptimization>true</WholeProgramOptimization>
</ClCompile>
<Lib>
<AdditionalOptions>/LTCG %(AdditionalOptions)</AdditionalOptions>
<OutputFile>$(OutDir)lib\$(ProjectName).lib</OutputFile>
</Lib>
<Link>
<AdditionalDependencies>ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AllowIsolation>true</AllowIsolation>
<DataExecutionPrevention>true</DataExecutionPrevention>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<GenerateDebugInformation>true</GenerateDebugInformation>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
<OptimizeReferences>true</OptimizeReferences>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
<SuppressStartupBanner>true</SuppressStartupBanner>
</Link>
<ResourceCompile>
<AdditionalIncludeDirectories>include;src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;NDEBUG;%(PreprocessorDefinitions);%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemGroup>
<None Include="wpoll.gyp" />
<None Include="common.gypi" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\msafd.h" />
<ClInclude Include="src\ntapi.h" />
<ClInclude Include="src\tree.h" />
<ClInclude Include="include\wpoll.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\wpoll.c" />
<ClCompile Include="src\ntapi.c" />
<ClCompile Include="src\msafd.c" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets" />
</Project>