← All compilation units

Flyology.IO.Connections.TLS

Description

Adds ownership-preserving TLS to an admitted connection.

Finish

procedure Finish (Operation : in out Upgrade_Operation)

Consume a terminal TLS upgrade, close Item when a failed started handshake retained that obligation, and raise the familiar error. The same nonblocking close transfer runs for generic Consume and controlled finalization. Other operations registered on Item observe closing state and complete the deferred close when the last withdraws.

Parameters
Operation

Terminal TLS upgrade operation

Selected_Protocol

function Selected_Protocol (Item : in out Connection) return String

Read the peer's ALPN selection under Item's operation lease. Call this after the ALPN Upgrade overload succeeds. An empty String means that the peer made no selection.

Parameters
Item

Open ALPN-upgraded connection

Return value

Selected opaque protocol identifier or an empty String

Raised exceptions
Operation_Cancelled

Concurrent Close interrupts the query

TLS_Error

Flyology.IO.TLS.TLS_Error is raised when the session lacks the ALPN capability

Program_Error

Item is closed or still plaintext

Shutdown

procedure Shutdown
  (Item : in out Connection; Timeout : Duration := Infinite; Token : access Cancellation_Token := null)

Complete a bidirectional close_notify exchange without closing Item or releasing its admission permit. Repeating Shutdown after success is harmless. Close remains the terminal ownership operation.

Parameters
Item

Open connection whose transport uses TLS

Timeout

Shared shutdown deadline in seconds

Token

Optional one-shot token that must outlive the call

Raised exceptions
Operation_Cancelled

Shutdown, Token, or concurrent Close interrupts the operation

Timeout_Error

Flyology.IO.Timeout_Error is raised when the shared deadline expires

Device_Error

Flyology.IO.Device_Error is raised when readiness polling fails

TLS_Error

Flyology.IO.TLS.TLS_Error is raised when the provider or peer fails shutdown

Program_Error

Item is closed or still plaintext

Upgrade

function Upgrade
  (Set         : not null access Flyology.Operations.Completion_Set'Class;
   Item        : not null access Connection'Class;
   Backend     : not null access Flyology.IO.TLS.ALPN.Provider'Class;
   Side        : Flyology.IO.TLS.Role;
   Server_Name : String;
   Protocols   : Flyology.IO.TLS.ALPN.Protocol_List;
   Timeout     : Duration := Infinite;
   Token       : access Cancellation_Token := null) return Upgrade_Operation

Start an ALPN-capable TLS upgrade. Protocols is consumed during eager provider setup and need not outlive initiation; all other behavior matches the core scoped Upgrade.

Parameters
Set

Completion set that owns the operation slot

Item

Open plaintext admitted connection

Backend

Initialized ALPN-capable provider

Side

Client or server handshake role

Server_Name

Verified client DNS name or empty server name

Protocols

Ordered client offer or an empty list

Timeout

Shared lease, setup, and handshake deadline

Token

Optional cancellation source that outlives the operation

Return value

Started limited TLS upgrade operation

Upgrade

function Upgrade
  (Set         : not null access Flyology.Operations.Completion_Set'Class;
   Item        : not null access Connection'Class;
   Backend     : not null access Flyology.IO.TLS.Provider'Class;
   Side        : Flyology.IO.TLS.Role;
   Server_Name : String;
   Timeout     : Duration := Infinite;
   Token       : access Cancellation_Token := null) return Upgrade_Operation

Start a core TLS upgrade without suspending the owner task. Item and Backend are borrowed through provider setup; Item remains borrowed until typed Finish or finalization. A failure after the transport transition becomes terminal without closing from the driver. Typed Finish, generic Consume, or controlled finalization transfers the mandatory close to Item; the last registered operation to withdraw completes it.

Parameters
Set

Completion set that owns the operation slot

Item

Open plaintext admitted connection

Backend

Initialized TLS provider

Side

Client or server handshake role

Server_Name

Verified client DNS name or empty server name

Timeout

Shared lease, setup, and handshake deadline

Token

Optional cancellation source that outlives the operation

Return value

Started limited TLS upgrade operation

Upgrade

procedure Upgrade
  (Item        : in out Connection;
   Backend     : in out Flyology.IO.TLS.ALPN.Provider'Class;
   Side        : Flyology.IO.TLS.Role;
   Server_Name : String;
   Protocols   : Flyology.IO.TLS.ALPN.Protocol_List;
   Timeout     : Duration := Infinite;
   Token       : access Cancellation_Token := null)

Replace Item's plaintext transport with an ALPN-capable TLS session and complete its handshake. Ownership, deadline, cancellation, and failure behavior match the core Upgrade overload. Protocol identifiers are offered in list order; an empty list sends no ALPN extension.

