Description
Now there is no way to know if TFTP is progressing, so I think with a quick fix and two extra public variables this can be solved.
Attached my patch for this.
A more extended functionality with events might be better but will require more rework
Index: TFTPClient.java
===================================================================
— TFTPClient.java (revision 1773211)
+++ TFTPClient.java (working copy)
@@ -64,6 +64,12 @@
/*** The maximum number of timeouts allowed before failing. ***/
private int __maxTimeouts;
+
+ /*** The number of bytes received in the ongoing download. ***/
+ public int totalBytesReceived = 0;
+
+ /*** The number of bytes sent in the ongoing upload. ***/
+ public int totalBytesSent = 0;
/***
- Creates a TFTPClient instance with a default timeout of DEFAULT_TIMEOUT,
@@ -134,7 +140,7 @@
beginBufferedOps();
- dataLength = lastBlock = hostPort = bytesRead = 0;
+ dataLength = lastBlock = hostPort = bytesRead = totalBytesReceived = 0;
block = 1;
if (mode == TFTP.ASCII_MODE)
{ @@ -277,6 +283,8 @@ ack.setBlockNumber(lastBlock); sent = ack; bytesRead += dataLength; + + totalBytesReceived += dataLength; }// First data packet less than 512 bytes signals end of stream.
while (dataLength == TFTPPacket.SEGMENT_SIZE);
@@ -385,7 +393,7 @@
beginBufferedOps();
- dataLength = lastBlock = hostPort = bytesRead = totalThisPacket = 0;
+ dataLength = lastBlock = hostPort = bytesRead = totalThisPacket = totalBytesSent = 0;
block = 0;
boolean lastAckWait = false;
@@ -538,15 +546,18 @@
/* this will be our last packet – send, wait for ack, stop */
lastAckWait = true;
}
+
data.setBlockNumber(block);
data.setData(_sendBuffer, 4, totalThisPacket);
sent = data;
+
+ totalBytesSent += totalThisPacket;
}
while ( totalThisPacket > 0 || lastAckWait );
// Note: this was looping while dataLength == 0 || lastAckWait,
// which was discarding the last packet if it was not full size
// Should send the packet.
-
+
endBufferedOps();
}