Skip to content

ping package

Federico Dossena edited this page Sep 12, 2019 · 1 revision
Pinger class

A Thread that uses a Connection to repeatedly ping a specified path.

A ping is defined as the time difference between the moment in which we finish sending the HTTP request, and the moment in which we start receiving the response, over a persistent HTTP connection.

Constructor:

public Pinger(Connection c, String path)
  • c: the instance of Connection to be used
  • path: path on the server where the ping should be done

Callbacks:

  • boolean onPong(long ns): called after a ping. ns is the ping time in nanoseconds. Return true to perform another ping, false to stop.
  • onError(String err): called if something goes wrong. err contains the error message

Methods:

  • stopASAP(): stops the pinging as soon as possible. Use join() to wait for the thread to die
PingStream class

A stream for the ping+jitter test. Manages a Connection and a Pinger, and handles errors according to the specified policy.

Constructor:

public DownloadStream(String server, String path, int pings, String errorHandlingMode, int connectTimeout, int soTimeout, int recvBuffer, int sendBuffer, Logger log)
  • server: URL to the server where we need to connect
  • path: path on the server where the ping can be done
  • pings: number of pings to be performed
  • errorHandlingMode: what we should do in case of errors:
    • SpeedtestConfig.ONERROR_FAIL: Fail immediately
    • SpeedtestConfig.ONERROR_ATTEMPT_RESTART: Try to reconnect. If that fails, the stream fails
    • SpeedtestConfig.ONERROR_MUST_RESTART: Keep trying to reconnect until we succeed (or stopped)
  • connectTimeout, soTimeout, recvBuffer, sendBuffer: settings for the socket created by Connection
  • log: instance of Logger that is used to report errors such as dead connections

Callbacks:

  • boolean onPong(long ns): called after a ping. ns is the ping time in nanoseconds. Return true to perform another ping, false to stop.
  • onError(String err): called if the stream fails. err contains the error message
  • onDone(): called after all the pings are done

Methods:

  • stopASAP(): asks to stop the pinging as soon as possible. The Connection will also be closed. Use join() to wait for the connection to be actually closed
  • join(): waits for the instance of Pinger to die
Clone this wiki locally