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.



663
664
665
666
# File 'lib/em/pure_ruby.rb', line 663

def initialize io
  super
  @pending = true
end

Class Method Details

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



649
650
651
652
653
654
655
656
657
658
659
660
# File 'lib/em/pure_ruby.rb', line 649

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



677
678
679
680
681
682
683
684
685
686
# File 'lib/em/pure_ruby.rb', line 677

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)


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

def select_for_reading?
  @pending ? false : super
end

#select_for_writing?Boolean

Returns:

  • (Boolean)


669
670
671
# File 'lib/em/pure_ruby.rb', line 669

def select_for_writing?
  @pending ? true : super
end