mirror of
https://github.com/reactos/reactos.git
synced 2025-08-04 08:15:41 +00:00
select: change it to be more readable, avoid a spurious compiler warning.
svn path=/trunk/; revision=43303
This commit is contained in:
parent
9c974bb786
commit
6c43b7b64f
1 changed files with 56 additions and 59 deletions
|
@ -48,72 +48,69 @@ select(IN INT s,
|
||||||
PWSSOCKET Socket;
|
PWSSOCKET Socket;
|
||||||
INT Status;
|
INT Status;
|
||||||
INT ErrorCode;
|
INT ErrorCode;
|
||||||
BOOL Found = FALSE;
|
|
||||||
SOCKET Handle;
|
SOCKET Handle;
|
||||||
|
LPWSPSELECT WSPSelect;
|
||||||
|
|
||||||
DPRINT("select: %lx %p %p %p %p\n", s, readfds, writefds, exceptfds, timeout);
|
DPRINT("select: %lx %p %p %p %p\n", s, readfds, writefds, exceptfds, timeout);
|
||||||
|
|
||||||
#if defined(__GNUC__) && \
|
|
||||||
(__GNUC__ * 100 + __GNUC_MINOR__ == 404)
|
|
||||||
/* Silence incorrect GCC 4.4.x warning */
|
|
||||||
Handle = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Check for WSAStartup */
|
/* Check for WSAStartup */
|
||||||
if ((ErrorCode = WsQuickProlog()) == ERROR_SUCCESS)
|
ErrorCode = WsQuickProlog();
|
||||||
|
|
||||||
|
if (ErrorCode != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
/* Use the first Socket from the first valid set */
|
SetLastError(ErrorCode);
|
||||||
if (readfds && readfds->fd_count)
|
return SOCKET_ERROR;
|
||||||
{
|
|
||||||
Handle = readfds->fd_array[0];
|
|
||||||
Found = TRUE;
|
|
||||||
}
|
|
||||||
if (!Found && writefds && writefds->fd_count)
|
|
||||||
{
|
|
||||||
Handle = writefds->fd_array[0];
|
|
||||||
Found = TRUE;
|
|
||||||
}
|
|
||||||
if (!Found && exceptfds && exceptfds->fd_count)
|
|
||||||
{
|
|
||||||
Handle = exceptfds->fd_array[0];
|
|
||||||
Found = TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Make sure we found one */
|
|
||||||
if (Found)
|
|
||||||
{
|
|
||||||
/* Get the Socket Context */
|
|
||||||
if ((Socket = WsSockGetSocket(Handle)))
|
|
||||||
{
|
|
||||||
/* Make the call */
|
|
||||||
Status = Socket->Provider->Service.lpWSPSelect(s,
|
|
||||||
readfds,
|
|
||||||
writefds,
|
|
||||||
exceptfds,
|
|
||||||
(struct timeval *)timeout,
|
|
||||||
&ErrorCode);
|
|
||||||
/* Deference the Socket Context */
|
|
||||||
WsSockDereference(Socket);
|
|
||||||
|
|
||||||
/* Return Provider Value */
|
|
||||||
if (Status != SOCKET_ERROR) return Status;
|
|
||||||
|
|
||||||
/* If everything seemed fine, then the WSP call failed itself */
|
|
||||||
if (ErrorCode == NO_ERROR) ErrorCode = WSASYSCALLFAILURE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* No Socket Context Found */
|
|
||||||
ErrorCode = WSAENOTSOCK;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Invalid handles */
|
|
||||||
ErrorCode = WSAEINVAL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return with an Error */
|
/* Use the first Socket from the first valid set */
|
||||||
|
if (readfds && readfds->fd_count)
|
||||||
|
{
|
||||||
|
Handle = readfds->fd_array[0];
|
||||||
|
}
|
||||||
|
else if (writefds && writefds->fd_count)
|
||||||
|
{
|
||||||
|
Handle = writefds->fd_array[0];
|
||||||
|
}
|
||||||
|
else if (exceptfds && exceptfds->fd_count)
|
||||||
|
{
|
||||||
|
Handle = exceptfds->fd_array[0];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Invalid handles */
|
||||||
|
SetLastError(WSAEINVAL);
|
||||||
|
return SOCKET_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get the Socket Context */
|
||||||
|
Socket = WsSockGetSocket(Handle);
|
||||||
|
|
||||||
|
if (!Socket)
|
||||||
|
{
|
||||||
|
/* No Socket Context Found */
|
||||||
|
SetLastError(WSAENOTSOCK);
|
||||||
|
return SOCKET_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get the select procedure */
|
||||||
|
WSPSelect = Socket->Provider->Service.lpWSPSelect;
|
||||||
|
|
||||||
|
/* Make the call */
|
||||||
|
Status = WSPSelect(s, readfds, writefds, exceptfds, (struct timeval *)timeout,
|
||||||
|
&ErrorCode);
|
||||||
|
|
||||||
|
/* Deference the Socket Context */
|
||||||
|
WsSockDereference(Socket);
|
||||||
|
|
||||||
|
/* Return Provider Value */
|
||||||
|
if (Status != SOCKET_ERROR)
|
||||||
|
return Status;
|
||||||
|
|
||||||
|
/* If everything seemed fine, then the WSP call failed itself */
|
||||||
|
if (ErrorCode == NO_ERROR)
|
||||||
|
ErrorCode = WSASYSCALLFAILURE;
|
||||||
|
|
||||||
|
/* Return with an error */
|
||||||
SetLastError(ErrorCode);
|
SetLastError(ErrorCode);
|
||||||
return SOCKET_ERROR;
|
return SOCKET_ERROR;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue