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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# 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 begin run_send io_control rescue ShutdownSignal rescue StandardError, NativeException => e @logger.warn e, :hint => 'Unknown write error' unless @logger.nil? io_control << ['F'] return end end @recv_thread = Thread.new do begin run_recv io_control rescue ShutdownSignal rescue StandardError, NativeException => e @logger.warn e, :hint => 'Unknown read error' unless @logger.nil? io_control << ['F'] return end end return end |
#disconnect ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/log-courier/client_tcp.rb', line 90 def disconnect @send_thread.raise ShutdownSignal @send_thread.join @recv_thread.raise ShutdownSignal @recv_thread.join return end |
#pause_send ⇒ Object
104 105 106 107 108 109 |
# File 'lib/log-courier/client_tcp.rb', line 104 def pause_send return if @send_paused @send_paused = true @send_q << nil return end |
#resume_send ⇒ Object
115 116 117 118 119 120 121 |
# File 'lib/log-courier/client_tcp.rb', line 115 def resume_send if @send_paused @send_paused = false @send_q << nil end return end |
#send(signature, message) ⇒ Object
98 99 100 101 102 |
# File 'lib/log-courier/client_tcp.rb', line 98 def send(signature, ) # Add to send queue @send_q << [signature, .length].pack('A4N') + return end |
#send_paused? ⇒ Boolean
111 112 113 |
# File 'lib/log-courier/client_tcp.rb', line 111 def send_paused? @send_paused end |