On Mon, 28 Nov 2011, Graeme Geldenhuys wrote:

On 28/11/2011, michael.vancann...@wisa.be <michael.vancanneyt@w.....> wrote:

If so, that's a pretty dumb design.

Ah. And why is that so ?

Now it's much less useful.

How are you supposed to "correctly" terminate the HTTP Server once
Active = True is called?

1. From a request.
2. From the main thread if the component is set to active in a thread.

If you want still to have a "main program", you should use a thread and
create the component in the thread. Which is exactly what happens in a
service application, the intended environment for the component.

I fail to see how this will resolve the problem, but that could be
contributed to my lack of experience with service-style projects. None
the less, I'll adapt my very simple test project and create the server
instance inside a thread, and see how it goes. Like I said, I still
can't see how you can cleanly terminate the HTTP server, because it
will never give the thread a chance to look at the value of
TThread.Terminated?

The mistake you make is that you create a loop in the thread; The thread does not need a loop. It just needs to set Active to true:

Procedure TMyServerThread.Execute;

begin
  MyServer.Active:=True;
end;

As soon as a request or the main thread sets active to false, the statement
will return and the thread will terminate.

To terminate the server, you should not set the thread to terminated, but set

MyServerThread.MyServer.Active:=False;

or implement

Procedure TMyServerThread.StopServer;

begin
  MyServer.Active:=False;
end;

and call

MyServerThread.StopServer;

Since this will happen from another thread or from a request handler,
you can do this without problem.

Michael.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to