Class: Rendezvous

Inherits:
Object
  • Object
show all
Defined in:
lib/rendezvous.rb,
lib/rendezvous/version.rb

Defined Under Namespace

Modules: Errors

Constant Summary collapse

DEFAULT_CHUNK_SIZE =

1 megabyte

1048576
VERSION =
"0.1.3"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Rendezvous

Returns a new instance of Rendezvous.



31
32
33
34
35
36
37
38
# File 'lib/rendezvous.rb', line 31

def initialize(options={})
  @activity_timeout = options[:activity_timeout]
  @connect_timeout  = options[:connect_timeout] || 120
  @input            = options[:input] || $stdin
  @output           = options[:output] || $stdout
  @url              = options[:url]
  @ssl_verify_peer  = options.fetch(:ssl_verify_peer, true)
end

Instance Attribute Details

#activity_timeoutObject (readonly)

Returns the value of attribute activity_timeout.



24
25
26
# File 'lib/rendezvous.rb', line 24

def activity_timeout
  @activity_timeout
end

#connect_timeoutObject (readonly)

Returns the value of attribute connect_timeout.



24
25
26
# File 'lib/rendezvous.rb', line 24

def connect_timeout
  @connect_timeout
end

#inputObject (readonly)

Returns the value of attribute input.



24
25
26
# File 'lib/rendezvous.rb', line 24

def input
  @input
end

#outputObject (readonly)

Returns the value of attribute output.



24
25
26
# File 'lib/rendezvous.rb', line 24

def output
  @output
end

#urlObject (readonly)

Returns the value of attribute url.



24
25
26
# File 'lib/rendezvous.rb', line 24

def url
  @url
end

Class Method Details

.start(options = {}) ⇒ Object



26
27
28
29
# File 'lib/rendezvous.rb', line 26

def self.start(options={})
  rendezvous = self.new(options)
  rendezvous.start
end

Instance Method Details

#startObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/rendezvous.rb', line 40

def start
  begin
    `stty -icanon -echo` if input.isatty

    if input.is_a?(StringIO)
      input.each(DEFAULT_CHUNK_SIZE) do |chunk|
        socket.write(chunk)
        socket.flush
      end

      ios = [socket]
    else
      ios = [socket, input]
    end

    loop do
      if selected = IO.select(ios, nil, nil, activity_timeout)
        if selected.first.first == input
          socket.write(input.readpartial(DEFAULT_CHUNK_SIZE))
          socket.flush
        else
          output.write(socket.readpartial(DEFAULT_CHUNK_SIZE))
        end
      else
        raise Rendezvous::Errors::ActivityTimeout
      end
    end
  rescue EOFError, Errno::EIO
  rescue Interrupt
    socket.write(3.chr)
    socket.flush
    retry
  rescue SignalException => e
    if Signal.list["QUIT"] == e.signo
      socket.write(28.chr)
      socket.flush
      retry
    end
    raise
  ensure
    `stty icanon echo` if input.isatty
  end
end