Skip to content
This repository has been archived by the owner on Nov 1, 2018. It is now read-only.

Commit

Permalink
Changes async calls to use OnAsyncComplete event pattern (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkotalik authored Oct 17, 2017
1 parent 7117147 commit 68014a7
Show file tree
Hide file tree
Showing 9 changed files with 360 additions and 19 deletions.
5 changes: 4 additions & 1 deletion AspNetCoreModule.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26815.1
VisualStudioVersion = 15.0.26815.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AspNetCore", "src\AspNetCore\AspNetCore.vcxproj", "{439824F9-1455-4CC4-BD79-B44FA0A16552}"
ProjectSection(ProjectDependencies) = postProject
Expand Down Expand Up @@ -102,4 +102,7 @@ Global
{030225D8-4EE8-47E5-B692-2A96B3B51A38} = {02F461DC-5166-4E88-AAD5-CF110016A647}
{4062EA94-75F5-4691-86DC-C8594BA896DE} = {02F461DC-5166-4E88-AAD5-CF110016A647}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0967E9B4-FEE7-40D7-860A-23E340E65840}
EndGlobalSection
EndGlobal
2 changes: 2 additions & 0 deletions src/AspNetCore/AspNetCore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,11 @@
<ClInclude Include="Inc\fx_ver.h" />
<ClInclude Include="Inc\inprocessapplication.h" />
<ClInclude Include="Inc\outprocessapplication.h" />
<ClInclude Include="Inc\inprocessstoredcontext.h" />
<ClInclude Include="Src\precomp.hxx" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Src\inprocessstoredcontext.cxx" />
<ClCompile Include="Src\inprocessapplication.cxx" />
<ClCompile Include="Src\outprocessapplication.cxx" />
<ClCompile Include="Src\application.cxx" />
Expand Down
12 changes: 12 additions & 0 deletions src/AspNetCore/Inc/inprocessapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
typedef void(*request_handler_cb) (int error, IHttpContext* pHttpContext, void* pvCompletionContext);
typedef REQUEST_NOTIFICATION_STATUS(*PFN_REQUEST_HANDLER) (IHttpContext* pHttpContext, void* pvRequstHandlerContext);
typedef BOOL(*PFN_SHUTDOWN_HANDLER) (void* pvShutdownHandlerContext);
typedef REQUEST_NOTIFICATION_STATUS(*PFN_MANAGED_CONTEXT_HANDLER)(void *pvManagedHttpContext, HRESULT hrCompletionStatus, DWORD cbCompletion);

#include "application.h"

Expand Down Expand Up @@ -39,6 +40,7 @@ class IN_PROCESS_APPLICATION : public APPLICATION
SetCallbackHandles(
_In_ PFN_REQUEST_HANDLER request_callback,
_In_ PFN_SHUTDOWN_HANDLER shutdown_callback,
_In_ PFN_MANAGED_CONTEXT_HANDLER managed_context_callback,
_In_ VOID* pvRequstHandlerContext,
_In_ VOID* pvShutdownHandlerContext
);
Expand All @@ -54,6 +56,13 @@ class IN_PROCESS_APPLICATION : public APPLICATION
VOID
);

REQUEST_NOTIFICATION_STATUS
OnAsyncCompletion(
IHttpContext* pHttpContext,
DWORD cbCompletion,
HRESULT hrCompletionStatus
);

static
IN_PROCESS_APPLICATION*
GetInstance(
Expand All @@ -76,6 +85,8 @@ class IN_PROCESS_APPLICATION : public APPLICATION
PFN_SHUTDOWN_HANDLER m_ShutdownHandler;
VOID* m_ShutdownHandlerContext;

PFN_MANAGED_CONTEXT_HANDLER m_AsyncCompletionHandler;

// The event that gets triggered when managed initialization is complete
HANDLE m_pInitalizeEvent;

Expand All @@ -84,6 +95,7 @@ class IN_PROCESS_APPLICATION : public APPLICATION

BOOL m_fManagedAppLoaded;
BOOL m_fLoadManagedAppError;
BOOL m_fIsWebSocketsConnection;

static IN_PROCESS_APPLICATION* s_Application;

Expand Down
67 changes: 67 additions & 0 deletions src/AspNetCore/Inc/inprocessstoredcontext.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

#pragma once
class IN_PROCESS_STORED_CONTEXT : public IHttpStoredContext
{
public:
IN_PROCESS_STORED_CONTEXT(
IHttpContext* pHttpContext,
PVOID pvManagedContext
);
~IN_PROCESS_STORED_CONTEXT();

virtual
VOID
CleanupStoredContext(
VOID
)
{
delete this;
}

virtual
VOID
OnClientDisconnected(
VOID
)
{
}

virtual
VOID
OnListenerEvicted(
VOID
)
{
}

PVOID
QueryManagedHttpContext(
VOID
);

IHttpContext*
QueryHttpContext(
VOID
);

static
HRESULT
GetInProcessStoredContext(
IHttpContext* pHttpContext,
IN_PROCESS_STORED_CONTEXT** ppInProcessStoredContext
);

static
HRESULT
SetInProcessStoredContext(
IHttpContext* pHttpContext,
IN_PROCESS_STORED_CONTEXT* pInProcessStoredContext
);

private:
PVOID m_pManagedHttpContext;
IHttpContext* m_pHttpContext;
};

28 changes: 22 additions & 6 deletions src/AspNetCore/Src/forwardinghandler.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1143,11 +1143,6 @@ FORWARDING_HANDLER::OnExecuteRequestHandler(
{
case HOSTING_IN_PROCESS:
{
// Allow reading and writing to simultaneously
((IHttpContext3*)m_pW3Context)->EnableFullDuplex();

// Disable response buffering by default, we'll do a write behind buffering in managed code
((IHttpResponse2*)m_pW3Context->GetResponse())->DisableBuffering();

hr = ((IN_PROCESS_APPLICATION*)m_pApplication)->LoadManagedApplication();
if (FAILED(hr))
Expand Down Expand Up @@ -1570,7 +1565,28 @@ REQUEST_NOTIFICATION_STATUS
reinterpret_cast<PVOID>(static_cast<DWORD_PTR>(hrCompletionStatus)));
}

if (m_pApplication->QueryConfig()->QueryHostingModel() == HOSTING_OUT_PROCESS)
if (m_pApplication->QueryConfig()->QueryHostingModel() == HOSTING_IN_PROCESS)
{
if (FAILED(hrCompletionStatus))
{
return RQ_NOTIFICATION_FINISH_REQUEST;
}
else
{
// For now we are assuming we are in our own self contained box.
// TODO refactor Finished and Failure sections to handle in process and out of process failure.
// TODO verify that websocket's OnAsyncCompletion is not calling this.
IN_PROCESS_APPLICATION* application = (IN_PROCESS_APPLICATION*)m_pApplication;
if (application == NULL)
{
hr = E_FAIL;
return RQ_NOTIFICATION_FINISH_REQUEST;
}

return application->OnAsyncCompletion(m_pW3Context, cbCompletion, hrCompletionStatus);
}
}
else if (m_pApplication->QueryConfig()->QueryHostingModel() == HOSTING_OUT_PROCESS)
{
//
// Take a reference so that object does not go away as a result of
Expand Down
Loading

0 comments on commit 68014a7

Please sign in to comment.