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.0.2"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Rendezvous

Returns a new instance of Rendezvous.



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

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]
end

Instance Attribute Details

#activity_timeoutObject (readonly)

Returns the value of attribute activity_timeout.



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

def activity_timeout
  @activity_timeout
end

#connect_timeoutObject (readonly)

Returns the value of attribute connect_timeout.



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

def connect_timeout
  @connect_timeout
end

#inputObject (readonly)

Returns the value of attribute input.



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

def input
  @input
end

#outputObject (readonly)

Returns the value of attribute output.



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

def output
  @output
end

#urlObject (readonly)

Returns the value of attribute url.



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

def url
  @url
end

Class Method Details

.start(options = {}) ⇒ Object



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

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

Instance Method Details

#startObject



38
39
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
# File 'lib/rendezvous.rb', line 38

def start
  begin
    `stty -icanon -echo` if input.isatty
    loop do
      if selected = IO.select([socket, input], 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