Module: David::Server::Multicast

Included in:
David::Server
Defined in:
lib/david/server/multicast.rb

Overview

Instance Method Summary collapse

Instance Method Details

#multicast_initialize!Object


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/david/server/multicast.rb', line 5

def multicast_initialize!
  @socket.to_io.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR, 1)

  if ipv6?
    maddrs = @options[:MulticastGroups]
    maddrs << 'ff02::1' if OS.osx? # OSX needs ff02::1 explicitly joined.
    maddrs.each { |maddr| multicast_listen_ipv6(maddr) }

    setsockopts_ipv6
  else
    maddrs = ['224.0.1.187']
    multicast_listen_ipv4(maddrs.first)

    setsockopts_ipv4
  end

  log.debug("Joined multicast groups: #{maddrs.join(', ')}")
rescue Errno::ENODEV, Errno::EADDRNOTAVAIL
  log.warn('Multicast initialization failure: Device not found.')
  @options[:Multicast] = false
end