Skip to content

Commit

Permalink
port: do not use separate poll groups for different socket types
Browse files Browse the repository at this point in the history
It appears that this was never necessary after all.
  • Loading branch information
piscisaureus committed Mar 9, 2018
1 parent 075e1ce commit e7e8385
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 54 deletions.
34 changes: 14 additions & 20 deletions src/afd.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,9 @@ static SOCKET _afd_get_base_socket(SOCKET socket) {
return base_socket;
}

static ssize_t _afd_get_protocol_info(SOCKET socket,
WSAPROTOCOL_INFOW* protocol_info) {
static int _afd_get_protocol_info(SOCKET socket,
WSAPROTOCOL_INFOW* protocol_info) {
int opt_len;
ssize_t id;
size_t i;

opt_len = sizeof *protocol_info;
Expand All @@ -119,36 +118,31 @@ static ssize_t _afd_get_protocol_info(SOCKET socket,
&opt_len) != 0)
return_error(-1);

id = -1;
for (i = 0; i < array_count(AFD_PROVIDER_GUID_LIST); i++) {
if (memcmp(&protocol_info->ProviderId,
&AFD_PROVIDER_GUID_LIST[i],
sizeof protocol_info->ProviderId) == 0) {
id = i;
break;
return 0;
}
}

/* Check if the protocol uses an msafd socket. */
if (id < 0)
return_error(-1, ERROR_DEVICE_FEATURE_NOT_SUPPORTED);

return id;
/* Socket doesn't appear to be controlled by MSAFD. */
return_error(-1, ERROR_DEVICE_FEATURE_NOT_SUPPORTED);
}

