Class: Rendezvous
- Inherits:
-
Object
- Object
- Rendezvous
- 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.1"
Instance Attribute Summary collapse
-
#activity_timeout ⇒ Object
readonly
Returns the value of attribute activity_timeout.
-
#connect_timeout ⇒ Object
readonly
Returns the value of attribute connect_timeout.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Rendezvous
constructor
A new instance of Rendezvous.
- #start ⇒ Object
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(={}) @activity_timeout = [:activity_timeout] @connect_timeout = [:connect_timeout] || 120 @input = [:input] || $stdin @output = [:output] || $stdout @url = [:url] @ssl_verify_peer = .fetch(:ssl_verify_peer, true) end |
Instance Attribute Details
#activity_timeout ⇒ Object (readonly)
Returns the value of attribute activity_timeout.
24 25 26 |
# File 'lib/rendezvous.rb', line 24 def activity_timeout @activity_timeout end |
#connect_timeout ⇒ Object (readonly)
Returns the value of attribute connect_timeout.
24 25 26 |
# File 'lib/rendezvous.rb', line 24 def connect_timeout @connect_timeout end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
24 25 26 |
# File 'lib/rendezvous.rb', line 24 def input @input end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
24 25 26 |
# File 'lib/rendezvous.rb', line 24 def output @output end |
#url ⇒ Object (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(={}) rendezvous = self.new() rendezvous.start end |
Instance Method Details
#start ⇒ Object
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 |