Class: ProxyLocal::Client
- Inherits:
-
EventMachine::Connection
- Object
- EventMachine::Connection
- ProxyLocal::Client
- Includes:
- EventMachine::Protocols::ObjectProtocol
- Defined in:
- lib/client.rb
Class Method Summary collapse
Instance Method Summary collapse
- #first_line(data) ⇒ Object
- #receive_object(message) ⇒ Object
- #send_options ⇒ Object
- #serializer ⇒ Object
- #ssl_handshake_completed ⇒ Object
- #unbind ⇒ Object
Class Method Details
.run(options = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/client.rb', line 22 def self.run( = {}) @@logger = Logger.new(STDOUT) @@logger.level = [:verbose] ? Logger::INFO : Logger::WARN @@logger.info("Run with options #{.inspect}") trap "SIGCLD", "IGNORE" trap "INT" do puts EventMachine.run exit end EventMachine.run do EventMachine.connect([:server_host], [:server_port], self) do |c| c.instance_eval do @options = if @options[:tls] @@logger.info("Request TLS") send_object(:start_tls) else end end end end end |
Instance Method Details
#first_line(data) ⇒ Object
62 63 64 |
# File 'lib/client.rb', line 62 def first_line(data) data.split(/\r?\n/, 2).first end |
#receive_object(message) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/client.rb', line 66 def receive_object() = [] unless .is_a?(Array) case [0] when :start_tls @@logger.info("Start TLS") start_tls when :message puts [1] when :halt EventMachine.stop_event_loop when :request _, uuid, request = @@logger.info(first_line(request)) EventMachine.connect('127.0.0.1', @options[:local_port], ClientProxy) do |connection| connection.callback do |data| @@logger.info("#{first_line(data)} - #{first_line(request)}") send_object(BERT::Tuple[:response, uuid, data]) end connection.send_data(request) end end end |
#send_options ⇒ Object
54 55 56 |
# File 'lib/client.rb', line 54 def send_object(BERT::Tuple[:options, @options]) end |
#serializer ⇒ Object
50 51 52 |
# File 'lib/client.rb', line 50 def serializer Serializer end |
#ssl_handshake_completed ⇒ Object
58 59 60 |
# File 'lib/client.rb', line 58 def ssl_handshake_completed end |
#unbind ⇒ Object
90 91 92 93 |
# File 'lib/client.rb', line 90 def unbind EventMachine.stop_event_loop puts "A connection has been terminated" end |