다음을 통해 공유


IHttpResponse::WriteEntityChunks 메서드

하나 이상의 HTTP_DATA_CHUNK 구조를 응답 본문에 추가합니다.

구문

virtual HRESULT WriteEntityChunks(  
   IN HTTP_DATA_CHUNK* pDataChunks,  
   IN DWORD nChunks,  
   IN BOOL fAsync,  
   IN BOOL fMoreData,  
   OUT DWORD* pcbSent,  
   OUT BOOL* pfCompletionExpected = NULL  
) = 0;  

매개 변수

pDataChunks
[IN] 하나 이상의 HTTP_DATA_CHUNK 구조체에 대한 포인터입니다.

nChunks
[IN] DWORD 가 가리키는 pDataChunks청크 수를 포함하는 입니다.

fAsync
[IN] true 메서드가 비동기적으로 완료되어야 하면 이고, 그렇지 않으면 입니다 false.

fMoreData
[IN] true 응답에 더 많은 데이터를 전송해야 하는 경우 false 마지막 데이터인 경우 입니다.

pcbSent
[OUT] 호출이 동기적으로 완료된 경우 클라이언트로 전송된 바이트 수입니다.

pfCompletionExpected
[OUT] true 이 호출에 대해 비동기 완료가 보류 중이면 이고, 그렇지 않으면 입니다 false.

반환 값

HRESULT입니다. 가능한 값에는 다음 표에 있는 값이 포함되지만, 이에 국한되는 것은 아닙니다.

설명
S_OK 작업이 성공했음을 나타냅니다.
ERROR_INVALID_PARAMETER 매개 변수가 유효하지 않음을 나타냅니다(예: 포인터가 pDataChunks NULL로 설정됨).
ERROR_NOT_ENOUGH_MEMORY 작업을 수행할 메모리가 부족했음을 나타냅니다.
ERROR_ARITHMETIC_OVERFLOW 응답에 65535개 이상의 청크가 추가되었습니다.

설명

개발자는 메서드를 WriteEntityChunks 사용하여 단일 HTTP_DATA_CHUNK 구조체 또는 구조체 HTTP_DATA_CHUNK 배열을 응답 본문에 삽입할 수 있습니다. 작업이 동기적으로 pcbSent 완료된 경우 매개 변수는 응답에 삽입된 바이트 수를 수신합니다.

버퍼링이 켜져 WriteEntityChunks 있으면 메서드는 모든 HTTP_DATA_CHUNK 구조체의 복사본을 만들어 기본 데이터를 복제하여 보존할 필요가 없습니다. 버퍼링이 꺼져 있거나 응답 버퍼 제한에 도달 WriteEntityChunks 하면 메서드도 응답을 플러시합니다. 버퍼링이 꺼져 있고 매개 변수가 fAsynctrue인 경우 요청이 완료될 때까지 메모리를 유지해야 합니다.

매개 변수true를 로 WriteEntityChunks 설정 fAsync 하여 비동기적으로 완료하도록 작업을 구성할 수 있습니다. 이 경우 메서드는 WriteEntityChunks 호출자에게 즉시 반환되고 pcbSent 매개 변수는 응답에 삽입된 바이트 수를 수신하지 않습니다. 버퍼링이 비활성화되고 매개 변수가 fAsynctrue인 경우 비동기 호출이 완료될 때까지 매개 변수의 메모리 pDataChunks 를 유지해야 합니다.

요청에 최대 65535 청크(64KB -1)를 쓸 수 있습니다.

예제

다음 예제에서는 메서드를 사용하여 WriteEntityChunks 응답에 두 데이터 청크의 배열을 삽입하는 HTTP 모듈을 만드는 방법을 보여 줍니다. 그런 다음, 웹 클라이언트에 대한 응답을 반환합니다.

#define _WINSOCKAPI_
#include <windows.h>
#include <sal.h>
#include <httpserv.h>

