Пример #1
0
/*
 * @implemented
 */
INT
EXPORT
WSAEventSelect(IN  SOCKET s,
               IN  WSAEVENT hEventObject,
               IN  LONG lNetworkEvents)
{
    PCATALOG_ENTRY Provider;
    INT Status;
    INT Errno;

    if (!WSAINITIALIZED)
    {
        WSASetLastError(WSANOTINITIALISED);
        return SOCKET_ERROR;
    }

    if (!ReferenceProviderByHandle((HANDLE)s, &Provider))
    {
        WSASetLastError(WSAENOTSOCK);
        return SOCKET_ERROR;
    }

    Status = Provider->ProcTable.lpWSPEventSelect(s,
                                                  hEventObject,
                                                  lNetworkEvents,
                                                  &Errno);

    DereferenceProviderByPointer(Provider);

    if (Status == SOCKET_ERROR)
        WSASetLastError(Errno);

    return Status;
}
Пример #2
0
/*
 * @implemented
 */
INT
EXPORT
shutdown(IN  SOCKET s,
         IN  INT how)
{
    PCATALOG_ENTRY Provider;
    INT Errno;
    int Error;

    if (!WSAINITIALIZED)
    {
        WSASetLastError(WSANOTINITIALISED);
        return SOCKET_ERROR;
    }

    if (!ReferenceProviderByHandle((HANDLE)s, &Provider))
    {
        WSASetLastError(WSAENOTSOCK);
        return SOCKET_ERROR;
    }

    Error = Provider->ProcTable.lpWSPShutdown(s,
                                              how,
                                              &Errno);

    DereferenceProviderByPointer(Provider);

    if (Error == SOCKET_ERROR)
    {
        WSASetLastError(Errno);
    }

    return Error;
}
Пример #3
0
/*
 * @implemented
 */
INT
EXPORT
listen(IN SOCKET s,
       IN INT backlog)
{
    PCATALOG_ENTRY Provider;
    INT Status;
    INT Errno;

    if (!WSAINITIALIZED)
    {
        WSASetLastError(WSANOTINITIALISED);
        return SOCKET_ERROR;
    }

    if (!ReferenceProviderByHandle((HANDLE)s,
                                   &Provider))
    {
        WSASetLastError(WSAENOTSOCK);
        return SOCKET_ERROR;
    }

    Status = Provider->ProcTable.lpWSPListen(s,
                                             backlog,
                                             &Errno);

    DereferenceProviderByPointer(Provider);

    if (Status == SOCKET_ERROR)
        WSASetLastError(Errno);

    return Status;
}
Пример #4
0
VOID
CloseAllHandles(PPROVIDER_HANDLE_BLOCK HandleTable)
{
    PPROVIDER_HANDLE_BLOCK Current;
    PLIST_ENTRY CurrentEntry;
    PCATALOG_ENTRY Provider;
    ULONG i;

    WS_DbgPrint(MAX_TRACE, ("HandleTable (0x%X).\n", HandleTable));

    CurrentEntry = HandleTable->Entry.Flink;

    while (CurrentEntry != &HandleTable->Entry)
    {
        Current = CONTAINING_RECORD(CurrentEntry, PROVIDER_HANDLE_BLOCK, Entry);

        for (i = 0; i < HANDLE_BLOCK_ENTRIES; i++)
        {
            Provider = Current->Handles[i].Provider;
            if (Provider != NULL)
            {
                DereferenceProviderByPointer(Provider);
                Current->Handles[i].Handle   = (HANDLE)0;
                Current->Handles[i].Provider = NULL;
            }
        }
        CurrentEntry = CurrentEntry->Flink;
    }
}
Пример #5
0
/*
 * @implemented
 */