WEPOLL_INTERNAL ssize_t afd_get_protocol(SOCKET socket,
SOCKET* afd_socket_out,
WSAPROTOCOL_INFOW* protocol_info) {
ssize_t id;
WEPOLL_INTERNAL int afd_get_protocol_info(SOCKET socket,
SOCKET* afd_socket_out,
WSAPROTOCOL_INFOW* protocol_info) {
SOCKET afd_socket;
int r;

/* Try to get protocol information, assuming that the given socket is an AFD
* socket. This should almost always be the case, and if it is, that saves us
* a call to WSAIoctl(). */
afd_socket = socket;
id = _afd_get_protocol_info(afd_socket, protocol_info);
r = _afd_get_protocol_info(afd_socket, protocol_info);

if (id < 0) {
if (r < 0) {
/* If getting protocol information failed, it might be due to the socket
* not being an AFD socket. If so, attempt to fetch the underlying base
* socket, then try again to obtain protocol information. */
Expand All @@ -160,11 +154,11 @@ WEPOLL_INTERNAL ssize_t afd_get_protocol(SOCKET socket,
if (afd_socket == INVALID_SOCKET || afd_socket == socket)
return_error(-1, error);

id = _afd_get_protocol_info(afd_socket, protocol_info);
if (id < 0)
r = _afd_get_protocol_info(afd_socket, protocol_info);
if (r < 0)
return -1;
}

*afd_socket_out = afd_socket;
return id;
return r;
}
6 changes: 3 additions & 3 deletions src/afd.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ WEPOLL_INTERNAL int afd_poll(SOCKET driver_socket,
AFD_POLL_INFO* poll_info,
OVERLAPPED* overlapped);

WEPOLL_INTERNAL ssize_t afd_get_protocol(SOCKET socket,
SOCKET* afd_socket_out,
WSAPROTOCOL_INFOW* protocol_info);
WEPOLL_INTERNAL int afd_get_protocol_info(SOCKET socket,
SOCKET* afd_socket_out,
WSAPROTOCOL_INFOW* protocol_info);

/* clang-format off */

Expand Down
31 changes: 10 additions & 21 deletions src/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ int ep_port_close(ep_port_t* port_info) {
int ep_port_delete(ep_port_t* port_info) {
tree_node_t* tree_node;
queue_node_t* queue_node;
size_t i;

/* At this point the IOCP port should have been closed. */
assert(port_info->iocp == NULL);
Expand All @@ -103,11 +102,8 @@ int ep_port_delete(ep_port_t* port_info) {
ep_sock_force_delete(port_info, sock_info);
}

for (i = 0; i < array_count(port_info->poll_group_allocators); i++) {
poll_group_allocator_t* pga = port_info->poll_group_allocators[i];
if (pga != NULL)
poll_group_allocator_delete(pga);
}
if (port_info->poll_group_allocator != NULL)
poll_group_allocator_delete(port_info->poll_group_allocator);

DeleteCriticalSection(&port_info->lock);

Expand Down Expand Up @@ -357,26 +353,19 @@ ep_sock_t* ep_port_find_socket(ep_port_t* port_info, SOCKET socket) {
}

static poll_group_allocator_t* _ep_port_get_poll_group_allocator(
ep_port_t* port_info,
size_t protocol_id,
const WSAPROTOCOL_INFOW* protocol_info) {
poll_group_allocator_t** pga;

assert(protocol_id < array_count(port_info->poll_group_allocators));

pga = &port_info->poll_group_allocators[protocol_id];
if (*pga == NULL)
*pga = poll_group_allocator_new(port_info, protocol_info);
ep_port_t* port_info, const WSAPROTOCOL_INFOW* protocol_info) {
if (port_info->poll_group_allocator == NULL) {
port_info->poll_group_allocator =
poll_group_allocator_new(port_info, protocol_info);
}

return *pga;
return port_info->poll_group_allocator;
}

poll_group_t* ep_port_acquire_poll_group(
ep_port_t* port_info,
size_t protocol_id,
const WSAPROTOCOL_INFOW* protocol_info) {
ep_port_t* port_info, const WSAPROTOCOL_INFOW* protocol_info) {
poll_group_allocator_t* pga =
_ep_port_get_poll_group_allocator(port_info, protocol_id, protocol_info);
_ep_port_get_poll_group_allocator(port_info, protocol_info);
return poll_group_acquire(pga);
}

Expand Down
7 changes: 2 additions & 5 deletions src/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ typedef struct ep_sock ep_sock_t;

typedef struct ep_port {
HANDLE iocp;
poll_group_allocator_t*
poll_group_allocators[array_count(AFD_PROVIDER_GUID_LIST)];
poll_group_allocator_t* poll_group_allocator;
tree_t sock_tree;
queue_t sock_update_queue;
queue_t sock_deleted_queue;
Expand All @@ -41,9 +40,7 @@ WEPOLL_INTERNAL int ep_port_ctl(ep_port_t* port_info,
struct epoll_event* ev);

WEPOLL_INTERNAL poll_group_t* ep_port_acquire_poll_group(
ep_port_t* port_info,
size_t protocol_id,
const WSAPROTOCOL_INFOW* protocol_info);
ep_port_t* port_info, const WSAPROTOCOL_INFOW* protocol_info);
WEPOLL_INTERNAL void ep_port_release_poll_group(ep_port_t* port_info,
poll_group_t* poll_group);

Expand Down
7 changes: 2 additions & 5 deletions src/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,20 +173,17 @@ static int _ep_sock_cancel_poll(_ep_sock_private_t* sock_private) {

ep_sock_t* ep_sock_new(ep_port_t* port_info, SOCKET socket) {
SOCKET afd_socket;
ssize_t protocol_id;
WSAPROTOCOL_INFOW protocol_info;
poll_group_t* poll_group;
_ep_sock_private_t* sock_private;

if (socket == 0 || socket == INVALID_SOCKET)
return_error(NULL, ERROR_INVALID_HANDLE);

protocol_id = afd_get_protocol(socket, &afd_socket, &protocol_info);
if (protocol_id < 0)
if (afd_get_protocol_info(socket, &afd_socket, &protocol_info) < 0)
return NULL;

poll_group =
ep_port_acquire_poll_group(port_info, protocol_id, &protocol_info);
poll_group = ep_port_acquire_poll_group(port_info, &protocol_info);
if (poll_group == NULL)
return NULL;

Expand Down

0 comments on commit e7e8385

Please sign in to comment.