lib/cosmos/interfaces/udp_interface.rb in cosmos-3.8.2 vs lib/cosmos/interfaces/udp_interface.rb in cosmos-3.8.3
- old
+ new
@@ -77,10 +77,11 @@
@write_src_port,
@interface_address,
@ttl,
@bind_address) if @write_dest_port
@read_socket = UdpReadSocket.new(@read_port, @hostname, @interface_address, @bind_address) if @read_port
+ @thread_sleeper = nil
end
# @return [Boolean] Whether the active ports (read and/or write) have
# created sockets. Since UDP is connectionless, creation of the sockets
# is used to determine connection.
@@ -98,10 +99,12 @@
def disconnect
Cosmos.close_socket(@write_socket)
@write_socket = nil
Cosmos.close_socket(@read_socket)
@read_socket = nil
+ @thread_sleeper.cancel if @thread_sleeper
+ @thread_sleeper = nil
end
# If the read port was given, the read_socket is read and the data returned
# in a {Packet}. bytes_read and read_count are updated.
#
@@ -111,19 +114,23 @@
begin
data = @read_socket.read(@read_timeout)
@raw_logger_pair.read_logger.write(data) if @raw_logger_pair
rescue IOError
# Disconnected
- Thread.stop
+ return nil
end
@bytes_read += data.length
@read_count += 1
return Packet.new(nil, nil, :BIG_ENDIAN, nil, data)
else
# Write only interface so stop the thread which calls read
- Thread.stop
+ @thread_sleeper = Sleeper.new
+ while connected?()
+ @thread_sleeper.sleep(1000000)
+ end
+ return nil
end
end
# If the write_dest_port was given, the write_socket is written with the
# packet data. bytes_written and write_count are updated.