SOCKET
EXPORT
WSAAccept(IN     SOCKET s,
          OUT    LPSOCKADDR addr,
          IN OUT LPINT addrlen,
          IN     LPCONDITIONPROC lpfnCondition,
          IN     DWORD_PTR dwCallbackData)
{
    PCATALOG_ENTRY Provider;
    SOCKET Socket;
    INT Errno;

    if (!WSAINITIALIZED)
    {
        WSASetLastError(WSANOTINITIALISED);
        return SOCKET_ERROR;
    }

    if (!ReferenceProviderByHandle((HANDLE)s, &Provider))
    {
        WSASetLastError(WSAENOTSOCK);
        return SOCKET_ERROR;
    }

    WS_DbgPrint(MAX_TRACE,("Calling provider accept\n"));

    Socket = Provider->ProcTable.lpWSPAccept(s,
                                             addr,
                                             addrlen,
                                             lpfnCondition,
                                             dwCallbackData,
                                             &Errno);

    WS_DbgPrint(MAX_TRACE,("Calling provider accept -> Socket %x, Errno %x\n",
                Socket, Errno));

    DereferenceProviderByPointer(Provider);

    if (Socket == INVALID_SOCKET)
        WSASetLastError(Errno);

    if ( addr && addrlen )
    {
#if DBG
        LPSOCKADDR_IN sa = (LPSOCKADDR_IN)addr;
        WS_DbgPrint(MAX_TRACE,("Returned address: %d %s:%d (len %d)\n",
                               sa->sin_family,
                               inet_ntoa(sa->sin_addr),
                               ntohs(sa->sin_port),
                               *addrlen));
#endif
    }

    return Socket;
}
Пример #6
0
/*
 * @implemented
 */
INT
EXPORT
WSAConnect(IN  SOCKET s,
           IN  CONST struct sockaddr *name,
           IN  INT namelen,
           IN  LPWSABUF lpCallerData,
           OUT LPWSABUF lpCalleeData,
           IN  LPQOS lpSQOS,
           IN  LPQOS lpGQOS)
{
    PCATALOG_ENTRY Provider;
    INT Status;
    INT Errno;

    if (!WSAINITIALIZED)
    {
        WSASetLastError(WSANOTINITIALISED);
        return SOCKET_ERROR;
    }

    if (!ReferenceProviderByHandle((HANDLE)s, &Provider))
    {
        WSASetLastError(WSAENOTSOCK);
        return SOCKET_ERROR;
    }

#if (__W32API_MAJOR_VERSION < 2 || __W32API_MINOR_VERSION < 5)
    Status = Provider->ProcTable.lpWSPConnect(s,
                                              (CONST LPSOCKADDR)name,
                                              namelen,
                                              lpCallerData,
                                              lpCalleeData,
                                              lpSQOS,
                                              lpGQOS,
                                              &Errno);
#else
    Status = Provider->ProcTable.lpWSPConnect(s,
                                              name,
                                              namelen,
                                              lpCallerData,
                                              lpCalleeData,
                                              lpSQOS,
                                              lpGQOS,
                                              &Errno);
#endif

    DereferenceProviderByPointer(Provider);

    if (Status == SOCKET_ERROR)
        WSASetLastError(Errno);

    return Status;
}
Пример #7
0
/*
 * @implemented
 */
INT
EXPORT
WSAEnumNetworkEvents(IN  SOCKET s,
                     IN  WSAEVENT hEventObject,
                     OUT LPWSANETWORKEVENTS lpNetworkEvents)
{
    PCATALOG_ENTRY Provider;
    INT Status;
    INT Errno;

    WS_DbgPrint(MID_TRACE,("Called (Socket %x, hEventObject %x, "
                "lpNetworkEvents %x)\n",
                s,
                hEventObject,
                lpNetworkEvents));

    if (!lpNetworkEvents)
    {
        WSASetLastError(WSAEINVAL);
        return SOCKET_ERROR;
    }

    if (!WSAINITIALIZED)
    {
        WSASetLastError(WSANOTINITIALISED);
        return SOCKET_ERROR;
    }

    if (!ReferenceProviderByHandle((HANDLE)s,
                                   &Provider))
    {
        WSASetLastError(WSAENOTSOCK);
        return SOCKET_ERROR;
    }

    Status = Provider->ProcTable.lpWSPEnumNetworkEvents(s,
                                                        hEventObject,
                                                        lpNetworkEvents,
                                                        &Errno);

    DereferenceProviderByPointer(Provider);

    if (Status == SOCKET_ERROR)
        WSASetLastError(Errno);

    WS_DbgPrint(MID_TRACE,("Leaving %x\n", Status));

    return Status;
}
Пример #8
0
/*
 * @implemented
 */
