Class: EventMachine::EvmaTCPClient

Inherits:
StreamObject show all
Defined in:
lib/pr_eventmachine.rb

Instance Attribute Summary

Attributes inherited from Selectable

#io, #uuid

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from StreamObject

#eventable_read, #get_outbound_data_size, #get_peername, #heartbeat, #schedule_close, #send_data

Methods inherited from Selectable

#close_scheduled?, #get_peername, #heartbeat, #set_inactivity_timeout

Constructor Details

#initialize(io) ⇒ EvmaTCPClient

Returns a new instance of EvmaTCPClient.



655
656
657
658
# File 'lib/pr_eventmachine.rb', line 655

def initialize io
  super
  @pending = true
end

Class Method Details

.connect(host, port) ⇒ Object



643
644
645
646
647
648
649
650
651
652
# File 'lib/pr_eventmachine.rb', line 643

def self.connect host, port
  sd = Socket.new( Socket::AF_INET, Socket::SOCK_STREAM, 0 )
  begin
    # TODO, this assumes a current Ruby snapshot.
    # We need to degrade to a nonblocking connect otherwise.
    sd.connect_nonblock( Socket.pack_sockaddr_in( port, host ))
  rescue Errno::EINPROGRESS
  end
  EvmaTCPClient.new sd
end

Instance Method Details

#eventable_writeObject



669
670
671
672
673
674
675
676
677
678
# File 'lib/pr_eventmachine.rb', line 669

def eventable_write
  if @pending
    @pending = false
	if 0 == io.getsockopt(Socket::SOL_SOCKET, Socket::SO_ERROR).unpack("i").first
      EventMachine::event_callback uuid, ConnectionCompleted, ""
	end
  else
    super
  end
end

#select_for_reading?Boolean

Returns:

  • (Boolean)


665
666
667
# File 'lib/pr_eventmachine.rb', line 665

def select_for_reading?
  @pending ? false : super
end

#select_for_writing?Boolean

Returns:

  • (Boolean)


661
662
663
# File 'lib/pr_eventmachine.rb', line 661

def select_for_writing?
  @pending ? true : super
end