// Create the module class.
class MyHttpModule : public CHttpModule
{
public:
    REQUEST_NOTIFICATION_STATUS
    OnBeginRequest(
        IN IHttpContext * pHttpContext,
        IN IHttpEventProvider * pProvider
    )
    {
        UNREFERENCED_PARAMETER( pProvider );

        // Create an HRESULT to receive return values from methods.
        HRESULT hr;
        
        // Create an array of data chunks.
        HTTP_DATA_CHUNK dataChunk[2];

        // Buffer for bytes written of data chunk.
        DWORD cbSent;
        
        // Create string buffers.
        PCSTR pszOne = "First chunk data\n";
        PCSTR pszTwo = "Second chunk data\n";

        // Retrieve a pointer to the response.
        IHttpResponse * pHttpResponse = pHttpContext->GetResponse();

        // Test for an error.
        if (pHttpResponse != NULL)
        {
            // Clear the existing response.
            pHttpResponse->Clear();
            // Set the MIME type to plain text.
            pHttpResponse->SetHeader(
                HttpHeaderContentType,"text/plain",
                (USHORT)strlen("text/plain"),TRUE);
            
            // Set the chunk to a chunk in memory.
            dataChunk[0].DataChunkType = HttpDataChunkFromMemory;
            // Set the chunk to the first buffer.
            dataChunk[0].FromMemory.pBuffer =
                (PVOID) pszOne;
            // Set the chunk size to the first buffer size.
            dataChunk[0].FromMemory.BufferLength =
                (USHORT) strlen(pszOne);

            // Set the chunk to a chunk in memory.
            dataChunk[1].DataChunkType = HttpDataChunkFromMemory;
            // Set the chunk to the second buffer.
            dataChunk[1].FromMemory.pBuffer =
                (PVOID) pszTwo;
            // Set the chunk size to the second buffer size.
            dataChunk[1].FromMemory.BufferLength =
                (USHORT) strlen(pszTwo);

            // Insert the data chunks into the response.
            hr = pHttpResponse->WriteEntityChunks(
                dataChunk,2,FALSE,TRUE,&cbSent);

            // Test for an error.
            if (FAILED(hr))
            {
                // Set the error status.
                pProvider->SetErrorStatus( hr );
            }
            // End additional processing.
            return RQ_NOTIFICATION_FINISH_REQUEST;
        }
        // Return processing to the pipeline.
        return RQ_NOTIFICATION_CONTINUE;
    }
};

// Create the module's class factory.
class MyHttpModuleFactory : public IHttpModuleFactory
{
public:
    HRESULT
    GetHttpModule(
        OUT CHttpModule ** ppModule, 
        IN IModuleAllocator * pAllocator
    )
    {
        UNREFERENCED_PARAMETER( pAllocator );

        // Create a new instance.
        MyHttpModule * pModule = new MyHttpModule;

        // Test for an error.
        if (!pModule)
        {
            // Return an error if the factory cannot create the instance.
            return HRESULT_FROM_WIN32( ERROR_NOT_ENOUGH_MEMORY );
        }
        else
        {
            // Return a pointer to the module.
            *ppModule = pModule;
            pModule = NULL;
            // Return a success status.
            return S_OK;
        }            
    }

    void Terminate()
    {
        // Remove the class from memory.
        delete this;
    }
};

// Create the module's exported registration function.
HRESULT
__stdcall
RegisterModule(
    DWORD dwServerVersion,
    IHttpModuleRegistrationInfo * pModuleInfo,
    IHttpServer * pGlobalInfo
)
{
    UNREFERENCED_PARAMETER( dwServerVersion );
    UNREFERENCED_PARAMETER( pGlobalInfo );

    // Set the request notifications and exit.
    return pModuleInfo->SetRequestNotifications(
        new MyHttpModuleFactory,
        RQ_BEGIN_REQUEST,
        0
    );
}

모듈은 RegisterModule 함수를 내보내야 합니다. 프로젝트에 대한 모듈 정의(.def) 파일을 만들어 이 함수를 내보내거나 스위치를 사용하여 /EXPORT:RegisterModule 모듈을 컴파일할 수 있습니다. 자세한 내용은 연습: 네이티브 코드를 사용하여 Request-Level HTTP 모듈 만들기를 참조하세요.

필요에 따라 각 함수에 대한 호출 규칙을 명시적으로 선언하는 대신 호출 규칙을 사용하여 __stdcall (/Gz) 코드를 컴파일할 수 있습니다.

요구 사항

형식 Description
클라이언트 - Windows Vista의 IIS 7.0
- Windows 7의 IIS 7.5
- Windows 8의 IIS 8.0
- WINDOWS 10 IIS 10.0
서버 - Windows Server 2008의 IIS 7.0
- Windows Server 2008 R2의 IIS 7.5
- Windows Server 2012의 IIS 8.0
- Windows Server 2012 R2의 IIS 8.5
- WINDOWS SERVER 2016 IIS 10.0
제품 - IIS 7.0, IIS 7.5, IIS 8.0, IIS 8.5, IIS 10.0
- IIS Express 7.5, IIS Express 8.0, IIS Express 10.0
헤더 Httpserv.h

참고 항목

IHttpResponse 인터페이스
IHttpResponse::WriteEntityChunkByReference 메서드