[Lazarus] lnet sockets, ´"eventer"

Bernd prof7bit at gmail.com
Thu Oct 25 12:31:19 CEST 2012

2012/10/25 Michael Schnell <mschnell at lumino.de>:

> Some questions:
>  - Can such an "eventer" be used in the main thread and in worker threads ?
>  - If used in the main thread, can the "eventer" decently coexist with LCL
> based Events (such as TTimer, GIU, QueueAsyncCall, ...),
>  - If Yes: How ?

The eventer that is used by default when putting an lnet component
onto an LCL form is different from the other eventers that lnet
provides. This one is tightly integrated into the LCL and fires its
event from the main thread, just like button clicks and other GUI
events. No sleeping and blocking is required here by your application
and no worker threads.

All other eventers (select, epoll, kqueue) are only meant to be used
when you explicitly not want the events to be generated by the LCL
main thread, for example when there is no LCL at all because you are
writing a command line program or using a different GUI framework for
which no lnet eventer has been written (yet). These eventers always
block. They have a timeout, so you can make them wake up every x
milliseconds but still they block all of the time. So the usual way to
use them is a separate thread that does nothing other than to wait in
a CallAction() call. All the OnXxxx methods of your socket objects
will then be called from within that thread and you need to take care
of that fact when talking to the main thread. Thats the reason you
should use the existing LCL eventers when you have LCL in your
application, they will free you from all this trouble.

More information about the Lazarus mailing list