lib/arborist/monitor/socket.rb in arborist-0.0.1.pre20160829140603 vs lib/arborist/monitor/socket.rb in arborist-0.0.1.pre20161005112841
- old
+ new
@@ -1,8 +1,9 @@
# -*- ruby -*-
#encoding: utf-8
+require 'time'
require 'loggability'
require 'timeout'
require 'socket'
require 'arborist/monitor' unless defined?( Arborist::Monitor )
@@ -116,29 +117,32 @@
end
# Now wait for connections to complete
wait_seconds = timeout_at - Time.now
until connections.empty? || wait_seconds <= 0
- self.log.debug "Waiting on %d connections for %0.3ds..." %
+ self.log.debug "Waiting on %d connections for %0.3fs..." %
[ connections.values.length, wait_seconds ]
- # :FIXME: Race condition: errors if timeout_at - Time.now is 0
_, ready, _ = IO.select( nil, connections.keys, nil, wait_seconds )
now = Time.now
ready.each do |sock|
identifier, sockaddr = *connections.delete( sock )
begin
- sock.connect_nonblock( sockaddr )
- rescue Errno::EISCONN
+ res = sock.getpeername
+ self.log.debug "connected to %s" % [ identifier ]
results[ identifier ] = {
- tcp_socket_connect: { time: now.to_s, duration: now - start }
+ tcp_socket_connect: { time: now.iso8601, duration: now - start }
}
rescue SocketError, SystemCallError => err
- self.log.debug "%p during connection: %s" % [ err.class, err.message ]
- results[ identifier ] = { error: err.message }
+ begin
+ sock.read( 1 )
+ rescue => err
+ self.log.debug "read: %p: %s" % [ err.class, err.message ]
+ results[ identifier ] = { error: err.message }
+ end
ensure
sock.close
end
end if ready
@@ -255,10 +259,10 @@
rescue IO::WaitReadable
ready, _, _ = IO.select( [sock], [], [], self.timeout )
if ready.nil?
now = Time.now
results[ identifier ] = {
- udp_socket_connect: { time: now.to_s, duration: now - start }
+ udp_socket_connect: { time: now.iso8601, duration: now - start }
}
self.log.debug " connection successful"
else
retry
end