Sha256: 9600afdab53f01658bdc62d5d644ad02b8e92930b206f4de68ea05c074d197ec

Contents?: true

Size: 885 Bytes

Versions: 2

Compression:

Stored size: 885 Bytes

Contents

# frozen_string_literal: true

module Socketry
  # User Datagram Protocol: "fire-and-forget" packet protocol
  module UDP
    # Represents a received UDP message
    class Datagram
      attr_reader :message, :sockaddr, :remote_host, :remote_addr, :remote_port

      def initialize(message, sockaddr)
        @message  = message
        @sockaddr = sockaddr
        @remote_port = sockaddr[1]
        @remote_host = sockaddr[2]
        @remote_addr = sockaddr[3]
      end

      def addrinfo
        addr_family = case @sockaddr[0]
                      when "AF_INET"  then ::Socket::AF_INET
                      when "AF_INET6" then ::Socket::AF_INET6
                      else raise Socketry::AddressError, "unsupported IP address family: #{@sockaddr[0]}"
                      end

        Addrinfo.new(@sockaddr, addr_family, ::Socket::SOCK_DGRAM)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
socketry-0.5.1 lib/socketry/udp/datagram.rb
socketry-0.5.0 lib/socketry/udp/datagram.rb