On Thursday 10 January 2008 16:40, robert at freenetproject.org wrote: > Author: robert > Date: 2008-01-10 16:40:27 +0000 (Thu, 10 Jan 2008) > New Revision: 16993 > > Modified: > trunk/freenet/src/freenet/io/xfer/BlockTransmitter.java > Log: > simplify _senderThread
You've removed the resetting of timeAllSent when _unsent.size() == 0. The rest
is reasonable refactoring.
>
>
> Modified: trunk/freenet/src/freenet/io/xfer/BlockTransmitter.java
> ===================================================================
> --- trunk/freenet/src/freenet/io/xfer/BlockTransmitter.java 2008-01-10
15:06:43 UTC (rev 16992)
> +++ trunk/freenet/src/freenet/io/xfer/BlockTransmitter.java 2008-01-10
16:40:27 UTC (rev 16993)
> @@ -81,61 +81,50 @@
> public void run() {
> while (!_sendComplete) {
> long startCycleTime =
> System.currentTimeMillis();
> + int packetNo;
> try {
> - while (true) {
> -
> synchronized(_senderThread) {
> -
> if(_unsent.size() != 0) {
> -
> timeAllSent = -1;
> - break;
> - }
> - // No unsent
> packets
> - if(getNumSent()
> == _prb.getNumPackets()) {
> - //No
> unreceived packets
> -
> if(Logger.shouldLog(Logger.MINOR, this))
> -
> Logger.minor(this, "Sent all blocks, none unsent");
> -
> if(timeAllSent <= 0)
> -
> timeAllSent = System.currentTimeMillis();
> - }
> + synchronized(_senderThread) {
> + while (_unsent.size()
> == 0) {
>
> if(_sendComplete) return;
>
> _senderThread.wait(10*1000);
> }
> - }
> - } catch (InterruptedException e) {
> - } catch (AbortedException e) {
> - synchronized(_senderThread) {
> - _sendComplete = true;
> -
> _senderThread.notifyAll();
> - }
> - return;
> - }
> - int packetNo;
> - try {
> - synchronized(_senderThread) {
> packetNo = ((Integer)
> _unsent.removeFirst()).intValue();
> }
> - } catch (NoSuchElementException nsee) {
> - // back up to the top to check
> for completion
> + } catch (InterruptedException e) {
> + Logger.error(this,
> "_senderThread interrupted");
> continue;
> }
> - delay(startCycleTime);
> - if(_sendComplete) break;
> - _sentPackets.setBit(packetNo, true);
> + int totalPackets;
> try {
>
> _destination.sendAsync(DMT.createPacketTransmit(_uid, packetNo,
_sentPackets, _prb.getPacket(packetNo)), null, PACKET_SIZE, _ctr);
> _ctr.sentPayload(PACKET_SIZE);
> +
> totalPackets=_prb.getNumPackets();
> } catch (NotConnectedException e) {
> Logger.normal(this,
> "Terminating send: "+e);
> synchronized(_senderThread) {
> _sendComplete = true;
>
> _senderThread.notifyAll();
> + return;
> }
> } catch (AbortedException e) {
> Logger.normal(this,
> "Terminating send due to abort: "+e);
> synchronized(_senderThread) {
> _sendComplete = true;
>
> _senderThread.notifyAll();
> + return;
> }
> }
> + synchronized (_senderThread) {
> + _sentPackets.setBit(packetNo,
> true);
> + if(_unsent.size() == 0 &&
> getNumSent() == totalPackets) {
> + //No unsent packets, no
> unreceived packets
> + timeAllSent =
> System.currentTimeMillis();
> +
> if(Logger.shouldLog(Logger.MINOR, this))
> +
> Logger.minor(this, "Sent all blocks, none unsent");
> +
> _senderThread.notifyAll();
> + }
> + }
> + delay(startCycleTime);
> }
> }
>
>
> _______________________________________________
> cvs mailing list
> cvs at freenetproject.org
> http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL:
<https://emu.freenetproject.org/pipermail/devl/attachments/20080112/fa03f076/attachment.pgp>
