Sha256: 3dfaa6da2a5c766671a8723a25925cc6295e671e98f999968e2678dd1852ae57
Contents?: true
Size: 1010 Bytes
Versions: 12
Compression:
Stored size: 1010 Bytes
Contents
# frozen_string_literal: true # Released under the MIT License. # Copyright, 2018-2023, by Samuel Williams. require_relative 'endpoint' module Async module IO # This class doesn't exert ownership over the specified socket, wraps a native ::IO. class SocketEndpoint < Endpoint def initialize(socket, **options) super(**options) # This socket should already be in the required state. @socket = Async::IO.try_convert(socket) end def to_s "\#<#{self.class} #{@socket.inspect}>" end attr :socket def bind(&block) if block_given? begin yield @socket ensure @socket.reactor = nil end else return @socket end end def connect(&block) if block_given? begin yield @socket ensure @socket.reactor = nil end else return @socket end end end class Endpoint def self.socket(socket, **options) SocketEndpoint.new(socket, **options) end end end end
Version data entries
12 entries across 12 versions & 1 rubygems