ankh v0.6.0 Ankh.Connection

Genserver implementing HTTP/2 connection management

Ankh.Connection establishes the underlying TLS connection and provides connection and stream management, it also does frame (de)serialization and reassembly as needed.

After starting the connection, received frames are sent back to the caller, or the process specified in the controlling_process startup option, as messages. Separate messages are sent for HEADERS, PUSH_PROMISE and DATA frames.

Headers are always reassembled and sent back in one message to the controlling_process. For data frames a data msg is sent for each received DATA frame, and it is the controlling_process responsibility to reassemble incoming data.

For both HEADERS and DATA FRAMES the end_stream flag signals if the peer is done with the stream or more DATA/HEADERS blocks are going to be transmitted.

Errors are reported via error msg.

See typespecs below for message types and formats.

Link to this section Summary

Types

Startup options:

  • ssl_options: SSL connection options, for the Erlang :ssl module

Connection process

Ankh DATA message

Ankh ERROR message

Ankh HEADERS message

Ankh PUSH_PROMISE message

Functions

Accepts a client connection

Returns a specification to start this module under a supervisor

Closes the connection

Connects to a server

Sends a frame over the connection

Updates send settings for the connection

Start the connection process for the specified URI

Updates the connection window_size with the provided increment

Link to this section Types

Link to this type

args()
args() :: [uri: URI.t(), ssl_options: Keyword.t()]

Startup options:

  • ssl_options: SSL connection options, for the Erlang :ssl module
Link to this type

connection()
connection() :: GenServer.server()

Connection process

Link to this type

data_msg()
data_msg() :: {:ankh, :data, integer(), binary()}

Ankh DATA message

{:ankh, :data, stream_id, data}

Link to this type

error_msg()
error_msg() :: {:ankh, :data, integer(), term()}

Ankh ERROR message

{:ankh, :error, stream_id, error}

Link to this type

headers_msg()
headers_msg() :: {:ankh, :headers, integer(), Keyword.t()}

Ankh HEADERS message

{:ankh, :headers, stream_id, headers}

Link to this type

push_promise_msg()
push_promise_msg() :: {:ankh, :push_promise, integer(), integer(), Keyword.t()}

Ankh PUSH_PROMISE message

{:ankh, :headers, stream_id, promised_stream_id, headers}

Link to this section Functions

Link to this function

accept(connection, socket)
accept(connection(), pid()) :: :ok | {:error, term()}

Accepts a client connection

Link to this function

child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

close(connection)
close(connection()) :: :ok | {:error, term()}

Closes the connection

Before closing the TLS connection a GOAWAY frame is sent to the peer.

Link to this function

connect(connection)
connect(connection()) :: :ok | {:error, term()}

Connects to a server

Link to this function

send(connection, frame)
send(connection(), Ankh.Frame.t()) :: :ok | {:error, term()}

Sends a frame over the connection

Link to this function

send_settings(connection, settings)
send_settings(connection(), Ankh.Frame.Settings.Payload.t()) ::
  :ok | {:error, term()}

Updates send settings for the connection

Link to this function

start_link(args, options \\ [])
start_link(args(), GenServer.options()) :: GenServer.on_start()

Start the connection process for the specified URI.

Parameters:

  • args: startup options
  • options: GenServer startup options
Link to this function

start_stream(connection, id \\ nil, controlling_process \\ nil)
start_stream(connection(), integer() | nil, pid() | nil) ::
  {:ok, Ankh.Stream.id(), pid()} | {:error, term()}

Starts a new stream on the connection

Link to this function

window_update(connection, increment)
window_update(connection(), integer()) :: :ok | {:error, term()}

Updates the connection window_size with the provided increment