Class: QuietQUIC::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/quietquic/connection.rb

Overview

A single post-handshake, PSK-authenticated QUIC connection.

Produced identically by Server#accept and QuietQUIC::Client.connect (both sides surface the same type). Carries bidirectional Streams: #open_stream dials a new stream, #accept_stream awaits the next peer-opened one. Both park the fiber (under an Async reactor) until they resolve.

Dropping a Connection does not tear the connection down; call #close to send a CONNECTION_CLOSE so the peer tears down promptly rather than idling out.

Instance Method Summary collapse

Constructor Details

#initialize(native) ⇒ Connection

Returns a new instance of Connection.

Parameters:

  • native (Native::Connection)

    the wrapped crate connection.



15
16
17
# File 'lib/quietquic/connection.rb', line 15

def initialize(native)
  @native = native
end

Instance Method Details

#accept_streamStream

Await and return the next bidirectional Stream the peer opens.

Blocks until the peer initiates a stream. Under an Async reactor it parks the fiber; otherwise it blocks with the GVL released.

Returns:

Raises:

  • (QuietQUIC::ConnectionLost)

    if the connection is closed or lost while awaiting.



36
37
38
# File 'lib/quietquic/connection.rb', line 36

def accept_stream
  Stream.new(QuietQUIC.await(@native.accept_stream_op))
end

#closevoid

This method returns an undefined value.

Close the connection, sending a CONNECTION_CLOSE frame so the peer tears down promptly. Best-effort and idempotent.



51
52
53
# File 'lib/quietquic/connection.rb', line 51

def close
  @native.close
end

#open_streamStream

Open a new bidirectional Stream.

Returns:

Raises:

  • (QuietQUIC::ConnectionLost)

    if the connection is closed or lost.

  • (QuietQUIC::StreamError)

    if the transport refuses the stream.



24
25
26
# File 'lib/quietquic/connection.rb', line 24

def open_stream
  Stream.new(QuietQUIC.await(@native.open_stream_op))
end

#remote_addressString

The remote peer's address (e.g. "127.0.0.1:54321").

Returns:

  • (String)


43
44
45
# File 'lib/quietquic/connection.rb', line 43

def remote_address
  @native.remote_address
end