TsgcWebSocketHTTPServer › Properties › QueueOptions

QueueOptions Property

Serialises outbound messages through an internal per-connection queue to prevent contention between threads.

Syntax

property QueueOptions: TsgcWSQueueServer_Options read FQueueOptions write SetQueueOptions;

Default Value

Text.Level=qmNone, Binary.Level=qmNone, Ping.Level=qmNone, DrainedMode=qdmTransition

Remarks

When enabled, messages are placed in an internal queue and sent in the context of the connection thread instead of the caller's thread — this removes the locking needed when several threads write to the same connection simultaneously. Each message type (Text, Binary, Ping) is a sub-object with its own Level property, which assigns an independent priority: qmNone skips the queue (default), qmLevel0 is processed first, then qmLevel1 and finally qmLevel2. For example, setting Text.Level and Binary.Level to qmLevel2 and Ping.Level to qmLevel1 guarantees pings are delivered before ordinary traffic. QueueOptions is only supported by the default IOHandler. When IOHandlerOptions.IOHandlerType is iohIOCP or iohEPOLL the queue is switched off as the server starts: the three levels are reset to qmNone, the OnError event reports it, and messages are written inline on the caller thread. A level assigned after the server is already listening is reset the same way on every new connection.

DrainedMode selects when the OnQueueDrained event is raised. With qdmTransition (default) the event fires once each time the outgoing queue of a connection goes from holding messages to being empty. With qdmEveryPass it fires on every pass of the connection loop, right after the queues are sent, even when the queue was already empty and even when Text.Level, Binary.Level and Ping.Level are all qmNone, so no dummy queue level is needed. It is useful as a per-connection hook that runs on the connection own thread, for example to send pending application data with WriteData. The event does not follow NotifyEvents, so the handler must be fast and must not touch the user interface. Only the default IOHandler has this loop, with iohIOCP and iohEPOLL the event is never raised per pass. Each connection copies the queue options when it connects, so set DrainedMode before activating the component, connections already open keep the previous mode.

Example


oServer := TsgcWebSocketHTTPServer.Create(nil);
oServer.QueueOptions.Text.Level := qmLevel2;
oServer.QueueOptions.Binary.Level := qmLevel2;
oServer.QueueOptions.Ping.Level := qmLevel1;
oServer.Active := true;

Back to Properties