Class: RemoteSyslogSender::TcpSender

Inherits:
Sender
  • Object
show all
Defined in:
lib/remote_syslog_sender/tcp_sender.rb

Defined Under Namespace

Classes: NonBlockingTimeout

Instance Attribute Summary

Attributes inherited from Sender

#packet, #socket

Instance Method Summary collapse

Methods inherited from Sender

#transmit

Constructor Details

#initialize(remote_hostname, remote_port, options = {}) ⇒ TcpSender

Returns a new instance of TcpSender.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/remote_syslog_sender/tcp_sender.rb', line 9

def initialize(remote_hostname, remote_port, options = {})
  super
  @tls             = options[:tls]
  @retry_limit     = options[:retry_limit] || 3
  @retry_interval  = options[:retry_interval] || 0.5
  @remote_hostname = remote_hostname
  @remote_port     = remote_port
  @ssl_method      = options[:ssl_method] || 'TLSv1_2'
  @ca_file         = options[:ca_file]
  @verify_mode     = options[:verify_mode]
  @timeout         = options[:timeout] || 600
  @timeout_exception   = !!options[:timeout_exception]
  @exponential_backoff = !!options[:exponential_backoff]

  @mutex = Mutex.new
  @tcp_socket = nil

  if [:SOL_SOCKET, :SO_KEEPALIVE, :IPPROTO_TCP, :TCP_KEEPIDLE].all? {|c| Socket.const_defined? c}
    @keep_alive      = options[:keep_alive]
  end
  if Socket.const_defined?(:TCP_KEEPIDLE)
    @keep_alive_idle = options[:keep_alive_idle]
  end
  if Socket.const_defined?(:TCP_KEEPCNT)
    @keep_alive_cnt  = options[:keep_alive_cnt]
  end
  if Socket.const_defined?(:TCP_KEEPINTVL)
    @keep_alive_intvl = options[:keep_alive_intvl]
  end
  connect
end

Instance Method Details

#closeObject



41
42
43
44
# File 'lib/remote_syslog_sender/tcp_sender.rb', line 41

def close
  @socket.close if @socket
  @tcp_socket.close if @tcp_socket
end