次の方法で共有


IGlobalStopListeningProvider::D rainRequestsGracefully メソッド

IIS が現在保留中の要求を正常に閉じるかどうかを示します。

構文

virtual BOOL DrainRequestsGracefully(  
   VOID  
) const = 0;  

パラメーター

このメソッドは、パラメーターを受け取りません。

戻り値

true IIS が現在の要求を正常に閉じる場合は 。それ以外の場合は false

解説

メソッドは DrainRequestsGracefully 、ワーカー プロセスのシャットダウン時に、IIS が保留中の要求を閉じる方法に関する情報を取得します。 たとえば、IIS が再起動されると、 DrainRequestsGracefully 保留中のすべての要求が終了するため、 メソッドは を返 false します。 ただし、アプリケーション プールがリサイクルされた場合、 DrainRequestsGracefully シャットダウン中のワーカー プロセスで保留中のすべての要求が正常に閉じられるため、 メソッドは を返 true します。

次のコード例では、次のタスクを実行する HTTP モジュールを作成する方法を示します。

  1. GL_STOP_LISTENING通知に登録します。

  2. OnGlobalStopListening メソッドを含む CGlobalModule クラスを作成します。 このメソッドは、次のタスクを実行します。

    1. メソッドを使用して現在の要求を閉じるのに IIS が使用する状態を DrainRequestsGracefully 取得します。

    2. 状態情報を含む文字列を書式設定します。

    3. 文字列をイベントとして、イベント ビューアーのアプリケーション ログに書き込みます。

  3. クラスを CGlobalModule メモリから削除し、終了します。

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

// Create the module's global class.
class MyGlobalModule : public CGlobalModule
{
public:

    // Process a GL_STOP_LISTENING notification.
    GLOBAL_NOTIFICATION_STATUS
    OnGlobalStopListening(
        IN IGlobalStopListeningProvider * pProvider
    )
    {
        UNREFERENCED_PARAMETER( pProvider );
        // Create a string buffer.
        char szBuffer[256] = "";
        // Retrieve the Boolean value and format the string.
        sprintf_s(szBuffer,255,"Drain Requests Gracefully: %s",
            (TRUE==pProvider->DrainRequestsGracefully())?"Yes":"No");
        // Write the string to the event viewer.
        WriteEventViewerLog(szBuffer);
        // Continue processing.
        return GL_NOTIFICATION_CONTINUE;
    }

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

    MyGlobalModule()
    {
        // Open a handle to the Event Viewer.
        m_hEventLog = RegisterEventSource( NULL,"IISADMIN" );
    }

    ~MyGlobalModule()
    {
        // Test whether the handle for the Event Viewer is open.
        if (NULL != m_hEventLog)
        {
            // Close the handle to the Event Viewer.
            DeregisterEventSource( m_hEventLog );
            m_hEventLog = NULL;
        }
    }

private:

    // Create a handle for the event viewer.
    HANDLE m_hEventLog;

    // Define a method that writes to the Event Viewer.
    BOOL WriteEventViewerLog(LPCSTR szNotification)
    {
        // Test whether the handle for the Event Viewer is open.
        if (NULL != m_hEventLog)
        {
            // Write any strings to the Event Viewer and return.
            return ReportEvent(
                m_hEventLog, EVENTLOG_INFORMATION_TYPE, 0, 0,
                NULL, 1, 0, &szNotification, NULL );
        }
        return FALSE;
    }
};

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

    // Create an instance of the global module class.
    MyGlobalModule * pGlobalModule = new MyGlobalModule;
    // Test for an error.
    if (NULL == pGlobalModule)
    {
        return HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
    }
    // Set the global notifications and exit.
    return pModuleInfo->SetGlobalNotifications(
        pGlobalModule, GL_STOP_LISTENING );
}

モジュールで RegisterModule 関数をエクスポートする必要があります。 この関数をエクスポートするには、プロジェクトのモジュール定義 (.def) ファイルを作成するか、 スイッチを使用してモジュールを /EXPORT:RegisterModule コンパイルします。 詳細については、「 チュートリアル: ネイティブ コードを使用したRequest-Level HTTP モジュールの作成」を参照してください。

必要に応じて、各関数の呼び出し規約を __stdcall (/Gz) 明示的に宣言するのではなく、呼び出し規約を使用してコードをコンパイルできます。

要件

Type 説明
Client - 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
Header Httpserv.h

参照

IGlobalStopListeningProvider インターフェイス