Recent

Author Topic: SOLVED Embedded http server and worker (background) thread  (Read 2123 times)

Renat.Su

  • Full Member
  • ***
  • Posts: 232
    • Renat.Su
SOLVED Embedded http server and worker (background) thread
« on: September 27, 2018, 01:53:18 pm »
I have developed HTTP embedded server with Brook Framework. In addition to TBrookAction (offtop: actually I did not understand - its are executed  in a separate thread or in one awaiting for the queue) for user interaction via HTTP I have a background/worker thread to perform some continuous and periodical actions.
This worker thread is now starting in the unit initialization section and frees (so if app is terminated by user) in finalization section. Everything works. But...
I would like to have more control over the application via SSH: [auto]start, stop, restart, maybe something else. As I understand it I need to do not just the HTTP server but a daemon HTTP server.
And then there is the question whether it is possible to keep the run worker thread in the initialization part of the unit or need the start and stop of processing inside a class instance TBrookHttpDaemon. But how do I do that then?
« Last Edit: November 11, 2018, 08:52:17 am by Renat.Su »

Renat.Su

  • Full Member
  • ***
  • Posts: 232
    • Renat.Su
Re: SOLVED Embedded http server and worker (background) thread
« Reply #1 on: November 11, 2018, 08:58:32 am »
I have encountered an error when stopping the daemon.
Code: [Select]
Error in my_thread_global_end(): 1 threads didn't exitIt turned out that the problem was not in the worker thread but the use of the MySQL DB connector. I used one connection in a multithreaded connection. In the new version, I started using a separate MySQL connection for each thread (TBRookAction, Worker thread) and everything is fine now.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: SOLVED Embedded http server and worker (background) thread
« Reply #2 on: November 11, 2018, 08:40:02 pm »
offtop: actually I did not understand - its are executed  in a separate thread or in one awaiting for the queue
By default, it runs in single process. To make every request handled as separate thread, add this code before BrookApp.Run:
Code: Pascal  [Select][+][-]
  1. (BrookApp.Instance as TBrookHTTPApplication).Threaded := true;
  2.  
I would like to have more control over the application via SSH: [auto]start, stop, restart, maybe something else. As I understand it I need to do not just the HTTP server but a daemon HTTP server.
I would add protected endpoints instead of using daemon.
And then there is the question whether it is possible to keep the run worker thread in the initialization part of the unit or need the start and stop of processing inside a class instance TBrookHttpDaemon. But how do I do that then?
Not really get this.

 

TinyPortal © 2005-2018