Clover Coverage Report - JmDNS 3.4.1
Coverage timestamp: Thu Aug 25 2011 13:06:33 CEST
../../../img/srcFileCovDistChart7.png 18% of files have more coverage
29   81   21   9.67
18   59   0.72   3
3     7  
1    
 
  SocketListener       Line # 17 29 0% 21 16 68% 0.68
 
  (21)
 
1    // Copyright 2003-2005 Arthur van Hoff, Rick Blair
2    // Licensed under Apache License version 2.0
3    // Original license LGPL
4   
5    package javax.jmdns.impl;
6   
7    import java.io.IOException;
8    import java.net.DatagramPacket;
9    import java.util.logging.Level;
10    import java.util.logging.Logger;
11   
12    import javax.jmdns.impl.constants.DNSConstants;
13   
14    /**
15    * Listen for multicast packets.
16    */
 
17    class SocketListener extends Thread {
18    static Logger logger = Logger.getLogger(SocketListener.class.getName());
19   
20    /**
21    *
22    */
23    private final JmDNSImpl _jmDNSImpl;
24   
25    /**
26    * @param jmDNSImpl
27    */
 
28  29 toggle SocketListener(JmDNSImpl jmDNSImpl) {
29  29 super("SocketListener(" + (jmDNSImpl != null ? jmDNSImpl.getName() : "") + ")");
30  29 this.setDaemon(true);
31  29 this._jmDNSImpl = jmDNSImpl;
32    }
33   
 
34  29 toggle @Override
35    public void run() {
36  29 try {
37  29 byte buf[] = new byte[DNSConstants.MAX_MSG_ABSOLUTE];
38  29 DatagramPacket packet = new DatagramPacket(buf, buf.length);
39  673 while (!this._jmDNSImpl.isCanceling() && !this._jmDNSImpl.isCanceled()) {
40  679 packet.setLength(buf.length);
41  682 this._jmDNSImpl.getSocket().receive(packet);
42  652 if (this._jmDNSImpl.isCanceling() || this._jmDNSImpl.isCanceled() || this._jmDNSImpl.isClosing() || this._jmDNSImpl.isClosed()) {
43  16 break;
44    }
45  637 try {
46  638 if (this._jmDNSImpl.getLocalHost().shouldIgnorePacket(packet)) {
47  0 continue;
48    }
49   
50  644 DNSIncoming msg = new DNSIncoming(packet);
51  640 if (logger.isLoggable(Level.FINEST)) {
52  0 logger.finest(this.getName() + ".run() JmDNS in:" + msg.print(true));
53    }
54  647 if (msg.isQuery()) {
55  339 if (packet.getPort() != DNSConstants.MDNS_PORT) {
56  0 this._jmDNSImpl.handleQuery(msg, packet.getAddress(), packet.getPort());
57    }
58  336 this._jmDNSImpl.handleQuery(msg, this._jmDNSImpl.getGroup(), DNSConstants.MDNS_PORT);
59    } else {
60  298 this._jmDNSImpl.handleResponse(msg);
61    }
62    } catch (IOException e) {
63  0 logger.log(Level.WARNING, this.getName() + ".run() exception ", e);
64    }
65    }
66    } catch (IOException e) {
67  13 if (!this._jmDNSImpl.isCanceling() && !this._jmDNSImpl.isCanceled() && !this._jmDNSImpl.isClosing() && !this._jmDNSImpl.isClosed()) {
68  0 logger.log(Level.WARNING, this.getName() + ".run() exception ", e);
69  0 this._jmDNSImpl.recover();
70    }
71    }
72  29 if (logger.isLoggable(Level.FINEST)) {
73  0 logger.finest(this.getName() + ".run() exiting.");
74    }
75    }
76   
 
77  0 toggle public JmDNSImpl getDns() {
78  0 return _jmDNSImpl;
79    }
80   
81    }