Parameters
Item

Open plaintext admitted connection

Backend

Initialized ALPN-capable TLS provider

Side

Client or server handshake role

Server_Name

Verified DNS name for clients; empty for servers

Protocols

Ordered client offer or an empty list

Timeout

Shared upgrade deadline in seconds

Token

Optional one-shot token that must outlive the call

Raised exceptions
Operation_Cancelled

Shutdown, Token, or concurrent Close interrupts the upgrade

Timeout_Error

Flyology.IO.Timeout_Error is raised when the shared deadline expires

Device_Error

Flyology.IO.Device_Error is raised when readiness polling fails

TLS_Error

Flyology.IO.TLS.TLS_Error is raised when provider setup or the handshake fails

Socket_Error

Flyology.IO.Sockets.Socket_Error is raised when socket preparation or close fails

Program_Error

Item is closed, already uses TLS, or arguments do not match Side

Upgrade

procedure Upgrade
  (Item        : in out Connection;
   Backend     : in out Flyology.IO.TLS.Provider'Class;
   Side        : Flyology.IO.TLS.Role;
   Server_Name : String;
   Timeout     : Duration := Infinite;
   Token       : access Cancellation_Token := null)

Replace Item's plaintext transport with a provider session and complete its TLS handshake over the same socket. Item retains its admission permit and remains the sole closing owner. One deadline covers waiting for Item's operation lease, provider setup, and all handshake retries. Provider setup calls are synchronous and are not preempted; expiration during setup is observed as soon as the provider returns. A zero timeout still permits setup and immediately available handshake progress, but never waits for readiness. Once the transport enters the upgrade state, any failure closes Item; plaintext fallback must be selected before calling Upgrade. Plaintext operations queued before the transition are cancelled rather than run against the TLS transport. Lightweight callers suspend on readiness; native callers block only their pthread.

Parameters
Item

Open plaintext admitted connection

Backend

Initialized TLS provider

Side

Client or server handshake role

Server_Name

Verified DNS name for clients; empty for servers

Timeout

Shared upgrade deadline in seconds

Token

Optional one-shot token that must outlive the call

Raised exceptions
Operation_Cancelled

Shutdown, Token, or concurrent Close interrupts the upgrade

Timeout_Error

Flyology.IO.Timeout_Error is raised when the shared deadline expires

Device_Error

Flyology.IO.Device_Error is raised when readiness polling fails

TLS_Error

Flyology.IO.TLS.TLS_Error is raised when provider setup or the handshake fails

Socket_Error

Flyology.IO.Sockets.Socket_Error is raised when socket preparation or close fails

Program_Error

Item is closed, already uses TLS, or arguments do not match Side

Upgrade

procedure Upgrade
  (Item        : not null access Connection'Class;
   Backend     : not null access Flyology.IO.TLS.ALPN.Provider'Class;
   Side        : Flyology.IO.TLS.Role;
   Server_Name : String;
   Protocols   : Flyology.IO.TLS.ALPN.Protocol_List;
   Timeout     : Duration := Infinite;
   Token       : access Cancellation_Token := null;
   Operation   : in out Upgrade_Operation)

Start or restart an ALPN-capable TLS upgrade.

Parameters
Item

Open plaintext admitted connection

Backend

Initialized ALPN-capable provider

Side

Client or server handshake role

Server_Name

Verified client DNS name or empty server name

Protocols

Ordered client offer or an empty list

Timeout

Shared lease, setup, and handshake deadline

Token

Optional cancellation source that outlives the operation

Operation

Fresh, released, or consumed upgrade operation

Upgrade

procedure Upgrade
  (Item        : not null access Connection'Class;
   Backend     : not null access Flyology.IO.TLS.Provider'Class;
   Side        : Flyology.IO.TLS.Role;
   Server_Name : String;
   Timeout     : Duration := Infinite;
   Token       : access Cancellation_Token := null;
   Operation   : in out Upgrade_Operation)

Start or restart a core TLS upgrade in an established operation object.

Parameters
Item

Open plaintext admitted connection

Backend

Initialized TLS provider

Side

Client or server handshake role

Server_Name

Verified client DNS name or empty server name

Timeout

Shared lease, setup, and handshake deadline

Token

Optional cancellation source that outlives the operation

Operation

Fresh, released, or consumed upgrade operation

Upgrade_Operation

type Upgrade_Operation is new Connection_Operation with private;

First-class ownership-preserving TLS upgrade. Provider setup is an eager bounded initiation step; lease acquisition and every handshake WANT_READ/WANT_WRITE step compose through the owning completion set.