← All compilation units

Flyology.IO.Sockets

Description

Provides nonblocking socket operations with one API for both task lanes. Lightweight callers suspend on readiness; native callers block their thread in poll(2). Callers must synchronize concurrent use and close of the same socket.

Interrupt sets are the raw composition hook for independent lifecycle sources such as connection close, server shutdown, and per-operation cancellation. Readability interrupts the socket operation; this package does not consume or close a member, and every owner must outlive the call.

Example:

Flyology.IO.Sockets.Receive (Socket, Buffer, Last, Timeout => 1.0);

Accept_Connection

procedure Accept_Connection
  (Server  : GNAT.Sockets.Socket_Type;
   Socket  : out GNAT.Sockets.Socket_Type;
   Address : out GNAT.Sockets.Sock_Addr_Type;
   Timeout    : Duration := Infinite;
   Interrupts : Interrupt_Set := No_Interrupts)

Accept one connection and configure it for Flyology I/O. Aborted backlog entries and protocol-level admission errors are retried. Process or system descriptor exhaustion is retried with exponential backoff capped at 50 milliseconds; interrupt descriptors remain part of that wait. Other listener errors fail. Timeout and interrupt behavior match Receive, with one deadline across all retries and backoff.

Parameters
Server

Open listening socket; ownership is retained

Socket

Newly accepted socket owned by the caller on return

Address

Accepted peer address

Timeout

Deadline interval in seconds

Interrupts

Independent readable lifecycle wake descriptors

Raised exceptions
Timeout_Error

The deadline expires before an accept

Operation_Interrupted

An interrupt descriptor is readable

Device_Error

Readiness polling fails

GNAT

.Sockets.Socket_Error Accept or socket setup fails

Connect

procedure Connect
  (Socket  : GNAT.Sockets.Socket_Type;
   Server  : GNAT.Sockets.Sock_Addr_Type;
   Timeout    : Duration := Infinite;
   Interrupts : Interrupt_Set := No_Interrupts)

Connect Socket to Server. A nonblocking connect waits for write readiness and checks the socket error. One deadline spans retries.

Parameters
Socket

Open unconnected socket; ownership is retained

Server

Destination address

Timeout

Deadline interval in seconds

Interrupts

Independent readable lifecycle wake descriptors

Raised exceptions
Timeout_Error

The deadline expires before connection

Operation_Interrupted

An interrupt descriptor is readable

Device_Error

Readiness polling fails

GNAT

.Sockets.Socket_Error Connect or socket setup fails

Native_Descriptor

function Native_Descriptor
  (Socket : GNAT.Sockets.Socket_Type) return Descriptor

Return Socket's operating-system descriptor without transferring ownership.

Parameters
Socket

Socket to inspect

Return value

Borrowed descriptor; the socket remains its owner

Operation_Interrupted

Operation_Interrupted : exception;

Raised when a member of the operation's interrupt set becomes readable.

Prepare

procedure Prepare (Socket : GNAT.Sockets.Socket_Type)

Enable nonblocking mode. All other operations call Prepare themselves.

Parameters
Socket

Open socket to configure

Raised exceptions
GNAT

.Sockets.Socket_Error Socket configuration fails

Receive

procedure Receive
  (Socket  : GNAT.Sockets.Socket_Type;
   Item    : out Ada.Streams.Stream_Element_Array;
   Last    : out Ada.Streams.Stream_Element_Offset;
   Timeout    : Duration := Infinite;
   Interrupts : Interrupt_Set := No_Interrupts)

Receive one available chunk. Negative Timeout means no limit; zero is an immediate poll, and one deadline spans EINTR/readiness retries. Optional interrupt descriptors are observed for readability but not consumed.

Parameters
Socket

Open connected socket

Item

Destination buffer

Last

Last element received, or Item'First - 1 on orderly closure

Timeout

Deadline interval in seconds

Interrupts

Independent readable lifecycle wake descriptors

Raised exceptions
Timeout_Error

The deadline expires before readiness

Operation_Interrupted

An interrupt descriptor is readable

Device_Error

Readiness polling fails

GNAT

.Sockets.Socket_Error Socket receive or setup fails

Receive_Exactly

procedure Receive_Exactly
  (Socket  : GNAT.Sockets.Socket_Type;
   Item    : out Ada.Streams.Stream_Element_Array;
   Timeout    : Duration := Infinite;
   Interrupts : Interrupt_Set := No_Interrupts)

Fill Item or raise. One Timeout deadline spans every partial receive and retry. Lane and interrupt behavior match Receive.

Parameters
Socket

Open connected socket

Item

Destination buffer to fill

Timeout

Deadline interval in seconds

Interrupts

Independent readable lifecycle wake descriptors

Raised exceptions
Timeout_Error

The shared deadline expires

Operation_Interrupted

An interrupt descriptor is readable

Device_Error

Polling fails or peer closes before completion

GNAT

.Sockets.Socket_Error Socket receive or setup fails

Send

procedure Send
  (Socket  : GNAT.Sockets.Socket_Type;
   Item    : Ada.Streams.Stream_Element_Array;
   Last    : out Ada.Streams.Stream_Element_Offset;
   Timeout    : Duration := Infinite;
   Interrupts : Interrupt_Set := No_Interrupts)

Send one available chunk. Timeout and interrupt behavior match Receive; one deadline spans EINTR/readiness retries.

Parameters
Socket

Open connected socket

Item

Source buffer

Last

Last element sent, or Item'First - 1 if none

Timeout

Deadline interval in seconds

Interrupts

Independent readable lifecycle wake descriptors

Raised exceptions
Timeout_Error

The deadline expires before readiness

Operation_Interrupted

An interrupt descriptor is readable

Device_Error

Readiness polling fails

GNAT

.Sockets.Socket_Error Socket send or setup fails

Send_All

procedure Send_All
  (Socket  : GNAT.Sockets.Socket_Type;
   Item    : Ada.Streams.Stream_Element_Array;
   Timeout    : Duration := Infinite;
   Interrupts : Interrupt_Set := No_Interrupts)

Send all of Item or raise. One Timeout deadline spans every partial send and retry. Lane and interrupt behavior match Send.

Parameters
Socket

Open connected socket

Item

Source buffer to send completely

Timeout

Deadline interval in seconds

Interrupts

Independent readable lifecycle wake descriptors

Raised exceptions
Timeout_Error

The shared deadline expires

Operation_Interrupted

An interrupt descriptor is readable

Device_Error

Polling fails or no forward progress is made

GNAT

.Sockets.Socket_Error Socket send or setup fails