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

Version Path
async-io-1.43.2 lib/async/io/socket_endpoint.rb
async-io-1.43.1 lib/async/io/socket_endpoint.rb
async-io-1.43.0 lib/async/io/socket_endpoint.rb
async-io-1.42.1 lib/async/io/socket_endpoint.rb
async-io-1.42.0 lib/async/io/socket_endpoint.rb
async-io-1.41.0 lib/async/io/socket_endpoint.rb
async-io-1.39.0 lib/async/io/socket_endpoint.rb
async-io-1.38.1 lib/async/io/socket_endpoint.rb
async-io-1.38.0 lib/async/io/socket_endpoint.rb
async-io-1.37.0 lib/async/io/socket_endpoint.rb
async-io-1.36.1 lib/async/io/socket_endpoint.rb
async-io-1.36.0 lib/async/io/socket_endpoint.rb