INT
EXPORT
closesocket(IN  SOCKET s)
/*
 * FUNCTION: Closes a socket descriptor
 * ARGUMENTS:
 *     s = Socket descriptor
 * RETURNS:
 *     0, or SOCKET_ERROR if an error ocurred
 */
{
    PCATALOG_ENTRY Provider;
    INT Status;
    INT Errno;

    WS_DbgPrint(MAX_TRACE, ("s (0x%X).\n", s));

    if (!WSAINITIALIZED)
    {
        WSASetLastError(WSANOTINITIALISED);
        return SOCKET_ERROR;
    }

    if (!ReferenceProviderByHandle((HANDLE)s, &Provider))
    {
        WSASetLastError(WSAENOTSOCK);
        return SOCKET_ERROR;
    }

    CloseProviderHandle((HANDLE)s);

    WS_DbgPrint(MAX_TRACE,("DereferenceProviderByHandle\n"));

    DereferenceProviderByPointer(Provider);

    WS_DbgPrint(MAX_TRACE,("DereferenceProviderByHandle Done\n"));

    Status = Provider->ProcTable.lpWSPCloseSocket(s, &Errno);

    WS_DbgPrint(MAX_TRACE,("Provider Close Done\n"));

    if (Status == SOCKET_ERROR)
        WSASetLastError(Errno);

    WS_DbgPrint(MAX_TRACE,("Returning success\n"));

    return 0;
}
Пример #9
0
/*
 * @implemented
 */
