コード例 #1
0
ファイル: async.c プロジェクト: RareHare/reactos
VOID
WSAAPI
WsAsyncGetHost(IN HANDLE TaskHandle,
               IN DWORD Operation,
               IN HWND hWnd,
               IN UINT wMsg,
               IN CHAR FAR *ByWhat,
               IN INT Length,
               IN INT Type,
               IN CHAR FAR *Buffer,
               IN INT BufferLength)
{
    PHOSTENT Hostent;
    SIZE_T BufferSize = 0;
    LPARAM lParam;
    INT ErrorCode = 0;

    /* Check the operaiton */
    if (Operation == WsAsyncGetHostByAddr)
    {
        /* Call the API */
        Hostent = gethostbyaddr(ByWhat, Length, Type);
    }
    else
    {
        /* Call the API */
        Hostent = gethostbyname(ByWhat);
    }

    /* Make sure we got one */
    if (!Hostent) ErrorCode = GetLastError();

    /* Acquire the lock */
    WsAsyncLock();

    /* Check if this task got cancelled */
    if (TaskHandle == WsAsyncCancelledTaskHandle)
    {
        /* Return */
        WsAsyncUnlock();
        return;
    }

    /* If we got a Servent back, copy it */
    if (Hostent)
    {
        /* Copy it into the buffer */
        BufferSize = CopyHostentToBuffer(Buffer, BufferLength, Hostent);

        /* Check if we had enough space */
        if (BufferSize > (DWORD)BufferLength)
        {
            /* Not enough */
            ErrorCode = WSAENOBUFS;
        }
        else
        {
            /* Perfect */
            ErrorCode = NO_ERROR;
        }
    }

    /* Not processing anyomre */
    WsAsyncCurrentTaskHandle = NULL;

    /* Release the lock */
    WsAsyncUnlock();

    /* Make the messed-up lParam reply */
    lParam = WSAMAKEASYNCREPLY(BufferSize, ErrorCode);

    /* Sent it through the Upcall API */
    WPUPostMessage(hWnd, wMsg, (WPARAM)TaskHandle, lParam);
}
コード例 #2
0
ファイル: wsdata.c プロジェクト: chunhualiu/OpenNT
BOOL
WWS32PostAsyncGetHost (
    HWND hWnd,
    UINT Msg,
    WPARAM wParam,
    LPARAM lParam
    )
{
    PWINSOCK_ASYNC_CONTEXT_BLOCK context;
    BOOL ret;
    PVOID buffer16;
    DWORD bytesRequired;

    context = WWS32FindAndRemoveAsyncContext( (HANDLE)wParam );
    ASSERT( context != NULL );

    //
    // If the call was successful, copy the 32-bit buffer to the
    // 16-bit buffer specified by the application.
    //

    if ( WSAGETASYNCERROR( lParam ) == 0 ) {

        //
        // Copy the 32-bit structure to 16-bit buffer.
        //

        GETVDMPTR( context->vBuffer16, context->Buffer16Length, buffer16 );

        bytesRequired = CopyHostent32To16(
                            buffer16,
                            context->vBuffer16,
                            context->Buffer16Length,
                            context->Buffer32
                            );

        //
        // If the application's buffer was too small, return an error
        // and information aqbout the buffer size required.
        //

        if ( bytesRequired > context->Buffer16Length ) {
            lParam = WSAMAKEASYNCREPLY( (WORD)bytesRequired, WSAENOBUFS );
        }
    }

    //
    // Post the completion message to the 16-bit application.
    //

    ret = PostMessage(
              hWnd,
              Msg >> 16,
              context->AsyncTaskHandle16,
              lParam
              );

    //
    // Free resources and return.
    //

    free_w( context->Buffer32 );
    free_w( (PVOID)context );

    return ret;

} // WWS32PostAsyncGetHost