port: move IOCP port creation to ep_port_new()
This commit is contained in:
parent
a6c2c49071
commit
729fa3c733
16
src/epoll.c
16
src/epoll.c
@ -24,29 +24,23 @@ int epoll_global_init(void) {
|
||||
|
||||
HANDLE epoll_create(void) {
|
||||
ep_port_t* port_info;
|
||||
HANDLE iocp;
|
||||
HANDLE ephnd;
|
||||
|
||||
if (init() < 0)
|
||||
return NULL;
|
||||
|
||||
iocp = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 0);
|
||||
if (iocp == INVALID_HANDLE_VALUE)
|
||||
return_error(NULL);
|
||||
|
||||
port_info = ep_port_new(iocp);
|
||||
if (port_info == NULL) {
|
||||
CloseHandle(iocp);
|
||||
port_info = ep_port_new(&ephnd);
|
||||
if (port_info == NULL)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (reflock_tree_add(&_epoll_handle_tree,
|
||||
&port_info->handle_tree_node,
|
||||
(uintptr_t) iocp) < 0) {
|
||||
(uintptr_t) ephnd) < 0) {
|
||||
ep_port_delete(port_info);
|
||||
return_error(INVALID_HANDLE_VALUE, ERROR_ALREADY_EXISTS);
|
||||
}
|
||||
|
||||
return iocp;
|
||||
return ephnd;
|
||||
}
|
||||
|
||||
int epoll_close(HANDLE ephnd) {
|
||||
|
||||
15
src/port.c
15
src/port.c
@ -27,12 +27,17 @@ static void _ep_port_free(ep_port_t* port) {
|
||||
free(port);
|
||||
}
|
||||
|
||||
ep_port_t* ep_port_new(HANDLE iocp) {
|
||||
ep_port_t* ep_port_new(HANDLE* iocp_out) {
|
||||
ep_port_t* port_info;
|
||||
HANDLE iocp;
|
||||
|
||||
port_info = _ep_port_alloc();
|
||||
if (port_info == NULL)
|
||||
return NULL;
|
||||
goto err1;
|
||||
|
||||
iocp = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 0);
|
||||
if (iocp == INVALID_HANDLE_VALUE)
|
||||
goto err2;
|
||||
|
||||
memset(port_info, 0, sizeof *port_info);
|
||||
|
||||
@ -42,7 +47,13 @@ ep_port_t* ep_port_new(HANDLE iocp) {
|
||||
reflock_tree_node_init(&port_info->handle_tree_node);
|
||||
InitializeCriticalSection(&port_info->lock);
|
||||
|
||||
*iocp_out = iocp;
|
||||
return port_info;
|
||||
|
||||
err2:
|
||||
_ep_port_free(port_info);
|
||||
err1:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int _ep_port_close_iocp(ep_port_t* port_info) {
|
||||
|
||||
@ -26,7 +26,7 @@ typedef struct ep_port {
|
||||
CRITICAL_SECTION lock;
|
||||
} ep_port_t;
|
||||
|
||||
EPOLL_INTERNAL ep_port_t* ep_port_new(HANDLE iocp);
|
||||
EPOLL_INTERNAL ep_port_t* ep_port_new(HANDLE* iocp_out);
|
||||
EPOLL_INTERNAL int ep_port_close(ep_port_t* port_info);
|
||||
EPOLL_INTERNAL int ep_port_delete(ep_port_t* port_info);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user