class Riemann::Client::UDP

Constants

MAX_SIZE

Attributes

host[RW]
max_size[RW]
port[RW]

Public Class Methods

new(opts = {}) click to toggle source
# File lib/riemann/client/udp.rb, line 10
def initialize(opts = {}) # rubocop:disable Lint/MissingSuper
  @host     = opts[:host] || HOST
  @port     = opts[:port] || PORT
  @max_size = opts[:max_size] || MAX_SIZE
  @socket   = nil
end

Public Instance Methods

close() click to toggle source
# File lib/riemann/client/udp.rb, line 23
def close
  @socket.close if connected?
  @socket = nil
end
connected?() click to toggle source
# File lib/riemann/client/udp.rb, line 28
def connected?
  @socket && !@socket.closed?
end
read_message(_socket) click to toggle source

Read a message from a stream

# File lib/riemann/client/udp.rb, line 33
def read_message(_socket)
  raise Unsupported
end
send_maybe_recv(message) click to toggle source
# File lib/riemann/client/udp.rb, line 41
def send_maybe_recv(message)
  encoded_string = message.encode.to_s
  raise TooBig unless encoded_string.length < @max_size

  socket.send(encoded_string, 0, @host, @port)
  nil
end
send_recv(_message) click to toggle source
# File lib/riemann/client/udp.rb, line 37
def send_recv(_message)
  raise Unsupported
end
socket() click to toggle source
# File lib/riemann/client/udp.rb, line 17
def socket
  return @socket if connected?

  @socket = UDPSocket.new
end