Recent

Author Topic: TSimpleIPCServer and Threads, again  (Read 4380 times)

21347

  • New member
  • *
  • Posts: 7
TSimpleIPCServer and Threads, again
« on: September 04, 2012, 12:59:26 pm »
Hi there.

I got the following problem: I've two apps that are both communicating using TSimpleIPCServer (ok, is more like one app is constantly sending data to annother).

The problem is, that the data is indeed not much in terms of overall size, but split up to many, many small parts.
Using the standard implementation of TSimpleIPCServer (im on Windows right now, using Laz. 1.0 x64) you can either wait for a message on the main thread (just droppin the component on the form and create an OnMessage-Event - which causes the Client to stall on each UI-based action in the server), or create the Component in another thread and poll.

Where the latter is incredibly fast, it uses as many CPU resources as available, obviously.

I tried now to implement my own version of TIPCServerComm, which should work I hope (and would result in an own MessageLoop in the Thread owning the comm. window, which - I hope - would enable me to use GetMessage instead of PeekMessage to save CPU resources) - but I cannot access some Protected Methods and Variables in TSimpleIPCServer to implement the ReadMessage() mechanics.

There's a simmilar discussion filed as bug #0019136 (http://bugs.freepascal.org/view.php?id=19136), but it only applies to Unix-like OSes (and was indeed fixed for them).

Should I file another bug for the WinXX-Platform / try to create a patch for it - or is there any other favoured solution?

BTW: Packing multiple messages in one could be done, but I'd like to get every message sent over at once, trying to avoid loosing a whole bunch of them when the program crashes, I'm using that for debugging.

Thanks for any help!

eny

  • Hero Member
  • *****
  • Posts: 1634
Re: TSimpleIPCServer and Threads, again
« Reply #1 on: September 04, 2012, 07:58:59 pm »
The problem is, that the data is indeed not much in terms of overall size, but split up to many, many small parts.
Using the standard implementation of TSimpleIPCServer (im on Windows right now, using Laz. 1.0 x64) you can either wait for a message on the main thread (just droppin the component on the form and create an OnMessage-Event - which causes the Client to stall on each UI-based action in the server), or create the Component in another thread and poll.
Or create the component in another thread, wait for an OnMessage event and then synchronize with the main thread.
Not sure what your real question is.
All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

21347

  • New member
  • *
  • Posts: 7
Re: TSimpleIPCServer and Threads, again
« Reply #2 on: September 04, 2012, 09:13:07 pm »
Or create the component in another thread, wait for an OnMessage event and then synchronize with the main thread.
Not sure what your real question is.

Yes, well, in fact that's what I would do - but as soon as the thread exits, the component is lost. So I have to enshure that the thread is kept running - somehow set him waiting, but not using resources...

Would Some kind of MsgWaitForSingleObject and a Post/SendMessage in OnMessage work? Just came to my mind...

eny

  • Hero Member
  • *****
  • Posts: 1634
Re: TSimpleIPCServer and Threads, again
« Reply #3 on: September 05, 2012, 05:59:58 pm »
Ah, see what you mean.
Wouldn't know how to solve it with the standard IPC component.
Did something like this in the past but by directly using the socket components (and they used blocking calls so the thread was put to sleep until a message was received).
All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

 

TinyPortal © 2005-2018