示例#1
0
BOOL InitializeServerIo(
    PSERVER_CONTEXT pServerContext
)
{
    ULONG Result;
    HTTP_BINDING_INFO HttpBindingInfo = {0};

    Result = HttpCreateRequestQueue(
                 g_HttpApiVersion,
                 L"Test_Http_Server_HTTPAPI_V2",
                 NULL,
                 0,
                 &(pServerContext->hRequestQueue));

    if (Result != NO_ERROR)
    {
        fprintf(stderr, "HttpCreateRequestQueue failed\n");
        return FALSE;
    }

    HttpBindingInfo.Flags.Present       = 1;
    HttpBindingInfo.RequestQueueHandle  = pServerContext->hRequestQueue;

    Result = HttpSetUrlGroupProperty(
                 pServerContext->urlGroupId,
                 HttpServerBindingProperty,
                 &HttpBindingInfo,
                 sizeof(HttpBindingInfo));

    if (Result != NO_ERROR)
    {
        fprintf(stderr, "HttpSetUrlGroupProperty(...HttpServerBindingProperty...) failed\n");
        return FALSE;
    }

    pServerContext->Io = CreateThreadpoolIo(
                             pServerContext->hRequestQueue,
                             IoCompletionCallback,
                             NULL,
                             NULL);

    if (pServerContext->Io == NULL)
    {
        fprintf(stderr, "Creating a new I/O completion object failed\n");
        return FALSE;
    }

    return TRUE;
}
示例#2
0
DWORD
CreateHttpListener(
	OUT PHTTP_LISTENER* httpListener
	)
{

	ULONG           result;

	PHTTP_LISTENER _listener = (PHTTP_LISTENER)ALLOC_MEM(sizeof(HTTP_LISTENER)); 
	ZeroMemory(_listener, sizeof(HTTP_LISTENER));
	(*httpListener) = _listener;

	_listener->hRequestQueue = NULL;
	_listener->RequestQueueLength = 5000; // Default request queue length;
	_listener->errorCode = 0;
	_listener->urls = NULL;
	_listener->pthreadPoolIO = NULL;
	_listener->State = HTTP_LISTENER_STATE_FAULTED;	
	_listener->stats = (PLISTENER_STATS)_aligned_malloc(sizeof(LISTENER_STATS),MEMORY_ALLOCATION_ALIGNMENT);
	HTTPAPI_VERSION HttpApiVersion = HTTPAPI_VERSION_2;	

	//
    // Initialize HTTP APIs.
    //
    result = HttpInitialize( 
                HttpApiVersion,
                HTTP_INITIALIZE_SERVER,    // Flags
                NULL                       // Reserved
                );

    if (result != NO_ERROR)
    {
		DEBUG_ASSERT(false);
		LOG_ERROR(L"\nHttpInitialize failed with %lu", result);		
    }
	
	if(result == NO_ERROR)
	{
		result = HttpCreateServerSession(HttpApiVersion,
										&_listener->SessionId, 
										NULL); 
		if(result)
		{		
			LOG_ERROR(L"\nHttpCreateServerSession failed with %lu", result);			
		}
	}

	if(result == NO_ERROR)
	{
		result = HttpCreateRequestQueue(HttpApiVersion, 
										NULL, 
										NULL, 
										0,
										&_listener->hRequestQueue);
		if(result)
		{
			LOG_ERROR(L"\nHttpCreateRequestQueue failed with %lu", result);				
		}
	}

	if(result == NO_ERROR)
	{
		result = HttpSetRequestQueueProperty(_listener->hRequestQueue, 
											HttpServerQueueLengthProperty, 
											&_listener->RequestQueueLength,
											sizeof(_listener->RequestQueueLength),
											NULL,
											NULL);
		if(result)
		{
			LOG_ERROR(L"\nHttpSetRequestQueueProperty failed with %lu", result);				
		}
	}
	
	if(result == NO_ERROR)
	{
		if(SetFileCompletionNotificationModes(_listener->hRequestQueue, 
											FILE_SKIP_COMPLETION_PORT_ON_SUCCESS | 
											FILE_SKIP_SET_EVENT_ON_HANDLE) == FALSE)
		{
			result = GetLastError();			
		}
	}

	if(result == NO_ERROR)
	{	
		result = HttpListenerInitializeThreadPool(_listener);
	}

	if(result == NO_ERROR)
	{
		_listener->pthreadPoolIO =  CreateThreadpoolIo(_listener->hRequestQueue, 
														HttpListenerDemuxer, 
														(void*)_listener, 
														&_listener->tpEnvironment);
	}


	InitializeIOContextCache();
	InitializeHttpInputQueue(_listener);
	_listener->errorCode = result;
	return _listener->errorCode;
}