@@ -15,6 +15,7 @@ interface
1515
1616uses
1717
18+ SyncObjs,
1819 RunnableIntf,
1920 RunnableWithDataNotifIntf,
2021 ProtocolProcessorIntf,
@@ -38,6 +39,7 @@ interface
3839 *-----------------------------------------------*)
3940 TFpwebProcessor = class (TInterfacedObject, IProtocolProcessor, IRunnable, IRunnableWithDataNotif)
4041 private
42+ fLock : TCriticalSection;
4143 fStdIn : IStreamAdapter;
4244 fRequestReadyListener : IReadyListener;
4345 fDataListener : IDataAvailListener;
@@ -75,6 +77,7 @@ TFpwebProcessor = class(TInterfacedObject, IProtocolProcessor, IRunnable, IR
7577
7678 public
7779 constructor create(
80+ const lock : TCriticalSection;
7881 const conn : IFpwebResponseAware;
7982 const svrConfig : TFpwebSvrConfig
8083 );
@@ -179,10 +182,12 @@ THttpServerThread = class(TThread)
179182 end ;
180183
181184 constructor TFpwebProcessor.create(
185+ const lock : TCriticalSection;
182186 const conn : IFpwebResponseAware;
183187 const svrConfig : TFpwebSvrConfig
184188 );
185189 begin
190+ fLock := lock;
186191 fConnection := conn;
187192 fStdIn := nil ;
188193 fRequestReadyListener := nil ;
@@ -198,6 +203,7 @@ THttpServerThread = class(TThread)
198203 fRequestReadyListener := nil ;
199204 fStdIn := nil ;
200205 fConnection := nil ;
206+ fLock := nil ;
201207 inherited destroy();
202208 end ;
203209
@@ -264,15 +270,32 @@ THttpServerThread = class(TThread)
264270 var fpwebEnv : ICGIEnvironment;
265271 begin
266272 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 ;
276299 end ;
277300
278301 procedure TFpwebProcessor.handleRequest (
0 commit comments