Class: LogCourier::ClientTcp
- Inherits:
-
Object
- Object
- LogCourier::ClientTcp
- Defined in:
- lib/log-courier/client_tcp.rb
Overview
TLS transport implementation
Instance Method Summary collapse
- #connect(io_control) ⇒ Object
- #disconnect ⇒ Object
-
#initialize(options = {}) ⇒ ClientTcp
constructor
A new instance of ClientTcp.
- #pause_send ⇒ Object
- #resume_send ⇒ Object
- #send(signature, message) ⇒ Object
- #send_paused? ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ ClientTcp
Returns a new instance of ClientTcp.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/log-courier/client_tcp.rb', line 27 def initialize( = {}) @options = { logger: nil, transport: 'tls', ssl_ca: nil, ssl_certificate: nil, ssl_key: nil, ssl_key_passphrase: nil, }.merge!() @logger = @options[:logger] [:port, :ssl_ca].each do |k| fail "output/courier: '#{k}' is required" if @options[k].nil? end if @options[:transport] == 'tls' c = 0 [:ssl_certificate, :ssl_key].each do c += 1 end fail 'output/courier: \'ssl_certificate\' and \'ssl_key\' must be specified together' if c == 1 end end |
Instance Method Details
#connect(io_control) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/log-courier/client_tcp.rb', line 52 def connect(io_control) loop do begin break if tls_connect rescue ShutdownSignal raise end # TODO: Make this configurable sleep 5 end @send_q = SizedQueue.new 1 @send_paused = false @send_thread = Thread.new do run_send io_control end @recv_thread = Thread.new do run_recv io_control end return end |
#disconnect ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/log-courier/client_tcp.rb', line 76 def disconnect @send_thread.raise ShutdownSignal @send_thread.join @recv_thread.raise ShutdownSignal @recv_thread.join return end |
#pause_send ⇒ Object
90 91 92 93 94 95 |
# File 'lib/log-courier/client_tcp.rb', line 90 def pause_send return if @send_paused @send_paused = true @send_q << nil return end |
#resume_send ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/log-courier/client_tcp.rb', line 101 def resume_send if @send_paused @send_paused = false @send_q << nil end return end |
#send(signature, message) ⇒ Object
84 85 86 87 88 |
# File 'lib/log-courier/client_tcp.rb', line 84 def send(signature, ) # Add to send queue @send_q << [signature, .length].pack('A4N') + return end |
#send_paused? ⇒ Boolean
97 98 99 |
# File 'lib/log-courier/client_tcp.rb', line 97 def send_paused? @send_paused end |