Recent

Author Topic: How to terminate a THttpAplication?  (Read 1006 times)

zen010101

  • Newbie
  • Posts: 4
How to terminate a THttpAplication?
« on: July 17, 2024, 07:54:44 pm »
My program wants to exit normally after Ctrl-C is pressed, but I haven't been able to accomplish this under FPC 3.22/3.3.1. The following is a sample program fragment from the official (...\fpcsrc\packages\fcl-web\examples\httpapp, I only added the code to respond to Ctrl-C)

Code: Pascal  [Select][+][-]
  1. procedure signalHandler(signum: cint); cdecl;
  2. begin
  3.   if (signum = SIGTERM) or (signum = SIGINT) then
  4.   begin
  5.     Writeln('Exiting');
  6.     Application.Terminate;  // can not quit the application
  7.     //Raise Exception.Create('EXIT THE APPLICATION'); // this can exit the THttpApplication normally, you will see 'Done' output to the console.
  8.   end;
  9. end;
  10.  
  11. begin
  12.   // Register SignalHandler
  13.   fpSignal(SIGINT, @signalHandler);
  14.   .
  15.   .
  16.   .
  17.   Application.Initialize;
  18.   Application.Port:=StrTointDef(ParamStr(2),8384);
  19.   Application.Title:='HTTP Demo application';
  20.   Application.Run;
  21.   Writeln('Done');
  22. end.
  23.  

I noticed a bug report which was committed 4 years ago (https://gitlab.com/freepascal.org/fpc/source/-/issues/36741#original-reporter-info-from-mantis-luca-olivlucareporter-name-luca-olivetti), but until now it is still there too.
« Last Edit: July 20, 2024, 07:59:52 pm by zen010101 »

PascalDragon

  • Hero Member
  • *****
  • Posts: 5755
  • Compiler Developer
Re: How to terminate a THttpAplication?
« Reply #1 on: July 18, 2024, 09:31:03 pm »
```pascal
[...]
```

The forum does not use Markdown, but BBCodes, in this case [code=pascal][/code].

 

TinyPortal © 2005-2018