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_peername, #schedule_close, #send_data

Methods inherited from Selectable

#close_scheduled?, #get_peername

Constructor Details

#initialize(io) ⇒ EvmaTCPClient

Returns a new instance of EvmaTCPClient.



495
496
497
498
# File 'lib/pr_eventmachine.rb', line 495

def initialize io
  super
  @pending = true
end

Class Method Details

.connect(host, port) ⇒ Object



483
484
485
486
487
488
489
490
491
492
# File 'lib/pr_eventmachine.rb', line 483

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



509
510
511
512
513
514
515
516
# File 'lib/pr_eventmachine.rb', line 509

def eventable_write
  if @pending
    @pending = false
    EventMachine::event_callback uuid, ConnectionCompleted, ""
  else
    super
  end
end

#select_for_reading?Boolean

Returns:

  • (Boolean)


505
506
507
# File 'lib/pr_eventmachine.rb', line 505

def select_for_reading?
  @pending ? false : super
end

#select_for_writing?Boolean

Returns:

  • (Boolean)


501
502
503
# File 'lib/pr_eventmachine.rb', line 501

def select_for_writing?
  @pending ? true : super
end