Event-driven threads

Threads that control client connections are event-driven. A request for action triggers a server event. See “Events” for details on events.

When a client event occurs, Open Server places the event in the thread’s event queue. The next time the thread executes, it reads the next event request from the event queue. Open Server calls the event handler associated with this event. When the handler returns, the thread attempts to read the next event in the queue. If there is no event, the thread “sleeps.”

For example, when a client application attempts to log in to the server, Open Server creates a thread to handle the connection and puts the SRV_CONNECT event in the threads queue. When the thread runs, it executes the routine installed to handle the SRV_CONNECT event. The default handler simply accepts the connection. You could install a custom SRV_CONNECT handler that checks the login name and password, and, if both are valid, allows the user to log in.

Event-driven threads exist primarily to handle client requests, but they can also be used with programmer-defined events to execute service routines within the server.