Skip to content

Commit

Permalink
Basic support for address_resolv using Resolv.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Jun 23, 2021
1 parent 6bcbc68 commit f36d350
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/async/scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
require 'console'
require 'event'
require 'timers'
require 'resolv'

module Async
class Scheduler < Node
Expand Down Expand Up @@ -134,6 +135,10 @@ def kernel_sleep(duration)
self.block(nil, duration)
end

def address_resolve(hostname)
::Resolv.getaddresses(hostname)
end

def io_wait(io, events, timeout = nil)
fiber = Fiber.current

Expand Down
33 changes: 33 additions & 0 deletions spec/async/scheduler/address_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright, 2021, by Samuel G. D. Williams. <http://www.codeotaku.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

require 'async/scheduler'

RSpec.describe Async::Scheduler, if: Async::Scheduler.supported? do
include_context Async::RSpec::Reactor

describe ::Addrinfo do
it "can resolve addresses" do
addresses = Addrinfo.getaddrinfo("www.google.com", "80")

expect(addresses).to_not be_empty
end
end
end

0 comments on commit f36d350

Please sign in to comment.