mirror of
https://github.com/f-droid/fdroidclient.git
synced 2026-06-23 07:10:11 -04:00
create testable LocalHTTPDManager for controlling the webserver
The RxJava tricks were a nightmare...
This commit is contained in:
@@ -63,6 +63,9 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.nio.charset.Charset;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
@@ -887,4 +890,26 @@ public final class Utils {
|
||||
theme.resolveAttribute(R.attr.colorPrimary, typedValue, true);
|
||||
swipeLayout.setColorSchemeColors(typedValue.data);
|
||||
}
|
||||
|
||||
public static boolean canConnectToSocket(String host, int port) {
|
||||
try {
|
||||
Socket socket = new Socket();
|
||||
socket.connect(new InetSocketAddress(host, port), 5);
|
||||
socket.close();
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
// Could not connect.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isServerSocketInUse(int port) {
|
||||
try {
|
||||
(new ServerSocket(port)).close();
|
||||
return false;
|
||||
} catch (IOException e) {
|
||||
// Could not connect.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user