Sha256: 1bc23c05f0cfab6c9acacd3d9a0e18f52f33650fdd10ca5b04d0c3f4b38d58e3

Contents?: true

Size: 730 Bytes

Versions: 19

Compression:

Stored size: 730 Bytes

Contents

# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2023, by Samuel Williams.

require_relative 'generic'

module IO::Endpoint
	# This class doesn't exert ownership over the specified socket, wraps a native ::IO.
	class SocketEndpoint < Generic
		def initialize(socket, **options)
			super(**options)
			
			@socket = socket
		end
		
		def to_s
			"\#<#{self.class} #{@socket.inspect}>"
		end
		
		attr :socket
		
		def bind(&block)
			if block_given?
				yield @socket
			else
				return @socket
			end
		end
		
		def connect(&block)
			if block_given?
				yield @socket
			else
				return @socket
			end
		end
	end
	
	def self.socket(socket, **options)
		SocketEndpoint.new(socket, **options)
	end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
io-endpoint-0.13.1 lib/io/endpoint/socket_endpoint.rb
io-endpoint-0.13.0 lib/io/endpoint/socket_endpoint.rb
io-endpoint-0.12.0 lib/io/endpoint/socket_endpoint.rb
io-endpoint-0.11.0 lib/io/endpoint/socket_endpoint.rb
io-endpoint-0.10.2 lib/io/endpoint/socket_endpoint.rb
io-endpoint-0.10.1 lib/io/endpoint/socket_endpoint.rb
io-endpoint-0.10.0 lib/io/endpoint/socket_endpoint.rb
io-endpoint-0.9.0 lib/io/endpoint/socket_endpoint.rb
io-endpoint-0.8.1 lib/io/endpoint/socket_endpoint.rb
io-endpoint-0.8.0 lib/io/endpoint/socket_endpoint.rb
io-endpoint-0.7.2 lib/io/endpoint/socket_endpoint.rb
io-endpoint-0.7.1 lib/io/endpoint/socket_endpoint.rb
io-endpoint-0.7.0 lib/io/endpoint/socket_endpoint.rb
io-endpoint-0.6.0 lib/io/endpoint/socket_endpoint.rb
io-endpoint-0.5.0 lib/io/endpoint/socket_endpoint.rb
io-endpoint-0.4.0 lib/io/endpoint/socket_endpoint.rb
io-endpoint-0.3.0 lib/io/endpoint/socket_endpoint.rb
io-endpoint-0.2.0 lib/io/endpoint/socket_endpoint.rb
io-endpoint-0.1.0 lib/io/endpoint/socket_endpoint.rb