Class: EventMachine::EvmaTCPClient

Inherits:
StreamObject show all
Defined in:
lib/em/pure_ruby.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.



666
667
668
669
# File 'lib/em/pure_ruby.rb', line 666

def initialize io
  super
  @pending = true
end

Class Method Details

.connect(bind_addr, bind_port, host, port) ⇒ Object



652
653
654
655
656
657
658
659
660
661
662
663
# File 'lib/em/pure_ruby.rb', line 652

def self.connect bind_addr, bind_port, host, port
  sd = Socket.new( Socket::AF_INET, Socket::SOCK_STREAM, 0 )
  sd.bind( Socket.pack_sockaddr_in( bind_port, bind_addr ))  if bind_addr

  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



680
681
682
683
684
685
686
687
688
689
# File 'lib/em/pure_ruby.rb', line 680

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)


676
677
678
# File 'lib/em/pure_ruby.rb', line 676

def select_for_reading?
  @pending ? false : super
end

#select_for_writing?Boolean

Returns:

  • (Boolean)


672
673
674
# File 'lib/em/pure_ruby.rb', line 672

def select_for_writing?
  @pending ? true : super
end