forked from MirrorHub/authlib-injector
nanohttpd: refactor: remove socket timeout parameter
This commit is contained in:
parent
85f38d47ac
commit
cda96f96e1
1 changed files with 11 additions and 31 deletions
|
@ -160,16 +160,17 @@ public abstract class NanoHTTPD {
|
||||||
*/
|
*/
|
||||||
private class ServerRunnable implements Runnable {
|
private class ServerRunnable implements Runnable {
|
||||||
|
|
||||||
private final int timeout;
|
/**
|
||||||
|
* Maximum time to wait on Socket.getInputStream().read() (in milliseconds)
|
||||||
|
* This is required as the Keep-Alive HTTP connections would otherwise block
|
||||||
|
* the socket reading thread forever (or as long the browser is open).
|
||||||
|
*/
|
||||||
|
private static final int SOCKET_READ_TIMEOUT = 5000;
|
||||||
|
|
||||||
private IOException bindException;
|
private IOException bindException;
|
||||||
|
|
||||||
private boolean hasBinded = false;
|
private boolean hasBinded = false;
|
||||||
|
|
||||||
public ServerRunnable(int timeout) {
|
|
||||||
this.timeout = timeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
|
@ -183,9 +184,7 @@ public abstract class NanoHTTPD {
|
||||||
try {
|
try {
|
||||||
@SuppressWarnings("resource")
|
@SuppressWarnings("resource")
|
||||||
final Socket finalAccept = NanoHTTPD.this.myServerSocket.accept();
|
final Socket finalAccept = NanoHTTPD.this.myServerSocket.accept();
|
||||||
if (this.timeout > 0) {
|
finalAccept.setSoTimeout(SOCKET_READ_TIMEOUT);
|
||||||
finalAccept.setSoTimeout(this.timeout);
|
|
||||||
}
|
|
||||||
@SuppressWarnings("resource")
|
@SuppressWarnings("resource")
|
||||||
final InputStream inputStream = finalAccept.getInputStream();
|
final InputStream inputStream = finalAccept.getInputStream();
|
||||||
NanoHTTPD.this.asyncRunner.exec(new ClientHandler(inputStream, finalAccept));
|
NanoHTTPD.this.asyncRunner.exec(new ClientHandler(inputStream, finalAccept));
|
||||||
|
@ -196,13 +195,6 @@ public abstract class NanoHTTPD {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Maximum time to wait on Socket.getInputStream().read() (in milliseconds)
|
|
||||||
* This is required as the Keep-Alive HTTP connections would otherwise block
|
|
||||||
* the socket reading thread forever (or as long the browser is open).
|
|
||||||
*/
|
|
||||||
public static final int SOCKET_READ_TIMEOUT = 5000;
|
|
||||||
|
|
||||||
static final void safeClose(Object closeable) {
|
static final void safeClose(Object closeable) {
|
||||||
try {
|
try {
|
||||||
if (closeable != null) {
|
if (closeable != null) {
|
||||||
|
@ -281,37 +273,25 @@ public abstract class NanoHTTPD {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start the server.
|
* Starts the server in daemon mode.
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
* if the socket is in use.
|
|
||||||
*/
|
*/
|
||||||
public void start() throws IOException {
|
public void start() throws IOException {
|
||||||
start(NanoHTTPD.SOCKET_READ_TIMEOUT);
|
start(true);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Starts the server (in setDaemon(true) mode).
|
|
||||||
*/
|
|
||||||
public void start(final int timeout) throws IOException {
|
|
||||||
start(timeout, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start the server.
|
* Start the server.
|
||||||
*
|
*
|
||||||
* @param timeout
|
|
||||||
* timeout to use for socket connections.
|
|
||||||
* @param daemon
|
* @param daemon
|
||||||
* start the thread daemon or not.
|
* start the thread daemon or not.
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* if the socket is in use.
|
* if the socket is in use.
|
||||||
*/
|
*/
|
||||||
public void start(final int timeout, boolean daemon) throws IOException {
|
public void start(boolean daemon) throws IOException {
|
||||||
this.myServerSocket = new ServerSocket();
|
this.myServerSocket = new ServerSocket();
|
||||||
this.myServerSocket.setReuseAddress(true);
|
this.myServerSocket.setReuseAddress(true);
|
||||||
|
|
||||||
ServerRunnable serverRunnable = new ServerRunnable(timeout);
|
ServerRunnable serverRunnable = new ServerRunnable();
|
||||||
this.myThread = new Thread(serverRunnable);
|
this.myThread = new Thread(serverRunnable);
|
||||||
this.myThread.setDaemon(daemon);
|
this.myThread.setDaemon(daemon);
|
||||||
this.myThread.setName("NanoHttpd Main Listener");
|
this.myThread.setName("NanoHttpd Main Listener");
|
||||||
|
|
Loading…
Reference in a new issue