Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed nil reference when removing c-ares sockets

  • Loading branch information...
commit 29e5e7f4eb686c62e6a0ee8e1b4be93bd11ee91f 1 parent 8a00ff5
David Albert authored
13 examples/resolver.rb
View
@@ -4,8 +4,11 @@
require 'eventless'
-puts IPSocket.getaddress("www.google.com")
-
-p Socket.unpack_sockaddr_in(Socket.pack_sockaddr_in(80, "www.google.com"))
-
-p Socket.pack_sockaddr_in(80, "www.google.com")
+fibers = []
+%w(www.google.com ipv6.google.com www.yahoo.com www.bing.com).each do |host|
+ fibers << Eventless.spawn do
+ puts "#{host}: #{IPSocket.getaddress(host)}"
+ end
+end
+
+fibers.each { |f| f.join }
3  ext/sockaddr/sockaddr.c
View
@@ -21,8 +21,7 @@ rb_eventless_pack_sockaddr_in(VALUE self, VALUE port, VALUE host, VALUE sa_famil
a.sin_port = htons(NUM2INT(port));
inet_pton(AF_INET, RSTRING_PTR(host), &a.sin_addr);
packed_str = rb_str_new((char *)&a, sizeof(struct sockaddr_in));
- }
- else if (NUM2INT(sa_family) == AF_INET6) {
+ } else if (NUM2INT(sa_family) == AF_INET6) {
struct sockaddr_in6 a;
memset(&a, 0, sizeof(a));
16 lib/eventless/resolver.rb
View
@@ -11,17 +11,17 @@ def setup_resolver
@resolver_sockets = {}
resolver = Cares.new do |socket, read, write|
+ handler = @resolver_sockets[socket.fileno]
+
if read or write
- unless @resolver_sockets.has_key?(socket)
+ if handler.nil?
# new socket
attach(@resolver_timer) unless @resolver_timer.attached?
handler = create_socket_watchers(socket)
- @resolver_sockets[socket] = handler
+ @resolver_sockets[socket.fileno] = handler
end
- handler = @resolver_sockets[socket]
-
if read
attach(handler.read_watcher)
else
@@ -35,10 +35,10 @@ def setup_resolver
end
else # socket just got closed
- detach(handler.read_handler) if handler.read_handler.attached?
- detach(handler.write_handler) if handler.write_handler.attached?
+ detach(handler.read_watcher) if handler.read_watcher.attached?
+ detach(handler.write_watcher) if handler.write_watcher.attached?
- @resolver_sockets.delete(socket)
+ @resolver_sockets.delete(socket.fileno)
if @resolver_sockets.size == 0
detach(@resolver_timer)
@@ -87,8 +87,6 @@ class << IPSocket
alias_method :old_getaddress, :getaddress
def getaddress(hostname)
- STDERR.puts "IPSocket.getaddress"
-
# return if we're already a valid ip address
begin
IPAddress.parse hostname
Please sign in to comment.
Something went wrong with that request. Please try again.