class Endpoint
This is an endpoint which bridges a client with a local server.
Definitions
def initialize(protocol = Protocol::HTTP2, scheme = "http", authority = "localhost", queue: Queue.new)
Initialize a mock endpoint for testing.
Signature
-
parameter
protocolProtocol The protocol to use for connections.
-
parameter
schemeString The URL scheme.
-
parameter
authorityString The hostname authority.
Implementation
def initialize(protocol = Protocol::HTTP2, scheme = "http", authority = "localhost", queue: Queue.new)
@protocol = protocol
@scheme = scheme
@authority = authority
@queue = queue
end
def run(parent: Task.current, &block)
Processing incoming connections
Implementation
def run(parent: Task.current, &block)
while peer = @queue.dequeue
server = @protocol.server(peer)
parent.async do
server.each(&block)
end
end
end
def connect
Create a new client-side connection by enqueuing the server-side socket.
Signature
-
returns
Socket The client-side socket.
Implementation
def connect
local, remote = ::Socket.pair(Socket::AF_UNIX, Socket::SOCK_STREAM)
@queue.enqueue(remote)
return local
end
def wrap(endpoint)
Create a new mock endpoint that shares the same connection queue but adopts another endpoint's scheme and authority.
Signature
-
parameter
endpointEndpoint The endpoint to mirror the scheme and authority from.
-
returns
Endpoint A new mock endpoint.
Implementation
def wrap(endpoint)
self.class.new(@protocol, endpoint.scheme, endpoint.authority, queue: @queue)
end