forked from tjanczuk/iisnode
/
cnodehttpstoredcontext.cpp
275 lines (222 loc) · 5.69 KB
/
cnodehttpstoredcontext.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#include "precomp.h"
CNodeHttpStoredContext::CNodeHttpStoredContext(CNodeApplication* nodeApplication, IHttpContext* context)
: nodeApplication(nodeApplication), context(context), process(NULL), buffer(NULL), bufferSize(0), dataSize(0), parsingOffset(0),
chunkLength(0), chunkTransmitted(0), isChunked(FALSE), pipe(INVALID_HANDLE_VALUE), result(S_OK), isLastChunk(FALSE),
requestNotificationStatus(RQ_NOTIFICATION_PENDING), connectionRetryCount(0), pendingAsyncOperationCount(1),
targetUrl(NULL), targetUrlLength(0), childContext(NULL), isConnectionFromPool(FALSE), expectResponseBody(TRUE)
{
IHttpTraceContext* tctx;
LPCGUID pguid;
RtlZeroMemory(&this->asyncContext, sizeof(ASYNC_CONTEXT));
if (NULL != (tctx = context->GetTraceContext()) && NULL != (pguid = tctx->GetTraceActivityId()))
{
memcpy(&this->activityId, pguid, sizeof GUID);
}
else
{
CoCreateGuid(&this->activityId);
}
this->asyncContext.data = this;
}
CNodeHttpStoredContext::~CNodeHttpStoredContext()
{
if (INVALID_HANDLE_VALUE != this->pipe)
{
CloseHandle(this->pipe);
this->pipe = INVALID_HANDLE_VALUE;
}
}
IHttpContext* CNodeHttpStoredContext::GetHttpContext()
{
return this->context;
}
CNodeApplication* CNodeHttpStoredContext::GetNodeApplication()
{
return this->nodeApplication;
}
void CNodeHttpStoredContext::SetNextProcessor(LPOVERLAPPED_COMPLETION_ROUTINE processor)
{
this->asyncContext.completionProcessor = processor;
}
LPOVERLAPPED CNodeHttpStoredContext::GetOverlapped()
{
return &this->asyncContext.overlapped;
}
LPOVERLAPPED CNodeHttpStoredContext::InitializeOverlapped()
{
RtlZeroMemory(&this->asyncContext.overlapped, sizeof(OVERLAPPED));
return &this->asyncContext.overlapped;
}
void CNodeHttpStoredContext::CleanupStoredContext()
{
delete this;
}
CNodeProcess* CNodeHttpStoredContext::GetNodeProcess()
{
return this->process;
}
void CNodeHttpStoredContext::SetNodeProcess(CNodeProcess* process)
{
this->process = process;
}
ASYNC_CONTEXT* CNodeHttpStoredContext::GetAsyncContext()
{
return &this->asyncContext;
}
CNodeHttpStoredContext* CNodeHttpStoredContext::Get(LPOVERLAPPED overlapped)
{
return overlapped == NULL ? NULL : (CNodeHttpStoredContext*)((ASYNC_CONTEXT*)overlapped)->data;
}
HANDLE CNodeHttpStoredContext::GetPipe()
{
return this->pipe;
}
void CNodeHttpStoredContext::SetPipe(HANDLE pipe)
{
this->pipe = pipe;
}
DWORD CNodeHttpStoredContext::GetConnectionRetryCount()
{
return this->connectionRetryCount;
}
void CNodeHttpStoredContext::SetConnectionRetryCount(DWORD count)
{
this->connectionRetryCount = count;
}
void* CNodeHttpStoredContext::GetBuffer()
{
return this->buffer;
}
DWORD CNodeHttpStoredContext::GetBufferSize()
{
return this->bufferSize;
}
void** CNodeHttpStoredContext::GetBufferRef()
{
return &this->buffer;
}
DWORD* CNodeHttpStoredContext::GetBufferSizeRef()
{
return &this->bufferSize;
}
void CNodeHttpStoredContext::SetBuffer(void* buffer)
{
this->buffer = buffer;
}
void CNodeHttpStoredContext::SetBufferSize(DWORD bufferSize)
{
this->bufferSize = bufferSize;
}
DWORD CNodeHttpStoredContext::GetDataSize()
{
return this->dataSize;
}
DWORD CNodeHttpStoredContext::GetParsingOffset()
{
return this->parsingOffset;
}
void CNodeHttpStoredContext::SetDataSize(DWORD dataSize)
{
this->dataSize = dataSize;
}
void CNodeHttpStoredContext::SetParsingOffset(DWORD parsingOffset)
{
this->parsingOffset = parsingOffset;
}
LONGLONG CNodeHttpStoredContext::GetChunkTransmitted()
{
return this->chunkTransmitted;
}
LONGLONG CNodeHttpStoredContext::GetChunkLength()
{
return this->chunkLength;
}
void CNodeHttpStoredContext::SetChunkTransmitted(LONGLONG length)
{
this->chunkTransmitted = length;
}
void CNodeHttpStoredContext::SetChunkLength(LONGLONG length)
{
this->chunkLength = length;
}
BOOL CNodeHttpStoredContext::GetIsChunked()
{
return this->isChunked;
}
void CNodeHttpStoredContext::SetIsChunked(BOOL chunked)
{
this->isChunked = chunked;
}
void CNodeHttpStoredContext::SetIsLastChunk(BOOL lastChunk)
{
this->isLastChunk = lastChunk;
}
BOOL CNodeHttpStoredContext::GetIsLastChunk()
{
return this->isLastChunk;
}
HRESULT CNodeHttpStoredContext::GetHresult()
{
return this->result;
}
void CNodeHttpStoredContext::SetHresult(HRESULT result)
{
this->result = result;
}
REQUEST_NOTIFICATION_STATUS CNodeHttpStoredContext::GetRequestNotificationStatus()
{
return this->requestNotificationStatus;
}
void CNodeHttpStoredContext::SetRequestNotificationStatus(REQUEST_NOTIFICATION_STATUS status)
{
this->requestNotificationStatus = status;
}
GUID* CNodeHttpStoredContext::GetActivityId()
{
return &this->activityId;
}
long CNodeHttpStoredContext::IncreasePendingAsyncOperationCount()
{
return InterlockedIncrement(&this->pendingAsyncOperationCount);
}
long CNodeHttpStoredContext::DecreasePendingAsyncOperationCount()
{
return InterlockedDecrement(&this->pendingAsyncOperationCount);
}
PCSTR CNodeHttpStoredContext::GetTargetUrl()
{
return this->targetUrl;
}
DWORD CNodeHttpStoredContext::GetTargetUrlLength()
{
return this->targetUrlLength;
}
void CNodeHttpStoredContext::SetTargetUrl(PCSTR targetUrl, DWORD targetUrlLength)
{
this->targetUrl = targetUrl;
this->targetUrlLength = targetUrlLength;
}
void CNodeHttpStoredContext::SetChildContext(IHttpContext* context)
{
this->childContext = context;
}
IHttpContext* CNodeHttpStoredContext::GetChildContext()
{
return this->childContext;
}
BOOL CNodeHttpStoredContext::GetIsConnectionFromPool()
{
return this->isConnectionFromPool;
}
void CNodeHttpStoredContext::SetIsConnectionFromPool(BOOL fromPool)
{
this->isConnectionFromPool = fromPool;
}
void CNodeHttpStoredContext::SetExpectResponseBody(BOOL expect)
{
this->expectResponseBody = expect;
}
BOOL CNodeHttpStoredContext::GetExpectResponseBody()
{
return this->expectResponseBody;
}