[fpc-pascal] fphttpserver: reduce the stack size of the thread spawned for threaded server

Luca Olivetti luca at ventoso.org
Mon May 18 22:17:25 CEST 2026


El 18/5/26 a les 22:05, Luca Olivetti via fpc-pascal ha escrit:
> El 18/5/26 a les 21:59, Michael Van Canneyt via fpc-pascal ha escrit:
> 
>>>
>>> what other options do I have?
>>
>> At this moment, none. The best I can do is add a class variable to 
>> allow you to
>> set its class-type value to a TFPHTTPConnectionThread class descendant,
>> then that descendant would be used. Then you set this variable at the 
>> start.
>>
>> Another option is to create a ConnectionThreadStackSize variable that 
>> would
>> be used to set the stack size.
> 
> Thank you, but both options would require an upgraded fpc/fcl, in that 
> case I could simply modify my copy of fphttpserver.pp to use a different 
> stack size.
> I'll see if I find a way of changing the stack size while keeping the 
> fpc3.2.2 sources pristine.

Since the FConnectionThreadList is only used in the destructor to force 
close the socket I can either override the destructor and use local list 
in my derived class or simply call 
TFPHttpConnectionThread.CreateConnection without the 
FConnectionThreadList and see what happens...but the 
WaitForRequests(High(Integer)) worries me:

destructor TFPCustomHttpServer.Destroy;
var
   ThreadList: TList;
   I: Integer;
begin
   Active:=False;
   if Threaded and (FConnectionCount>0) then
   begin
     // first wait for open requests to finish and get closed automatically
     WaitForRequests;
     // force close open sockets
     ThreadList:=FConnectionThreadList.LockList;
     try
       for I:= ThreadList.Count-1 downto 0 do
  
CloseSocket(TFPHTTPConnectionThread(ThreadList[I]).Connection.Socket.Handle);
     finally
       FConnectionThreadList.UnlockList;
     end;
     // all requests must be destroyed - wait infinitely
     WaitForRequests(High(Integer));
   end;
   FreeAndNil(FConnectionThreadList);
   FreeAndNil(FCertificateData);
   inherited Destroy;
end;


In that case I could simply override the destructor with one does 
nothing other than setting Active to false. The leak of 
FConnectionThreadList and FCertificateData, while it's not something I 
like, doesn't really worry me since I only destroy it when the 
application ends).

Bye
-- 
Luca



More information about the fpc-pascal mailing list