[dijjer-cvs] Dijjer/src/dijjer/io/xfer BlockTransmitter.java,1.20,1.21
Brought to you by:
gnovos
|
From: Chris C. <vo...@us...> - 2005-12-26 11:39:06
|
Update of /cvsroot/dijjer/Dijjer/src/dijjer/io/xfer In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10136 Modified Files: BlockTransmitter.java Log Message: Simplified flow control a little more; set it to rebegin the loop whenever it sleeps just in case new information comes in about having to delay. Index: BlockTransmitter.java =================================================================== RCS file: /cvsroot/dijjer/Dijjer/src/dijjer/io/xfer/BlockTransmitter.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** BlockTransmitter.java 24 Dec 2005 14:02:32 -0000 1.20 --- BlockTransmitter.java 26 Dec 2005 11:38:57 -0000 1.21 *************** *** 38,42 **** public class BlockTransmitter { - static long _nextPacketSendTime; public static final int WAIT_AFTER_ALL_SENT = 10000; UdpSocketManager _usm; --- 38,41 ---- *************** *** 86,105 **** }); sendloop: while (!isFinished()) { synchronized(this) { ! // Going to synchronize on this for the entire loop. This way we don't have to check on ! // isFinished so much since it will only change between loops and during the wait calls ! if (_nextPacketSendTime < System.currentTimeMillis()) { ! _nextPacketSendTime = System.currentTimeMillis(); ! } ! _nextPacketSendTime += _throttle.getDelay(); // Wait until we are allowed to send a packet according to throttle long lTime = System.currentTimeMillis(); ! long lTimeOut = _nextPacketSendTime - System.currentTimeMillis(); ! if (lTimeOut > 50) { try { ! this.wait(lTimeOut); } catch (InterruptedException e) { if (isFinished()) break sendloop; } ! } lTime = System.currentTimeMillis() - lTime; --- 85,105 ---- }); sendloop: while (!isFinished()) { synchronized(this) { ! // Synchronize on this for the entire loop. This way we don't have to check on ! // isFinished so much since it will only change between loops and during the wait calls. ! // Also, if we have to wait at all we start through the loop again to see if the delay ! // has been updated with a missing packet message. ! // Wait until we are allowed to send a packet according to throttle long lTime = System.currentTimeMillis(); ! long currentDelay = lTime - _lastPacketSendTime; ! long remainingDelay = _throttle.getDelay() - currentDelay; ! if (remainingDelay > 50) { ! System.out.println("CCC timeout:"+remainingDelay); try { ! this.wait(remainingDelay); } catch (InterruptedException e) { if (isFinished()) break sendloop; } ! continue sendloop; } lTime = System.currentTimeMillis() - lTime; *************** *** 111,129 **** int nextToSend = -1; lTime = System.currentTimeMillis(); ! do { ! for (int x = 0; x < Dijjer.PACKETS_IN_BLOCK; x++) { ! if (_prb.isReceived(x) && !_sent.bitAt(x)) { ! nextToSend = x; ! break; ! } } ! if (nextToSend == -1) { ! try { ! this.wait(); ! } catch (InterruptedException e) { ! if (isFinished()) break sendloop; ! } } ! } while (nextToSend == -1); lTime = System.currentTimeMillis() - lTime; if (lTime > 3000) { --- 111,128 ---- int nextToSend = -1; lTime = System.currentTimeMillis(); ! for (int x = 0; x < Dijjer.PACKETS_IN_BLOCK; x++) { ! if (_prb.isReceived(x) && !_sent.bitAt(x)) { ! nextToSend = x; ! break; } ! } ! if (nextToSend == -1) { ! try { ! this.wait(); ! } catch (InterruptedException e) { ! if (isFinished()) break sendloop; } ! continue sendloop; ! } lTime = System.currentTimeMillis() - lTime; if (lTime > 3000) { |