INT
EXPORT
WSAIoctl(IN  SOCKET s,
         IN  DWORD dwIoControlCode,
         IN  LPVOID lpvInBuffer,
         IN  DWORD cbInBuffer,
         OUT LPVOID lpvOutBuffer,
         IN  DWORD cbOutBuffer,
         OUT LPDWORD lpcbBytesReturned,
         IN  LPWSAOVERLAPPED lpOverlapped,
         IN  LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
{
    PCATALOG_ENTRY Provider;
    INT Status;
    INT Errno;

    if (!WSAINITIALIZED)
    {
        WSASetLastError(WSANOTINITIALISED);
        return SOCKET_ERROR;
    }

    if (!ReferenceProviderByHandle((HANDLE)s, &Provider))
    {
        WSASetLastError(WSAENOTSOCK);
        return SOCKET_ERROR;
    }

    Status = Provider->ProcTable.lpWSPIoctl(s,
                                            dwIoControlCode,
                                            lpvInBuffer,
                                            cbInBuffer,
                                            lpvOutBuffer,
                                            cbOutBuffer,
                                            lpcbBytesReturned,
                                            lpOverlapped,
                                            lpCompletionRoutine,
                                            NULL /* lpThreadId */,
                                            &Errno);

    DereferenceProviderByPointer(Provider);

    if (Status == SOCKET_ERROR)
        WSASetLastError(Errno);

    return Status;
}
Пример #10
0
/*
 * @implemented
 */
INT
EXPORT __stdcall
setsockopt(IN  SOCKET s,
           IN  INT level,
           IN  INT optname,
           IN  CONST CHAR FAR* optval,
           IN  INT optlen)
{
    PCATALOG_ENTRY Provider;
    INT Errno;
    int Error;

    if (!WSAINITIALIZED)
    {
        WSASetLastError(WSANOTINITIALISED);
        return SOCKET_ERROR;
    }

    if(IS_INTRESOURCE(optval))
    {
        SetLastError(WSAEFAULT);
        return SOCKET_ERROR;
    }

    if (!ReferenceProviderByHandle((HANDLE)s, &Provider))
    {
        WSASetLastError(WSAENOTSOCK);
        return SOCKET_ERROR;
    }

    Error = Provider->ProcTable.lpWSPSetSockOpt(s,
                                                  level,
                                                optname,
                                                optval,
                                                optlen,
                                                &Errno);

    DereferenceProviderByPointer(Provider);

    if (Error == SOCKET_ERROR)
    {
        WSASetLastError(Errno);
    }

    return Error;
}
Пример #11
0
/*
 * @implemented
 */
INT
EXPORT
bind(IN SOCKET s,
     IN CONST struct sockaddr *name,
     IN INT namelen)
{
    PCATALOG_ENTRY Provider;
    INT Status;
    INT Errno;

    if (!WSAINITIALIZED)
    {
        WSASetLastError(WSANOTINITIALISED);
        return SOCKET_ERROR;
    }

    if (!ReferenceProviderByHandle((HANDLE)s,
                                   &Provider))
    {
        WSASetLastError(WSAENOTSOCK);
        return SOCKET_ERROR;
    }

#if (__W32API_MAJOR_VERSION < 2 || __W32API_MINOR_VERSION < 5)
    Status = Provider->ProcTable.lpWSPBind(s,
                                           (CONST LPSOCKADDR)name,
                                           namelen,
                                           &Errno);
#else
    Status = Provider->ProcTable.lpWSPBind(s,
                                           name,
                                           namelen,
                                           &Errno);
#endif /* __W32API_MAJOR_VERSION < 2 || __W32API_MINOR_VERSION < 5 */

    DereferenceProviderByPointer(Provider);

    if (Status == SOCKET_ERROR)
        WSASetLastError(Errno);

  return Status;
}
Пример #12
0
BOOL
CloseProviderHandle(HANDLE Handle)
{
    PCATALOG_ENTRY Provider;

    WS_DbgPrint(MAX_TRACE, ("Handle (0x%X).\n", Handle));

    EnterCriticalSection(&ProviderHandleTableLock);

    Provider = DeleteProviderHandle(ProviderHandleTable,
                                    Handle);

    LeaveCriticalSection(&ProviderHandleTableLock);

    if (!Provider)
        return FALSE;

    DereferenceProviderByPointer(Provider);

    return TRUE;
}
Пример #13
0
/*
 * @unimplemented
 */
INT
EXPORT
WSACancelBlockingCall(VOID)
{
#if 0
    INT Errno;
    int Error;
    PCATALOG_ENTRY Provider;

    if (!WSAINITIALIZED)
    {
        WSASetLastError(WSANOTINITIALISED);
        return SOCKET_ERROR;
    }

    if (!ReferenceProviderByHandle((HANDLE)s, &Provider))
    {
        WSASetLastError(WSAENOTSOCK);
        return SOCKET_ERROR;
    }

    Error = Provider->ProcTable.lpWSPCancelBlockingCall(&Errno);

    DereferenceProviderByPointer(Provider);

    if (Error == SOCKET_ERROR)
    {
        WSASetLastError(Errno);
    }

    return Error;
#endif

    UNIMPLEMENTED

    WSASetLastError(WSASYSCALLFAILURE);
    return SOCKET_ERROR;
}
Пример #14
0
/*
 * @implemented
 */
INT
EXPORT
WSAAsyncSelect(IN  SOCKET s,
               IN  HWND hWnd,
               IN  UINT wMsg,
               IN  LONG lEvent)
{
    PCATALOG_ENTRY Provider;
    INT Errno;
    int Error;

    if (!WSAINITIALIZED)
    {
        WSASetLastError(WSANOTINITIALISED);
        return SOCKET_ERROR;
    }

    if (!ReferenceProviderByHandle((HANDLE)s, &Provider))
    {
        WSASetLastError(WSAENOTSOCK);
        return SOCKET_ERROR;
    }

    Error = Provider->ProcTable.lpWSPAsyncSelect(s,
                                                 hWnd,
                                                 wMsg,
                                                 lEvent,
                                                 &Errno);

    DereferenceProviderByPointer(Provider);

    if (Error == SOCKET_ERROR)
    {
        WSASetLastError(Errno);
    }

    return Error;
}
Пример #15
0
/*
 * @implemented
 */
INT
EXPORT
getsockname(IN     SOCKET s,
            OUT    LPSOCKADDR name,
            IN OUT INT FAR* namelen)
{
    int Error;
    INT Errno;
    PCATALOG_ENTRY Provider;

    if (!WSAINITIALIZED)
    {
        WSASetLastError(WSANOTINITIALISED);
        return SOCKET_ERROR;
    }

    if (!ReferenceProviderByHandle((HANDLE)s,
                                   &Provider))
    {
        WSASetLastError(WSAENOTSOCK);
        return SOCKET_ERROR;
    }

    Error = Provider->ProcTable.lpWSPGetSockName(s,
                                                 name,
                                                 namelen,
                                                 &Errno);

    DereferenceProviderByPointer(Provider);

    if (Error == SOCKET_ERROR)
    {
        WSASetLastError(Errno);
    }

    return Error;
}
Пример #16
0
/*
 * @implemented
 */
INT
EXPORT
select(IN      INT nfds,
       IN OUT  LPFD_SET readfds,
       IN OUT  LPFD_SET writefds,
       IN OUT  LPFD_SET exceptfds,
       IN      CONST struct timeval *timeout)
/*
 * FUNCTION: Returns status of one or more sockets
 * ARGUMENTS:
 *     nfds      = Always ignored
 *     readfds   = Pointer to socket set to be checked for readability (optional)
 *     writefds  = Pointer to socket set to be checked for writability (optional)
 *     exceptfds = Pointer to socket set to be checked for errors (optional)
 *     timeout   = Pointer to a TIMEVAL structure indicating maximum wait time
 *                 (NULL means wait forever)
 * RETURNS:
 *     Number of ready socket descriptors, or SOCKET_ERROR if an error ocurred
 */
{
    PCATALOG_ENTRY Provider = NULL;
    INT Count;
    INT Errno;

    WS_DbgPrint(MAX_TRACE, ("readfds (0x%X)  writefds (0x%X)  exceptfds (0x%X).\n",
                readfds, writefds, exceptfds));

    if (!WSAINITIALIZED)
    {
        WSASetLastError(WSANOTINITIALISED);
        WS_DbgPrint(MID_TRACE,("Not initialized\n"));
        return SOCKET_ERROR;
    }

    /* FIXME: Sockets in FD_SETs should be sorted by their provider */

    /* FIXME: For now, assume only one service provider */
    if ((readfds != NULL) && (readfds->fd_count > 0))
    {
        if (!ReferenceProviderByHandle((HANDLE)readfds->fd_array[0],
                                       &Provider))
        {
            WSASetLastError(WSAENOTSOCK);
            WS_DbgPrint(MID_TRACE,("No provider (read)\n"));
            return SOCKET_ERROR;
        }
    }
    else if ((writefds != NULL) && (writefds->fd_count > 0))
    {
        if (!ReferenceProviderByHandle((HANDLE)writefds->fd_array[0],
                                       &Provider))
        {
            WSASetLastError(WSAENOTSOCK);
            WS_DbgPrint(MID_TRACE,("No provider (write)\n"));
            return SOCKET_ERROR;
        }
    }
    else if ((exceptfds != NULL) && (exceptfds->fd_count > 0))
    {
        if (!ReferenceProviderByHandle((HANDLE)exceptfds->fd_array[0], &Provider))
        {
            WSASetLastError(WSAENOTSOCK);
            WS_DbgPrint(MID_TRACE,("No provider (err)\n"));
            return SOCKET_ERROR;
        }
#if 0 /* XXX empty select is not an error */
    }
    else
    {
        WSASetLastError(WSAEINVAL);
        return SOCKET_ERROR;
#endif
    }

    if ( !Provider )
    {
        if ( timeout )
        {
            WS_DbgPrint(MID_TRACE,("Select: used as timer\n"));
            Sleep( timeout->tv_sec * 1000 + (timeout->tv_usec / 1000) );
        }
        return 0;
    }
    else if (Provider->ProcTable.lpWSPSelect)
    {
        WS_DbgPrint(MID_TRACE,("Calling WSPSelect:%x\n", Provider->ProcTable.lpWSPSelect));
        Count = Provider->ProcTable.lpWSPSelect(nfds,
                                                readfds,
                                                writefds,
                                                exceptfds,
                                                (LPTIMEVAL)timeout,
                                                &Errno);

        WS_DbgPrint(MAX_TRACE, ("[%x] Select: Count %d Errno %x\n",
                    Provider, Count, Errno));

        DereferenceProviderByPointer(Provider);

        if (Count == SOCKET_ERROR)
        {
            WSASetLastError(Errno);
            return SOCKET_ERROR;
        }
    }
    else
    {
        WSASetLastError(WSAEINVAL);
        return SOCKET_ERROR;
    }

    return Count;
}