Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2016-09

Socket error when shutting down fpHttpServer

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Reimar Grabowski

Hi,

here is the code (FPC 3.0.0):

var
  Server: TMyServer;
procedure HandleSig(sig : cint); cdecl;
begin
  writeln('SIGTERM received');
  if (Assigned(Server)) then begin
    Server.Active:=False;
  end;
end;
begin
  FpSignal(SIGTERM, signalhandler(@HandleSig));
  Server:=TMyServer.Create(nil);
  try
    Server.Port:=12345;
    WriteLn('Start server');
    Server.Active:=True;
  finally
    writeln('Free server');
    FreeAndNil(Server);
    writeln('Server freed: ',Server=nil);
  end;
  writeln('Done');
end.

Here the output:

Start server
SIGTERM received
Free server
Server freed: TRUE
An unhandled exception occurred at $00000000004D05C9: ESocketError: Could not accept a client connection on socket: 3, error 22

How am I supposed to stop the server?
I installed the signal handler since 'Server.Active:=True' is blocking and I want to use the heaptrc unit (btw setting active to false inside the servers HandleRequest procedure works but that's not the road I want to take).

tia
R.