[fpc-pascal] Socket error when shutting down fpHttpServer
Reimar Grabowski
reimgrab at web.de
Thu Sep 29 17:59:28 CEST 2016
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.
More information about the fpc-pascal
mailing list