Sha256: f8f029d8e8bb6e0e468e46983d68599594c419f07c450eb9033e0f0f03b4eb96

Contents?: true

Size: 712 Bytes

Versions: 1

Compression:

Stored size: 712 Bytes

Contents

# frozen_string_literal: true

module StatsD
  module Instrument
    class UdpConnection
      include ConnectionBehavior

      DEFAULT_MAX_PACKET_SIZE = 1_472

      attr_reader :host, :port

      def initialize(host, port, max_packet_size: DEFAULT_MAX_PACKET_SIZE)
        @host = host
        @port = port
        @max_packet_size = max_packet_size
      end

      def send_datagram(message)
        socket.send(message, 0)
      end

      def type
        :udp
      end

      private

      def socket
        @socket ||= begin
          udp_socket = UDPSocket.new
          setup_socket(udp_socket)&.tap do |s|
            s.connect(@host, @port)
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
statsd-instrument-3.9.8 lib/statsd/instrument/udp_connection.rb