@@ -15,6 +15,7 @@ interface
15
15
16
16
uses
17
17
18
+ SyncObjs,
18
19
RunnableIntf,
19
20
RunnableWithDataNotifIntf,
20
21
ProtocolProcessorIntf,
@@ -38,6 +39,7 @@ interface
38
39
*-----------------------------------------------*)
39
40
TFpwebProcessor = class (TInterfacedObject, IProtocolProcessor, IRunnable, IRunnableWithDataNotif)
40
41
private
42
+ fLock : TCriticalSection;
41
43
fStdIn : IStreamAdapter;
42
44
fRequestReadyListener : IReadyListener;
43
45
fDataListener : IDataAvailListener;
@@ -75,6 +77,7 @@ TFpwebProcessor = class(TInterfacedObject, IProtocolProcessor, IRunnable, IR
75
77
76
78
public
77
79
constructor create(
80
+ const lock : TCriticalSection;
78
81
const conn : IFpwebResponseAware;
79
82
const svrConfig : TFpwebSvrConfig
80
83
);
@@ -179,10 +182,12 @@ THttpServerThread = class(TThread)
179
182
end ;
180
183
181
184
constructor TFpwebProcessor.create(
185
+ const lock : TCriticalSection;
182
186
const conn : IFpwebResponseAware;
183
187
const svrConfig : TFpwebSvrConfig
184
188
);
185
189
begin
190
+ fLock := lock;
186
191
fConnection := conn;
187
192
fStdIn := nil ;
188
193
fRequestReadyListener := nil ;
@@ -198,6 +203,7 @@ THttpServerThread = class(TThread)
198
203
fRequestReadyListener := nil ;
199
204
fStdIn := nil ;
200
205
fConnection := nil ;
206
+ fLock := nil ;
201
207
inherited destroy();
202
208
end ;
203
209
@@ -264,15 +270,32 @@ THttpServerThread = class(TThread)
264
270
var fpwebEnv : ICGIEnvironment;
265
271
begin
266
272
fConnection.response := response;
267
- fpwebEnv := buildEnv(request);
268
-
269
- fRequestReadyListener.ready(
270
- // we will not use socket stream as we will have our own IStdOut
271
- // that write output with TFpHttpServer
272
- TNullStreamAdapter.create(),
273
- fpwebEnv,
274
- TStreamAdapter.create(TStringStream.create(request.content))
275
- );
273
+ if (fSvrConfig.threaded) then
274
+ begin
275
+ fLock.acquire();
276
+ try
277
+ fpwebEnv := buildEnv(request);
278
+ fRequestReadyListener.ready(
279
+ // we will not use socket stream as we will have our own IStdOut
280
+ // that write output with TFpHttpServer
281
+ TNullStreamAdapter.create(),
282
+ fpwebEnv,
283
+ TStreamAdapter.create(TStringStream.create(request.content))
284
+ );
285
+ finally
286
+ fLock.release();
287
+ end ;
288
+ end else
289
+ begin
290
+ fpwebEnv := buildEnv(request);
291
+ fRequestReadyListener.ready(
292
+ // we will not use socket stream as we will have our own IStdOut
293
+ // that write output with TFpHttpServer
294
+ TNullStreamAdapter.create(),
295
+ fpwebEnv,
296
+ TStreamAdapter.create(TStringStream.create(request.content))
297
+ );
298
+ end ;
276
299
end ;
277
300
278
301
procedure TFpwebProcessor.handleRequest (
0 commit comments