ws2_32: Signal overlapped completion in WSAIoctl.

This commit is contained in:
Alexandre Julliard 2011-04-19 12:26:50 +02:00
parent 7e208f4896
commit de0b4a67d8

View File

@ -3069,6 +3069,7 @@ INT WINAPI WSAIoctl(SOCKET s, DWORD code, LPVOID in_buff, DWORD in_size, LPVOID
LPWSAOVERLAPPED_COMPLETION_ROUTINE completion ) LPWSAOVERLAPPED_COMPLETION_ROUTINE completion )
{ {
int fd; int fd;
DWORD status = 0, total = 0;
TRACE("%ld, 0x%08x, %p, %d, %p, %d, %p, %p, %p\n", TRACE("%ld, 0x%08x, %p, %d, %p, %d, %p, %p, %p\n",
s, code, in_buff, in_size, out_buff, out_size, ret_size, overlapped, completion); s, code, in_buff, in_size, out_buff, out_size, ret_size, overlapped, completion);
@ -3084,15 +3085,14 @@ INT WINAPI WSAIoctl(SOCKET s, DWORD code, LPVOID in_buff, DWORD in_size, LPVOID
if (_get_sock_mask(s)) if (_get_sock_mask(s))
{ {
/* AsyncSelect()'ed sockets are always nonblocking */ /* AsyncSelect()'ed sockets are always nonblocking */
if (*(WS_u_long *)in_buff) return 0; if (!*(WS_u_long *)in_buff) status = WSAEINVAL;
SetLastError(WSAEINVAL); break;
return SOCKET_ERROR;
} }
if (*(WS_u_long *)in_buff) if (*(WS_u_long *)in_buff)
_enable_event(SOCKET2HANDLE(s), 0, FD_WINE_NONBLOCKING, 0); _enable_event(SOCKET2HANDLE(s), 0, FD_WINE_NONBLOCKING, 0);
else else
_enable_event(SOCKET2HANDLE(s), 0, 0, FD_WINE_NONBLOCKING); _enable_event(SOCKET2HANDLE(s), 0, 0, FD_WINE_NONBLOCKING);
return 0; break;
case WS_FIONREAD: case WS_FIONREAD:
case WS_SIOCATMARK: case WS_SIOCATMARK:
@ -3105,14 +3105,9 @@ INT WINAPI WSAIoctl(SOCKET s, DWORD code, LPVOID in_buff, DWORD in_size, LPVOID
} }
if ((fd = get_sock_fd( s, 0, NULL )) == -1) return SOCKET_ERROR; if ((fd = get_sock_fd( s, 0, NULL )) == -1) return SOCKET_ERROR;
if (ioctl(fd, cmd, out_buff ) == -1) if (ioctl(fd, cmd, out_buff ) == -1)
{ status = (errno == EBADF) ? WSAENOTSOCK : wsaErrno();
SetLastError((errno == EBADF) ? WSAENOTSOCK : wsaErrno());
release_sock_fd( s, fd );
return SOCKET_ERROR;
}
release_sock_fd( s, fd ); release_sock_fd( s, fd );
if (ret_size) *ret_size = sizeof(WS_u_long); break;
return 0;
} }
case WS_FIOASYNC: case WS_FIOASYNC:
@ -3123,16 +3118,11 @@ INT WINAPI WSAIoctl(SOCKET s, DWORD code, LPVOID in_buff, DWORD in_size, LPVOID
case WS_SIO_GET_INTERFACE_LIST: case WS_SIO_GET_INTERFACE_LIST:
{ {
INTERFACE_INFO* intArray = out_buff; INTERFACE_INFO* intArray = out_buff;
DWORD size, numInt, apiReturn; DWORD size, numInt = 0, apiReturn;
TRACE("-> SIO_GET_INTERFACE_LIST request\n"); TRACE("-> SIO_GET_INTERFACE_LIST request\n");
if (!out_buff) if (!out_buff || !ret_size)
{
WSASetLastError(WSAEFAULT);
return SOCKET_ERROR;
}
if (!ret_size)
{ {
WSASetLastError(WSAEFAULT); WSASetLastError(WSAEFAULT);
return SOCKET_ERROR; return SOCKET_ERROR;
@ -3142,11 +3132,7 @@ INT WINAPI WSAIoctl(SOCKET s, DWORD code, LPVOID in_buff, DWORD in_size, LPVOID
if (fd == -1) return SOCKET_ERROR; if (fd == -1) return SOCKET_ERROR;
apiReturn = GetAdaptersInfo(NULL, &size); apiReturn = GetAdaptersInfo(NULL, &size);
if (apiReturn == ERROR_NO_DATA) if (apiReturn == ERROR_BUFFER_OVERFLOW)
{
numInt = 0;
}
else if (apiReturn == ERROR_BUFFER_OVERFLOW)
{ {
PIP_ADAPTER_INFO table = HeapAlloc(GetProcessHeap(),0,size); PIP_ADAPTER_INFO table = HeapAlloc(GetProcessHeap(),0,size);
@ -3161,8 +3147,8 @@ INT WINAPI WSAIoctl(SOCKET s, DWORD code, LPVOID in_buff, DWORD in_size, LPVOID
WARN("Buffer too small = %u, out_size = %u\n", size, out_size); WARN("Buffer too small = %u, out_size = %u\n", size, out_size);
HeapFree(GetProcessHeap(),0,table); HeapFree(GetProcessHeap(),0,table);
release_sock_fd( s, fd ); release_sock_fd( s, fd );
WSASetLastError(WSAEFAULT); status = WSAEFAULT;
return SOCKET_ERROR; break;
} }
for (ptr = table, numInt = 0; ptr; for (ptr = table, numInt = 0; ptr;
ptr = ptr->Next, intArray++, numInt++) ptr = ptr->Next, intArray++, numInt++)
@ -3177,8 +3163,8 @@ INT WINAPI WSAIoctl(SOCKET s, DWORD code, LPVOID in_buff, DWORD in_size, LPVOID
ERR("Error obtaining status flags for socket!\n"); ERR("Error obtaining status flags for socket!\n");
HeapFree(GetProcessHeap(),0,table); HeapFree(GetProcessHeap(),0,table);
release_sock_fd( s, fd ); release_sock_fd( s, fd );
WSASetLastError(WSAEINVAL); status = WSAEINVAL;
return SOCKET_ERROR; break;
} }
else else
{ {
@ -3221,29 +3207,19 @@ INT WINAPI WSAIoctl(SOCKET s, DWORD code, LPVOID in_buff, DWORD in_size, LPVOID
else else
{ {
ERR("Unable to get interface table!\n"); ERR("Unable to get interface table!\n");
release_sock_fd( s, fd ); status = WSAEINVAL;
HeapFree(GetProcessHeap(),0,table);
WSASetLastError(WSAEINVAL);
return SOCKET_ERROR;
} }
HeapFree(GetProcessHeap(),0,table); HeapFree(GetProcessHeap(),0,table);
} }
else else status = WSAEINVAL;
{
release_sock_fd( s, fd );
WSASetLastError(WSAEINVAL);
return SOCKET_ERROR;
}
} }
else else if (apiReturn != ERROR_NO_DATA)
{ {
ERR("Unable to get interface table!\n"); ERR("Unable to get interface table!\n");
release_sock_fd( s, fd ); status = WSAEINVAL;
WSASetLastError(WSAEINVAL);
return SOCKET_ERROR;
} }
/* Calculate the size of the array being returned */ /* Calculate the size of the array being returned */
*ret_size = sizeof(INTERFACE_INFO) * numInt; total = sizeof(INTERFACE_INFO) * numInt;
release_sock_fd( s, fd ); release_sock_fd( s, fd );
break; break;
} }
@ -3269,27 +3245,26 @@ INT WINAPI WSAIoctl(SOCKET s, DWORD code, LPVOID in_buff, DWORD in_size, LPVOID
if (GetAdaptersInfo(NULL, &size) == ERROR_BUFFER_OVERFLOW) if (GetAdaptersInfo(NULL, &size) == ERROR_BUFFER_OVERFLOW)
{ {
IP_ADAPTER_INFO *p, *table = HeapAlloc(GetProcessHeap(), 0, size); IP_ADAPTER_INFO *p, *table = HeapAlloc(GetProcessHeap(), 0, size);
DWORD need, num; DWORD num;
if (!table || GetAdaptersInfo(table, &size)) if (!table || GetAdaptersInfo(table, &size))
{ {
HeapFree(GetProcessHeap(), 0, table); HeapFree(GetProcessHeap(), 0, table);
WSASetLastError(WSAEINVAL); status = WSAEINVAL;
return SOCKET_ERROR; break;
} }
for (p = table, num = 0; p; p = p->Next) for (p = table, num = 0; p; p = p->Next)
if (p->IpAddressList.IpAddress.String[0]) num++; if (p->IpAddressList.IpAddress.String[0]) num++;
need = sizeof(SOCKET_ADDRESS_LIST) + sizeof(SOCKET_ADDRESS) * (num - 1); total = sizeof(SOCKET_ADDRESS_LIST) + sizeof(SOCKET_ADDRESS) * (num - 1);
need += sizeof(SOCKADDR) * num; total += sizeof(SOCKADDR) * num;
*ret_size = need;
if (need > out_size) if (total > out_size)
{ {
HeapFree(GetProcessHeap(), 0, table); HeapFree(GetProcessHeap(), 0, table);
WSASetLastError(WSAEFAULT); status = WSAEFAULT;
return SOCKET_ERROR; break;
} }
if (out_buff) if (out_buff)
@ -3318,15 +3293,15 @@ INT WINAPI WSAIoctl(SOCKET s, DWORD code, LPVOID in_buff, DWORD in_size, LPVOID
} }
HeapFree(GetProcessHeap(), 0, table); HeapFree(GetProcessHeap(), 0, table);
return 0;
} }
else else
{ {
WARN("unable to get IP address list\n"); WARN("unable to get IP address list\n");
WSASetLastError(WSAEINVAL); status = WSAEINVAL;
return SOCKET_ERROR;
} }
break;
} }
case WS_SIO_FLUSH: case WS_SIO_FLUSH:
FIXME("SIO_FLUSH: stub.\n"); FIXME("SIO_FLUSH: stub.\n");
break; break;
@ -3345,7 +3320,7 @@ INT WINAPI WSAIoctl(SOCKET s, DWORD code, LPVOID in_buff, DWORD in_size, LPVOID
if ( IsEqualGUID(&connectex_guid, in_buff) ) if ( IsEqualGUID(&connectex_guid, in_buff) )
{ {
*(LPFN_CONNECTEX *)out_buff = WS2_ConnectEx; *(LPFN_CONNECTEX *)out_buff = WS2_ConnectEx;
return 0; break;
} }
else if ( IsEqualGUID(&disconnectex_guid, in_buff) ) else if ( IsEqualGUID(&disconnectex_guid, in_buff) )
{ {
@ -3354,12 +3329,12 @@ INT WINAPI WSAIoctl(SOCKET s, DWORD code, LPVOID in_buff, DWORD in_size, LPVOID
else if ( IsEqualGUID(&acceptex_guid, in_buff) ) else if ( IsEqualGUID(&acceptex_guid, in_buff) )
{ {
*(LPFN_ACCEPTEX *)out_buff = WS2_AcceptEx; *(LPFN_ACCEPTEX *)out_buff = WS2_AcceptEx;
return 0; break;
} }
else if ( IsEqualGUID(&getaccepexsockaddrs_guid, in_buff) ) else if ( IsEqualGUID(&getaccepexsockaddrs_guid, in_buff) )
{ {
*(LPFN_GETACCEPTEXSOCKADDRS *)out_buff = WS2_GetAcceptExSockaddrs; *(LPFN_GETACCEPTEXSOCKADDRS *)out_buff = WS2_GetAcceptExSockaddrs;
return 0; break;
} }
else if ( IsEqualGUID(&transmitfile_guid, in_buff) ) else if ( IsEqualGUID(&transmitfile_guid, in_buff) )
{ {
@ -3372,7 +3347,7 @@ INT WINAPI WSAIoctl(SOCKET s, DWORD code, LPVOID in_buff, DWORD in_size, LPVOID
else if ( IsEqualGUID(&wsarecvmsg_guid, in_buff) ) else if ( IsEqualGUID(&wsarecvmsg_guid, in_buff) )
{ {
*(LPFN_WSARECVMSG *)out_buff = WS2_WSARecvMsg; *(LPFN_WSARECVMSG *)out_buff = WS2_WSARecvMsg;
return 0; break;
} }
else if ( IsEqualGUID(&wsasendmsg_guid, in_buff) ) else if ( IsEqualGUID(&wsasendmsg_guid, in_buff) )
{ {
@ -3381,10 +3356,9 @@ INT WINAPI WSAIoctl(SOCKET s, DWORD code, LPVOID in_buff, DWORD in_size, LPVOID
else else
FIXME("SIO_GET_EXTENSION_FUNCTION_POINTER %s: stub\n", debugstr_guid(in_buff)); FIXME("SIO_GET_EXTENSION_FUNCTION_POINTER %s: stub\n", debugstr_guid(in_buff));
WSASetLastError(WSAEOPNOTSUPP); status = WSAEOPNOTSUPP;
return SOCKET_ERROR; break;
} }
case WS_SIO_KEEPALIVE_VALS: case WS_SIO_KEEPALIVE_VALS:
{ {
struct tcp_keepalive *k = in_buff; struct tcp_keepalive *k = in_buff;
@ -3402,28 +3376,16 @@ INT WINAPI WSAIoctl(SOCKET s, DWORD code, LPVOID in_buff, DWORD in_size, LPVOID
fd = get_sock_fd(s, 0, NULL); fd = get_sock_fd(s, 0, NULL);
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void *)&keepalive, sizeof(int)) == -1) if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void *)&keepalive, sizeof(int)) == -1)
{ status = WSAEINVAL;
release_sock_fd(s, fd);
WSASetLastError(WSAEINVAL);
return SOCKET_ERROR;
}
#if defined(TCP_KEEPIDLE) && defined(TCP_KEEPINTVL) #if defined(TCP_KEEPIDLE) && defined(TCP_KEEPINTVL)
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, (void *)&keepidle, sizeof(int)) == -1) else if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, (void *)&keepidle, sizeof(int)) == -1)
{ status = WSAEINVAL;
release_sock_fd(s, fd); else if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, (void *)&keepintvl, sizeof(int)) == -1)
WSASetLastError(WSAEINVAL); status = WSAEINVAL;
return SOCKET_ERROR;
}
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, (void *)&keepintvl, sizeof(int)) == -1)
{
release_sock_fd(s, fd);
WSASetLastError(WSAEINVAL);
return SOCKET_ERROR;
}
#else #else
FIXME("ignoring keepalive interval and timeout\n"); else
FIXME("ignoring keepalive interval and timeout\n");
#endif #endif
release_sock_fd(s, fd); release_sock_fd(s, fd);
break; break;
} }
@ -3438,22 +3400,8 @@ INT WINAPI WSAIoctl(SOCKET s, DWORD code, LPVOID in_buff, DWORD in_size, LPVOID
TRACE("-> WS_SIO_ROUTING_INTERFACE_QUERY request\n"); TRACE("-> WS_SIO_ROUTING_INTERFACE_QUERY request\n");
if (!in_buff) if (!in_buff || in_size < sizeof(struct WS_sockaddr) ||
{ !out_buff || out_size < sizeof(struct WS_sockaddr_in) || !ret_size)
WSASetLastError(WSAEFAULT);
return SOCKET_ERROR;
}
if (in_size < sizeof(struct WS_sockaddr))
{
WSASetLastError(WSAEFAULT);
return SOCKET_ERROR;
}
if (!out_buff)
{
WSASetLastError(WSAEFAULT);
return SOCKET_ERROR;
}
if (!ret_size)
{ {
WSASetLastError(WSAEFAULT); WSASetLastError(WSAEFAULT);
return SOCKET_ERROR; return SOCKET_ERROR;
@ -3461,30 +3409,21 @@ INT WINAPI WSAIoctl(SOCKET s, DWORD code, LPVOID in_buff, DWORD in_size, LPVOID
if (daddr->sa_family != AF_INET) if (daddr->sa_family != AF_INET)
{ {
FIXME("unsupported address family %d\n", daddr->sa_family); FIXME("unsupported address family %d\n", daddr->sa_family);
WSASetLastError(WSAEAFNOSUPPORT); status = WSAEAFNOSUPPORT;
return SOCKET_ERROR; break;
} }
if (out_size < sizeof(struct WS_sockaddr_in)) if (GetBestRoute(daddr_in->sin_addr.S_un.S_addr, 0, &row) != NOERROR ||
GetIpAddrTable(NULL, &size, FALSE) != ERROR_INSUFFICIENT_BUFFER)
{ {
WSASetLastError(WSAEFAULT); status = WSAEFAULT;
return SOCKET_ERROR; break;
}
if (GetBestRoute(daddr_in->sin_addr.S_un.S_addr, 0, &row) != NOERROR)
{
WSASetLastError(WSAEFAULT);
return SOCKET_ERROR;
}
if (GetIpAddrTable(NULL, &size, FALSE) != ERROR_INSUFFICIENT_BUFFER)
{
WSASetLastError(WSAEFAULT);
return SOCKET_ERROR;
} }
ipAddrTable = HeapAlloc(GetProcessHeap(), 0, size); ipAddrTable = HeapAlloc(GetProcessHeap(), 0, size);
if (GetIpAddrTable(ipAddrTable, &size, FALSE)) if (GetIpAddrTable(ipAddrTable, &size, FALSE))
{ {
HeapFree(GetProcessHeap(), 0, ipAddrTable); HeapFree(GetProcessHeap(), 0, ipAddrTable);
WSASetLastError(WSAEFAULT); status = WSAEFAULT;
return SOCKET_ERROR; break;
} }
for (i = 0, found_index = ipAddrTable->dwNumEntries; for (i = 0, found_index = ipAddrTable->dwNumEntries;
i < ipAddrTable->dwNumEntries; i++) i < ipAddrTable->dwNumEntries; i++)
@ -3497,20 +3436,20 @@ INT WINAPI WSAIoctl(SOCKET s, DWORD code, LPVOID in_buff, DWORD in_size, LPVOID
ERR("no matching IP address for interface %d\n", ERR("no matching IP address for interface %d\n",
row.dwForwardIfIndex); row.dwForwardIfIndex);
HeapFree(GetProcessHeap(), 0, ipAddrTable); HeapFree(GetProcessHeap(), 0, ipAddrTable);
WSASetLastError(WSAEFAULT); status = WSAEFAULT;
return SOCKET_ERROR; break;
} }
saddr_in->sin_family = AF_INET; saddr_in->sin_family = AF_INET;
saddr_in->sin_addr.S_un.S_addr = ipAddrTable->table[found_index].dwAddr; saddr_in->sin_addr.S_un.S_addr = ipAddrTable->table[found_index].dwAddr;
saddr_in->sin_port = 0; saddr_in->sin_port = 0;
*ret_size = sizeof(struct WS_sockaddr_in); total = sizeof(struct WS_sockaddr_in);
HeapFree(GetProcessHeap(), 0, ipAddrTable); HeapFree(GetProcessHeap(), 0, ipAddrTable);
return 0; break;
} }
case WS_SIO_SET_COMPATIBILITY_MODE: case WS_SIO_SET_COMPATIBILITY_MODE:
TRACE("WS_SIO_SET_COMPATIBILITY_MODE ignored\n"); TRACE("WS_SIO_SET_COMPATIBILITY_MODE ignored\n");
WSASetLastError(WSAEOPNOTSUPP); status = WSAEOPNOTSUPP;
return SOCKET_ERROR; break;
case WS_SIO_UDP_CONNRESET: case WS_SIO_UDP_CONNRESET:
FIXME("WS_SIO_UDP_CONNRESET stub\n"); FIXME("WS_SIO_UDP_CONNRESET stub\n");
break; break;
@ -3519,11 +3458,30 @@ INT WINAPI WSAIoctl(SOCKET s, DWORD code, LPVOID in_buff, DWORD in_size, LPVOID
return SOCKET_ERROR; return SOCKET_ERROR;
default: default:
FIXME("unsupported WS_IOCTL cmd (%s)\n", debugstr_wsaioctl(code)); FIXME("unsupported WS_IOCTL cmd (%s)\n", debugstr_wsaioctl(code));
WSASetLastError(WSAEOPNOTSUPP); status = WSAEOPNOTSUPP;
return SOCKET_ERROR; break;
} }
return 0; if (completion)
{
FIXME( "completion routine %p not supported\n", completion );
}
else if (overlapped)
{
ULONG_PTR cvalue = (overlapped && ((ULONG_PTR)overlapped->hEvent & 1) == 0) ? (ULONG_PTR)overlapped : 0;
overlapped->Internal = status;
overlapped->InternalHigh = total;
if (overlapped->hEvent) NtSetEvent( overlapped->hEvent, NULL );
if (cvalue) WS_AddCompletion( HANDLE2SOCKET(s), cvalue, status, total );
}
if (!status)
{
if (ret_size) *ret_size = total;
return 0;
}
SetLastError( status );
return SOCKET_ERROR;
} }