#1 2014-06-25 20:29:27

dorival
Member
From: Brasil
Registered: 2013-04-17
Posts: 35

how is the best way to stop a HTTP server?

Hi,
I have one server (http api) and n clients.
My server is based on TSQLHttpServer, my client is based on TSQLHttpClient and some services that are consumed by clients.

Sometimes I need to stop de server, but I cannot just kill the server, 'cause maybe some important process are runing.

To stop the server I implemented:
- delete all users to stop new connections;
- wait that all request finished;
- and finally, freeandnil on my server object.

Below my code:

procedure TMyServer.StopServer;
var
  oSQLAuthUser: TSQLAuthUser;
begin
  oSQLAuthUser := TSQLAuthUser.Create;
  try
    oSQLAuthUser.FillPrepare(oSQLRestServerFullMemory);
    while (oSQLAuthUser.FillOne) do
      oSQLRestServerFullMemory.Delete(TSQLAuthUser, oSQLAuthUser.ID); // delete all users. This way I stop new clients connections.
  finally
    oSQLAuthUser.Free;
  end;
    while fDBServers[0].Server.Stats.ClientsCurrent > 0 do // until have clients, just wait...
      sleep(1000);
end;

And ...

procedure TMyServerAPP.StopServer;
begin
  fMyServer.StopServer;
  FreeAndNil(fMyServer);
end;

It's work... but I imagine that's not the best way to do this... Someone have any suggestion?
Thanks by your attention,

Dorival

Last edited by dorival (2014-06-25 20:30:23)

Offline

#2 2014-06-25 21:17:03

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,273
Website

Re: how is the best way to stop a HTTP server?

Could you add a feature request as ticket, so that we implement a clean "shutdown" of a running server?

Offline

#3 2014-06-26 11:58:24

dorival
Member
From: Brasil
Registered: 2013-04-17
Posts: 35

Re: how is the best way to stop a HTTP server?

of course, it's done.

Thanks

Offline

#4 2014-06-26 15:03:15

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,273
Website

Re: how is the best way to stop a HTTP server?

It has just been implemented as TSQLRestServer.Shutdown and TSQLHttpServer.Shutdown methods.
See http://synopse.info/fossil/info/4d4d2be … 8b328ae483

Offline

#5 2014-06-26 20:32:09

dorival
Member
From: Brasil
Registered: 2013-04-17
Posts: 35

Re: how is the best way to stop a HTTP server?

Thank you AB.

Offline

#6 2014-06-27 04:00:55

Chaa
Member
Registered: 2011-03-26
Posts: 245

Re: how is the best way to stop a HTTP server?

A small note:
More correctly "shutting down", with two letters t.

Offline

#7 2014-06-27 08:10:28

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,273
Website

Re: how is the best way to stop a HTTP server?

Typo is fixed.
Thanks!

Offline

Board footer

Powered by FluxBB