From: <th...@us...> - 2008-05-23 19:40:37
|
Revision: 1671 http://azsmrc.svn.sourceforge.net/azsmrc/?rev=1671&view=rev Author: the8472 Date: 2008-05-23 12:40:39 -0700 (Fri, 23 May 2008) Log Message: ----------- add exponential backoff, always sleep on exceptions Modified Paths: -------------- azsmrcplugins/trunk/lbms/plugins/mldht/kad/RPCServer.java Modified: azsmrcplugins/trunk/lbms/plugins/mldht/kad/RPCServer.java =================================================================== --- azsmrcplugins/trunk/lbms/plugins/mldht/kad/RPCServer.java 2008-05-22 16:43:57 UTC (rev 1670) +++ azsmrcplugins/trunk/lbms/plugins/mldht/kad/RPCServer.java 2008-05-23 19:40:39 UTC (rev 1671) @@ -83,7 +83,10 @@ * @see lbms.plugins.mldht.kad.RPCServerBase#run() */ public void run() { - outer: while (running) + + int delay = 1; + + while (running) { byte[] buffer = new byte[DHTConstants.RECEIVE_BUFFER_SIZE]; DatagramPacket packet = new DatagramPacket(buffer, buffer.length); @@ -91,29 +94,22 @@ { sock.receive(packet); handlePacket(packet); + if(delay > 1) + delay--; } catch (Exception e) { if (running) { DHT.log(e, LogLevel.Error); - while (running && sock.isClosed()) - { - try - { // wait a bit before we restore the socket to avoid screaming loops - Thread.sleep(200); - sock = new DatagramSocket(port); - } catch (Exception e1) - { - DHT.log("Reestablishing listening port failed, will retry in 5s", LogLevel.Error); - DHT.log(e1, LogLevel.Error); - try - { // the old, closed socket might not have been cleaned up properly, wait longer - Thread.sleep(5000); - } catch (InterruptedException e2) - { - break outer; - } - } + try { + // wait a bit before we restore the socket to avoid screaming loops + Thread.sleep(delay * 100); + if(delay < 256) + delay <<= 1; + sock.close(); + sock = new DatagramSocket(port); + } catch (Exception e1) { + DHT.log(e1, LogLevel.Error); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |