This page describes how the library is structured and where the hot path may work differently from the rest of the code. The rules apply to all code in this repository; CONTRIBUTING.md describes the general style.
- One type with behaviour per unit. Records that belong to a single class (options,
slots, results) go into
<Unit>.Types, for exampleWebSocket4D.Tls.Types. - Folders are layers.
Source/Coreuses only the RTL;Source/Tlsuses Core; backends inSource/Tls/<Backend>use Core and Tls;Source/Clientmay use all of them. Never add ausesthat points the other way. - Exception classes are grouped in
WebSocket4D.Exceptions. They are a small hierarchy with no behaviour beyond building their message, and callers catch them together. - Test units live in
Tests/<Folder>, mirroringSource/<Folder>. Consumers add theSourcefolders to their search path, and test units must not end up there.
The exceptions below apply only where stated. Everywhere else (handshake, URL parsing, options, events, samples, tests), the general style applies.
- Pointers and pointer arithmetic on the hot path: frame parsing, masking, UTF-8 validation, inflate/deflate (zlib and zstd), SPSC queue and socket I/O. Reason: zero-copy parsing and word-at-a-time loops.
varparameters for growable buffers passed into hot-path helpers. Reason:SetLengthmay move the array and the caller must see the new reference. Avarparameter is passed by address, so it copies nothing.- Comments only where they document how a protocol is implemented (RFC 6455, RFC 7692, the zlib-stream and zstd-stream formats) or something important that code cannot express: cache-line layout, memory ordering, thread ownership, buffer lifetime. API descriptions that restate the signature are not allowed.
- No framework dependencies;
TArray<T>/SetLengthfor collections. Reason: the hot path needs flat arrays, and a transport library should not force a framework on consumers. on E: Exceptionwithout re-raise at thread entry points and around user callbacks. Reason: an exception escaping a worker thread or a user handler must not kill the connection silently; it is reported throughOnErroror turned into a close code.- Cracker classes for TLS handles:
TTaurusTLSSocketAccess(WebSocket4D.Tls.TaurusTLS.Access), andTIdSSLSocketAccesswithTIdSSLContextAccess(WebSocket4D.Tls.Indy.Access; two crackers in one unit, as they open up one library). Reason: TaurusTLS and Indy keep thePSSLandSSL_CTXhandles protected. The TLS sessions needPSSLfor direct non-blockingSSL_read/SSL_write, and the Indy backend needsSSL_CTXto load the Windows root store. Re-check on every TaurusTLS or Indy upgrade.