Skip to content

Commit

Permalink
vhost should not exit if the link to which the vhost is connected is …
Browse files Browse the repository at this point in the history
…disabled.
  • Loading branch information
yasuhito committed Jun 4, 2015
1 parent b793a20 commit d7fa7aa
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions lib/phut/vhost_daemon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ def lookup_arp_table(ip_address)
def write_to_raw_socket(packet)
@packets_sent << packet.snapshot
raw_socket.write packet.to_binary_s
rescue Errno::ENXIO
# link is disconnected
true
end

def create_udp_packet(dest)
Expand All @@ -81,17 +84,24 @@ def log_file
"#{@options.fetch(:log_dir)}/vhost.#{@options.fetch(:name)}.log"
end

# rubocop:disable MethodLength
def read_loop
loop do
raw_data, = raw_socket.recvfrom(8192)
udp = Pio::Udp.read(raw_data)
unless @options[:promisc]
next if udp.ip_destination_address != @options.fetch(:ip_address)
begin
raw_data, = raw_socket.recvfrom(8192)
udp = Pio::Udp.read(raw_data)
unless @options[:promisc]
next if udp.ip_destination_address != @options.fetch(:ip_address)
end
@logger.info "Received: #{udp}"
@packets_received << udp.snapshot
rescue Errno::ENETDOWN
# link is disconnected
sleep 1
end
@logger.info "Received: #{udp}"
@packets_received << udp.snapshot
end
end
# rubocop:enable MethodLength

def start_daemon
Process.daemon
Expand Down

0 comments on commit d7fa7aa

Please sign in to comment.