sock: do not retrieve winsock protocol info for every socket

This commit is contained in:
Bert Belder 2018-05-02 02:24:19 +02:00
parent a54e813d2f
commit 607ed77216
No known key found for this signature in database
GPG Key ID: 7A77887B2E2ED461
3 changed files with 3 additions and 64 deletions

View File

@ -199,61 +199,3 @@ int afd_poll(SOCKET driver_socket,
else
return_error(-1, RtlNtStatusToDosError(status));
}
static int _afd_get_protocol_info(SOCKET socket,
WSAPROTOCOL_INFOW* protocol_info) {
int opt_len;
size_t i;
opt_len = sizeof *protocol_info;
if (getsockopt(socket,
SOL_SOCKET,
SO_PROTOCOL_INFOW,
(char*) protocol_info,
&opt_len) != 0)
return_error(-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) {
return 0;
}
}
/* Socket doesn't appear to be controlled by MSAFD. */
return_error(-1, ERROR_DEVICE_FEATURE_NOT_SUPPORTED);
}
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;
r = _afd_get_protocol_info(afd_socket, protocol_info);
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. */
DWORD error = GetLastError();
if (error != ERROR_DEVICE_FEATURE_NOT_SUPPORTED)
return -1;
afd_socket = ws_get_base_socket(socket);
if (afd_socket == INVALID_SOCKET || afd_socket == socket)
return_error(-1, error);
r = _afd_get_protocol_info(afd_socket, protocol_info);
if (r < 0)
return -1;
}
*afd_socket_out = afd_socket;
return r;
}

View File

@ -61,8 +61,4 @@ WEPOLL_INTERNAL int afd_poll(SOCKET driver_socket,
AFD_POLL_INFO* poll_info,
OVERLAPPED* overlapped);
WEPOLL_INTERNAL int afd_get_protocol_info(SOCKET socket,
SOCKET* afd_socket_out,
WSAPROTOCOL_INFOW* protocol_info);
#endif /* WEPOLL_AFD_H_ */

View File

@ -8,6 +8,7 @@
#include "poll-group.h"
#include "port.h"
#include "sock.h"
#include "ws.h"
#define _KNOWN_EPOLL_EVENTS \
(EPOLLIN | EPOLLPRI | EPOLLOUT | EPOLLERR | EPOLLHUP | EPOLLRDNORM | \
@ -172,14 +173,14 @@ 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;
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);
if (afd_get_protocol_info(socket, &afd_socket, &protocol_info) < 0)
afd_socket = ws_get_base_socket(socket);
if (afd_socket == INVALID_SOCKET)
return NULL;
poll_group = ep_port_acquire_poll_group(port_info);