Author: toad
Date: 2008-01-24 16:15:19 +0000 (Thu, 24 Jan 2008)
New Revision: 17232
Modified:
trunk/plugins/MDNSDiscovery/javax/jmdns/JmDNS.java
Log:
Prevent MDNSDiscovery from causing a shutdown timeout: Wake up the listener
every 1000ms to unlock the multicast socket so we can send messages on it
(while we are blocking, we are holding the lock).
Modified: trunk/plugins/MDNSDiscovery/javax/jmdns/JmDNS.java
===================================================================
--- trunk/plugins/MDNSDiscovery/javax/jmdns/JmDNS.java 2008-01-24 15:13:57 UTC
(rev 17231)
+++ trunk/plugins/MDNSDiscovery/javax/jmdns/JmDNS.java 2008-01-24 16:15:19 UTC
(rev 17232)
@@ -9,6 +9,7 @@
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
+import java.net.SocketTimeoutException;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -270,6 +271,10 @@
socket.setNetworkInterface(hostInfo.getInterface());
}
socket.setTimeToLive(255);
+ // Wake up every 1000ms to give an opportunity to send messages!
+ // Both sending and receiving take the same lock, and the lock is kept
while the socket is waiting for data.
+ // It looks like this may have caused the shutdown to never happen.
+ socket.setSoTimeout(1000);
socket.joinGroup(group);
}
@@ -1114,7 +1119,11 @@
while (state != DNSState.CANCELED)
{
packet.setLength(buf.length);
- socket.receive(packet);
+ try {
+ socket.receive(packet);
+ } catch (SocketTimeoutException e) {
+ continue;
+ }
if (state == DNSState.CANCELED)
{
break;