Skip to content
Permalink
Browse files
Use the scale in the var name.
We use milliseconds everywhere except in one API where we use seconds.
  • Loading branch information
garydgregory authored and arturobernalg committed Feb 6, 2021
1 parent edb6d11 commit e15bdfe258c1807e16fcaa675b089844bef71844
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 132 deletions.
@@ -94,8 +94,8 @@ public static void main(final String[] args) throws UnknownHostException
boolean mlst = false, mlsd = false, mdtm = false, saveUnparseable = false;
boolean size = false;
boolean lenient = false;
long keepAliveTimeout = -1;
int controlKeepAliveReplyTimeout = -1;
long keepAliveTimeoutSeconds = -1;
int controlKeepAliveReplyTimeoutMillis = -1;
int minParams = 5; // listings require 3 params
String protocol = null; // SSL protocol
String doCommand = null;
@@ -156,7 +156,7 @@ else if (args[base].equals("-i")) {
minParams = 3;
}
else if (args[base].equals("-k")) {
keepAliveTimeout = Long.parseLong(args[++base]);
keepAliveTimeoutSeconds = Long.parseLong(args[++base]);
}
else if (args[base].equals("-l")) {
listFiles = true;
@@ -187,7 +187,7 @@ else if (args[base].equals("-U")) {
saveUnparseable = true;
}
else if (args[base].equals("-w")) {
controlKeepAliveReplyTimeout = Integer.parseInt(args[++base]);
controlKeepAliveReplyTimeoutMillis = Integer.parseInt(args[++base]);
}
else if (args[base].equals("-T")) {
trustmgr = args[++base];
@@ -297,11 +297,11 @@ else if (args[base].equals("-#")) {
if (printHash) {
ftp.setCopyStreamListener(createListener());
}
if (keepAliveTimeout >= 0) {
ftp.setControlKeepAliveTimeout(keepAliveTimeout);
if (keepAliveTimeoutSeconds >= 0) {
ftp.setControlKeepAliveTimeout(keepAliveTimeoutSeconds);
}
if (controlKeepAliveReplyTimeout >= 0) {
ftp.setControlKeepAliveReplyTimeout(controlKeepAliveReplyTimeout);
if (controlKeepAliveReplyTimeoutMillis >= 0) {
ftp.setControlKeepAliveReplyTimeout(controlKeepAliveReplyTimeoutMillis);
}
if (encoding != null) {
ftp.setControlEncoding(encoding);
@@ -401,7 +401,7 @@ else if (args[base].equals("-#")) {
ftp.storeFile(remote, input);
}

if (keepAliveTimeout > 0) {
if (keepAliveTimeoutSeconds > 0) {
showCslStats(ftp);
}
}
@@ -505,7 +505,7 @@ else if (doCommand != null)
ftp.retrieveFile(remote, output);
}

if (keepAliveTimeout > 0) {
if (keepAliveTimeoutSeconds > 0) {
showCslStats(ftp);
}
}
@@ -123,7 +123,7 @@ public static void processResponse(final TimeInfo info)
final TimeStamp origNtpTime = message.getOriginateTimeStamp();
System.out.println(" Originate Timestamp:\t" + origNtpTime + " " + origNtpTime.toDateString());

final long destTime = info.getReturnTime();
final long destTimeMillis = info.getReturnTime();
// Receive Time is time request received by server (t2)
final TimeStamp rcvNtpTime = message.getReceiveTimeStamp();
System.out.println(" Receive Timestamp:\t" + rcvNtpTime + " " + rcvNtpTime.toDateString());
@@ -133,14 +133,14 @@ public static void processResponse(final TimeInfo info)
System.out.println(" Transmit Timestamp:\t" + xmitNtpTime + " " + xmitNtpTime.toDateString());

// Destination time is time reply received by client (t4)
final TimeStamp destNtpTime = TimeStamp.getNtpTime(destTime);
final TimeStamp destNtpTime = TimeStamp.getNtpTime(destTimeMillis);
System.out.println(" Destination Timestamp:\t" + destNtpTime + " " + destNtpTime.toDateString());

info.computeDetails(); // compute offset/delay if not already done
final Long offsetValue = info.getOffset();
final Long delayValue = info.getDelay();
final String delay = delayValue == null ? "N/A" : delayValue.toString();
final String offset = offsetValue == null ? "N/A" : offsetValue.toString();
final Long offsetMillis = info.getOffset();
final Long delayMillis = info.getDelay();
final String delay = delayMillis == null ? "N/A" : delayMillis.toString();
final String offset = offsetMillis == null ? "N/A" : offsetMillis.toString();

System.out.println(" Roundtrip delay(ms)=" + delay
+ ", clock offset(ms)=" + offset); // offset in ms
@@ -358,7 +358,7 @@ public class FTPClient extends FTP
public static final int PASSIVE_REMOTE_DATA_CONNECTION_MODE = 3;

private int dataConnectionMode;
private int dataTimeout;
private int dataTimeoutMillis;
private int passivePort;
private String passiveHost;
private final Random random;
@@ -402,11 +402,11 @@ public class FTPClient extends FTP
private CopyStreamListener copyStreamListener;

// How long to wait before sending another control keep-alive message
private long controlKeepAliveTimeout;
private long controlKeepAliveTimeoutMillis;

// How long to wait (ms) for keepalive message replies before continuing
// How long to wait (millis) for keepalive message replies before continuing
// Most FTP servers don't seem to support concurrent control and data connection usage
private int controlKeepAliveReplyTimeout = 1000;
private int controlKeepAliveReplyTimeoutMillis = 1000;

// Debug counts for NOOP acks
private int[] cslDebug;
@@ -481,7 +481,7 @@ private static Properties getOverrideProperties(){
public FTPClient()
{
initDefaults();
dataTimeout = -1;
dataTimeoutMillis = -1;
remoteVerificationEnabled = true;
parserFactory = new DefaultFTPFileEntryParserFactory();
configuration = null;
@@ -675,8 +675,8 @@ protected boolean _storeFile(final String command, final String remote, final In
}

CSL csl = null;
if (controlKeepAliveTimeout > 0) {
csl = new CSL(this, controlKeepAliveTimeout, controlKeepAliveReplyTimeout);
if (controlKeepAliveTimeoutMillis > 0) {
csl = new CSL(this, controlKeepAliveTimeoutMillis, controlKeepAliveReplyTimeoutMillis);
}

// Treat everything else as binary for now
@@ -858,14 +858,14 @@ protected Socket _openDataConnection_(final String command, final String arg)
// the data connection. It may be desirable to let this be a
// separately configurable value. In any case, we really want
// to allow preventing the accept from blocking indefinitely.
if (dataTimeout >= 0) {
server.setSoTimeout(dataTimeout);
if (dataTimeoutMillis >= 0) {
server.setSoTimeout(dataTimeoutMillis);
}
socket = server.accept();

// Ensure the timeout is set before any commands are issued on the new socket
if (dataTimeout >= 0) {
socket.setSoTimeout(dataTimeout);
if (dataTimeoutMillis >= 0) {
socket.setSoTimeout(dataTimeoutMillis);
}
if (receiveDataSocketBufferSize > 0) {
socket.setReceiveBufferSize(receiveDataSocketBufferSize);
@@ -917,8 +917,8 @@ protected Socket _openDataConnection_(final String command, final String arg)
// the data connection. It may be desirable to let this be a
// separately configurable value. In any case, we really want
// to allow preventing the accept from blocking indefinitely.
if (dataTimeout >= 0) {
socket.setSoTimeout(dataTimeout);
if (dataTimeoutMillis >= 0) {
socket.setSoTimeout(dataTimeoutMillis);
}

socket.connect(new InetSocketAddress(passiveHost, passivePort), connectTimeout);
@@ -998,12 +998,12 @@ protected void _connectAction_(final Reader socketIsReader) throws IOException
* <p>
* <b>Note:</b> the timeout will also be applied when calling accept()
* whilst establishing an active local data connection.
* @param timeout The default timeout in milliseconds that is used when
* @param timeoutMillis The default timeout in milliseconds that is used when
* opening a data connection socket. The value 0 means an infinite timeout.
*/
public void setDataTimeout(final int timeout)
public void setDataTimeout(final int timeoutMillis)
{
dataTimeout = timeout;
dataTimeoutMillis = timeoutMillis;
}

/**
@@ -1912,8 +1912,8 @@ protected boolean _retrieveFile(final String command, final String remote, final
input = getBufferedInputStream(socket.getInputStream());
}

if (controlKeepAliveTimeout > 0) {
csl = new CSL(this, controlKeepAliveTimeout, controlKeepAliveReplyTimeout);
if (controlKeepAliveTimeoutMillis > 0) {
csl = new CSL(this, controlKeepAliveTimeoutMillis, controlKeepAliveReplyTimeoutMillis);
}

// Treat everything else as binary for now
@@ -3803,16 +3803,16 @@ public CopyStreamListener getCopyStreamListener(){
* <p>
* See the class Javadoc section "Control channel keep-alive feature:"
*
* @param controlIdle the wait (in seconds) between keepalive messages. Zero (or less) disables.
* @param controlIdleSeconds the wait (in seconds) between keepalive messages. Zero (or less) disables.
* @since 3.0
* @see #setControlKeepAliveReplyTimeout(int)
*/
public void setControlKeepAliveTimeout(final long controlIdle){
controlKeepAliveTimeout = controlIdle * 1000;
public void setControlKeepAliveTimeout(final long controlIdleSeconds){
controlKeepAliveTimeoutMillis = controlIdleSeconds * 1000;
}

/**
* Get the time to wait between sending control connection keepalive messages
* Gets the time to wait between sending control connection keepalive messages
* when processing file upload or download.
* <p>
* See the class Javadoc section "Control channel keep-alive feature:"
@@ -3821,7 +3821,7 @@ public void setControlKeepAliveTimeout(final long controlIdle){
* @since 3.0
*/
public long getControlKeepAliveTimeout() {
return controlKeepAliveTimeout / 1000;
return controlKeepAliveTimeoutMillis / 1000;
}

/**
@@ -3843,28 +3843,29 @@ public long getControlKeepAliveTimeout() {
public int[] getCslDebug() {
return cslDebug;
}

/**
* Set how long to wait for control keep-alive message replies.
* Sets how long to wait for control keep-alive message replies.
*
* @param timeout number of milliseconds to wait (defaults to 1000)
* @param timeoutMillis number of milliseconds to wait (defaults to 1000)
* @since 3.0
* @see #setControlKeepAliveTimeout(long)
*/
public void setControlKeepAliveReplyTimeout(final int timeout) {
controlKeepAliveReplyTimeout = timeout;
public void setControlKeepAliveReplyTimeout(final int timeoutMillis) {
controlKeepAliveReplyTimeoutMillis = timeoutMillis;
}

/**
* Get how long to wait for control keep-alive message replies.
* @return wait time in msec
* Gets how long to wait for control keep-alive message replies.
* @return wait time in milliseconds.
* @since 3.0
*/
public int getControlKeepAliveReplyTimeout() {
return controlKeepAliveReplyTimeout;
return controlKeepAliveReplyTimeoutMillis;
}

/**
* Enable or disable passive mode NAT workaround.
* Enables or disables passive mode NAT workaround.
* If enabled, a site-local PASV mode reply address will be replaced with the
* remote host address to which the PASV mode request was sent
* (unless that is also a site local address).
@@ -3954,19 +3955,19 @@ private InputStream getBufferedInputStream(final InputStream inputStream) {
private static class CSL implements CopyStreamListener {

private final FTPClient parent;
private final long idle;
private final int currentSoTimeout;
private final long idleMillis;
private final int currentSoTimeoutMillis;

private long time = System.currentTimeMillis();
private long timeMillis = System.currentTimeMillis();
private int notAcked;
private int acksAcked;
private int ioErrors;

CSL(final FTPClient parent, final long idleTime, final int maxWait) throws SocketException {
this.idle = idleTime;
CSL(final FTPClient parent, final long idleTimeMillis, final int maxWaitMillis) throws SocketException {
this.idleMillis = idleTimeMillis;
this.parent = parent;
this.currentSoTimeout = parent.getSoTimeout();
parent.setSoTimeout(maxWait);
this.currentSoTimeoutMillis = parent.getSoTimeout();
parent.setSoTimeout(maxWaitMillis);
}

@Override
@@ -3977,8 +3978,8 @@ public void bytesTransferred(final CopyStreamEvent event) {
@Override
public void bytesTransferred(final long totalBytesTransferred,
final int bytesTransferred, final long streamSize) {
final long now = System.currentTimeMillis();
if (now - time > idle) {
final long nowMillis = System.currentTimeMillis();
if (nowMillis - timeMillis > idleMillis) {
try {
parent.__noop();
acksAcked++;
@@ -3988,7 +3989,7 @@ public void bytesTransferred(final long totalBytesTransferred,
ioErrors++;
// Ignored
}
time = now;
timeMillis = nowMillis;
}
}

@@ -4002,7 +4003,7 @@ int[] cleanUp() throws IOException {
} catch (final SocketTimeoutException e) { // NET-584
// ignored
} finally {
parent.setSoTimeout(currentSoTimeout);
parent.setSoTimeout(currentSoTimeoutMillis);
}
return new int [] {acksAcked, remain, notAcked, ioErrors}; // debug counts
}
@@ -89,11 +89,9 @@ public TimeInfo getTime(final InetAddress host, final int port) throws IOExcepti
_socket_.send(sendPacket);
_socket_.receive(receivePacket);

final long returnTime = System.currentTimeMillis();
final long returnTimeMillis = System.currentTimeMillis();
// create TimeInfo message container but don't pre-compute the details yet
final TimeInfo info = new TimeInfo(recMessage, returnTime, false);

return info;
return new TimeInfo(recMessage, returnTimeMillis, false);
}

/**

0 comments on commit e15bdfe

Please sign in to comment.