指示 IIS 是否会正常关闭任何当前挂起的请求。
语法
virtual BOOL DrainRequestsGracefully(
VOID
) const = 0;
参数
此方法不采用参数。
返回值
true
如果 IIS 将正常关闭当前请求,则为 ;否则为 false
。
备注
方法 DrainRequestsGracefully
检索有关在关闭工作进程时 IIS 如何关闭任何挂起的请求的信息。 例如,如果重新启动 IIS,方法 DrainRequestsGracefully
将返回 false
,因为所有挂起的请求都将终止。 但是,如果回收应用程序池,该方法 DrainRequestsGracefully
将返回 true
,因为正在关闭的工作进程上所有挂起的请求都将正常关闭。
示例
下面的代码示例演示如何创建执行以下任务的 HTTP 模块:
注册 GL_STOP_LISTENING 通知。
创建包含 OnGlobalStopListening 方法的 CGlobalModule 类。 此方法执行以下任务:
检索 IIS 将用于通过使用
DrainRequestsGracefully
方法关闭当前请求的状态。设置包含状态信息的字符串的格式。
将字符串作为事件写入事件查看器的应用程序日志。
从内存中删除
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)
而不是为每个函数显式声明调用约定。
要求
类型 | 说明 |
---|---|
客户端 | - 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 |