Skip to content
This repository was archived by the owner on Aug 29, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions .github/workflows/async-head.yaml

This file was deleted.

29 changes: 0 additions & 29 deletions .github/workflows/async-v1.yaml

This file was deleted.

2 changes: 0 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ jobs:
- macos

ruby:
- "2.7"
- "3.0"
- "3.1"
- "3.2"

Expand Down
3 changes: 2 additions & 1 deletion async-io.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ Gem::Specification.new do |spec|

spec.files = Dir.glob(['{lib}/**/*', '*.md'], File::FNM_DOTMATCH, base: __dir__)

spec.required_ruby_version = ">= 2.5"
spec.required_ruby_version = ">= 3.2"

spec.add_dependency "async"
spec.add_dependency "io-endpoint"

spec.add_development_dependency "async-container", "~> 0.15"
spec.add_development_dependency "async-rspec", "~> 1.10"
Expand Down
12 changes: 12 additions & 0 deletions config/external.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
async-http:
url: https://github.com/socketry/async-http.git
command: bundle exec rspec
async-websocket:
url: https://github.com/socketry/async-websocket.git
command: bundle exec sus
falcon:
url: https://github.com/socketry/falcon.git
command: bundle exec rspec
async-rest:
url: https://github.com/socketry/async-rest.git
command: bundle exec sus
10 changes: 0 additions & 10 deletions gems/async-head.rb

This file was deleted.

10 changes: 0 additions & 10 deletions gems/async-v1.rb

This file was deleted.

3 changes: 1 addition & 2 deletions lib/async/io.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
require_relative "io/generic"
require_relative "io/socket"
require_relative "io/version"

require_relative "io/endpoint"
require_relative "io/endpoint/each"
require_relative "io/address"

module Async
module IO
Expand Down
29 changes: 2 additions & 27 deletions lib/async/io/address_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,10 @@
# Copyright, 2018-2023, by Samuel Williams.

require_relative 'endpoint'
require 'io/endpoint/address_endpoint'

module Async
module IO
# This class will open and close the socket automatically.
class AddressEndpoint < Endpoint
def initialize(address, **options)
super(**options)

@address = address
end

def to_s
"\#<#{self.class} #{@address.inspect}>"
end

attr :address

# Bind a socket to the given address. If a block is given, the socket will be automatically closed when the block exits.
# @yield [Socket] the bound socket
# @return [Socket] the bound socket
def bind(&block)
Socket.bind(@address, **@options, &block)
end

# Connects a socket to the given address. If a block is given, the socket will be automatically closed when the block exits.
# @return [Socket] the connected socket
def connect(&block)
Socket.connect(@address, **@options, &block)
end
end
AddressEndpoint = ::IO::Endpoint::AddressEndpoint
end
end
13 changes: 0 additions & 13 deletions lib/async/io/binary_string.rb

This file was deleted.

35 changes: 2 additions & 33 deletions lib/async/io/composite_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,10 @@
# Copyright, 2022-2023, by Samuel Williams.

require_relative 'endpoint'
require 'io/endpoint/composite_endpoint'

module Async
module IO
class CompositeEndpoint < Endpoint
def initialize(endpoints, **options)
super(**options)
@endpoints = endpoints
end

def each(&block)
@endpoints.each(&block)
end

def connect(&block)
error = nil

@endpoints.each do |endpoint|
begin
return endpoint.connect(&block)
rescue => error
end
end

raise error
end

def bind(&block)
@endpoints.map(&:bind)
end
end

class Endpoint
def self.composite(*endpoints, **options)
CompositeEndpoint.new(endpoints, **options)
end
end
CompositeEndpoint = ::IO::Endpoint::CompositeEndpoint
end
end
105 changes: 2 additions & 103 deletions lib/async/io/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,111 +4,10 @@
# Copyright, 2017-2023, by Samuel Williams.
# Copyright, 2019, by Olle Jonsson.

require_relative 'address'
require_relative 'socket'

require 'uri'
require 'io/endpoint'

module Async
module IO
# Endpoints represent a way of connecting or binding to an address.
class Endpoint
def initialize(**options)
@options = options.freeze
end

def with(**options)
dup = self.dup

dup.options = @options.merge(options)

return dup
end

attr_accessor :options

# @return [String] The hostname of the bound socket.
def hostname
@options[:hostname]
end

# If `SO_REUSEPORT` is enabled on a socket, the socket can be successfully bound even if there are existing sockets bound to the same address, as long as all prior bound sockets also had `SO_REUSEPORT` set before they were bound.
# @return [Boolean, nil] The value for `SO_REUSEPORT`.
def reuse_port
@options[:reuse_port]
end

# If `SO_REUSEADDR` is enabled on a socket prior to binding it, the socket can be successfully bound unless there is a conflict with another socket bound to exactly the same combination of source address and port. Additionally, when set, binding a socket to the address of an existing socket in `TIME_WAIT` is not an error.
# @return [Boolean] The value for `SO_REUSEADDR`.
def reuse_address
@options[:reuse_address]
end

# Controls SO_LINGER. The amount of time the socket will stay in the `TIME_WAIT` state after being closed.
# @return [Integer, nil] The value for SO_LINGER.
def linger
@options[:linger]
end

# @return [Numeric] The default timeout for socket operations.
def timeout
@options[:timeout]
end

# @return [Address] the address to bind to before connecting.
def local_address
@options[:local_address]
end

# Endpoints sometimes have multiple paths.
# @yield [Endpoint] Enumerate all discrete paths as endpoints.
def each
return to_enum unless block_given?

yield self
end

# Accept connections from the specified endpoint.
# @param backlog [Integer] the number of connections to listen for.
def accept(backlog = Socket::SOMAXCONN, &block)
bind do |server|
server.listen(backlog)

server.accept_each(&block)
end
end

# Map all endpoints by invoking `#bind`.
# @yield the bound wrapper.
def bound
wrappers = []

self.each do |endpoint|
wrapper = endpoint.bind
wrappers << wrapper

yield wrapper
end

return wrappers
ensure
wrappers.each(&:close) if $!
end

# Create an Endpoint instance by URI scheme. The host and port of the URI will be passed to the Endpoint factory method, along with any options.
#
# @param string [String] URI as string. Scheme will decide implementation used.
# @param options keyword arguments passed through to {#initialize}
#
# @see Endpoint.ssl ssl - invoked when parsing a URL with the ssl scheme "ssl://127.0.0.1"
# @see Endpoint.tcp tcp - invoked when parsing a URL with the tcp scheme: "tcp://127.0.0.1"
# @see Endpoint.udp udp - invoked when parsing a URL with the udp scheme: "udp://127.0.0.1"
# @see Endpoint.unix unix - invoked when parsing a URL with the unix scheme: "unix://127.0.0.1"
def self.parse(string, **options)
uri = URI.parse(string)

self.public_send(uri.scheme, uri.host, uri.port, **options)
end
end
Endpoint = ::IO::Endpoint
end
end
40 changes: 0 additions & 40 deletions lib/async/io/endpoint/each.rb

This file was deleted.

Loading