class Datadog::Statsd::UDPConnection
Attributes
host[R]
StatsD host.
port[R]
StatsD port.
Public Class Methods
new(host, port, **kwargs)
click to toggle source
Calls superclass method
Datadog::Statsd::Connection::new
# File lib/datadog/statsd/udp_connection.rb, line 14 def initialize(host, port, **kwargs) super(**kwargs) @host = host @port = port @socket = nil end
Public Instance Methods
close()
click to toggle source
# File lib/datadog/statsd/udp_connection.rb, line 22 def close @socket.close if @socket @socket = nil end
Private Instance Methods
connect()
click to toggle source
# File lib/datadog/statsd/udp_connection.rb, line 29 def connect close if @socket family = Addrinfo.udp(host, port).afamily @socket = UDPSocket.new(family) @socket.connect(host, port) end
send_message(message)
click to toggle source
send_message
is writing the message in the socket, it may create the socket if nil It is not thread-safe but since it is called by either the Sender
bg thread or the SingleThreadSender
(which is using a mutex while Flushing), only one thread must call it at a time.
# File lib/datadog/statsd/udp_connection.rb, line 42 def send_message(message) connect unless @socket @socket.send(message, 0) end