Пример #1
0
VOID
WSAAPI
WsNqDereference(IN PNSQUERY Query)
{
    /* Decrease the reference count and check if it's zero */
    if (!InterlockedDecrement(&Query->RefCount))
    {
        /* Delete us*/
        WsNqDelete(Query);
    }
}
Пример #2
0
/*
 * @implemented
 */
INT 
WINAPI
WSALookupServiceBeginW(IN LPWSAQUERYSETW lpqsRestrictions,
                       IN DWORD dwControlFlags,
                       OUT LPHANDLE lphLookup)
{
    PWSPROCESS Process;
    PWSTHREAD Thread;
    INT ErrorCode;
    PNSQUERY Query;
    DPRINT("WSALookupServiceBeginW: %p\n", lpqsRestrictions);

    /* Enter prolog */
    if ((ErrorCode = WsApiProlog(&Process, &Thread)) != ERROR_SUCCESS)
    {
        /* Leave now */
        SetLastError(ErrorCode);
        return SOCKET_ERROR;
    }

    /* Verify pointers */
    if (IsBadWritePtr(lphLookup, sizeof(*lphLookup)) ||
        IsBadReadPtr(lpqsRestrictions, sizeof(*lpqsRestrictions)))
    {
        /* They are invalid; fail */
        SetLastError(WSAEFAULT);
        return SOCKET_ERROR;
    }

    /* Create a new query object */
    if ((Query = WsNqAllocate()))
    {
        /* Initialize it */
        WsNqInitialize(Query);

        /* Do the lookup */
        ErrorCode = WsNqLookupServiceBegin(Query,
                                           lpqsRestrictions,
                                           dwControlFlags,
                                           WsProcGetNsCatalog(Process));

        /* Check for success */
        if (ErrorCode == ERROR_SUCCESS)
        {
            /* Return the handle */
            *lphLookup = Query;
        }
        else
        {
            /* Fail */
            *lphLookup = NULL;
            WsNqDelete(Query);
        }
    }
    else
    {
        /* No memory */
        ErrorCode = SOCKET_ERROR;
        SetLastError(WSAENOBUFS);
    }
    
    /* Return */
    return ErrorCode;
}