mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-25 09:00:26 +00:00
Automatically close forked beacon connections, fix connection forwards
This commit is contained in:
parent
e0266fec6b
commit
6efad1fe42
6 changed files with 10 additions and 19 deletions
|
@ -30,7 +30,7 @@ public class BeaconConfig {
|
|||
|
||||
|
||||
public static final String BEACON_PORT_PROP = "io.xpipe.beacon.port";
|
||||
public static final int DEFAULT_PORT = 21721;
|
||||
public static final int DEFAULT_PORT = System.getProperty("os.name").startsWith("Windows") ? 21721 : 21722;
|
||||
|
||||
public static int getUsedPort() {
|
||||
if (System.getProperty(BEACON_PORT_PROP) != null) {
|
||||
|
|
|
@ -6,8 +6,6 @@ import lombok.experimental.UtilityClass;
|
|||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.ServerSocket;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Optional;
|
||||
|
@ -18,19 +16,14 @@ import java.util.Optional;
|
|||
@UtilityClass
|
||||
public class BeaconServer {
|
||||
|
||||
private static boolean isPortAvailable(int port) {
|
||||
try (var ignored = new ServerSocket(port); var ignored1 = new DatagramSocket(port)) {
|
||||
public static boolean isRunning() {
|
||||
try (var socket = new BeaconClient()) {
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isRunning() {
|
||||
var port = BeaconConfig.getUsedPort();
|
||||
return !isPortAvailable(port);
|
||||
}
|
||||
|
||||
private static void startFork(String custom) throws IOException {
|
||||
boolean print = BeaconConfig.execDebugEnabled();
|
||||
if (print) {
|
||||
|
@ -72,14 +65,17 @@ public class BeaconServer {
|
|||
}, "daemon fork syserr").start();
|
||||
}
|
||||
|
||||
public static boolean tryStart() throws Exception {
|
||||
public static boolean tryStartFork() throws Exception {
|
||||
var custom = BeaconConfig.getCustomExecCommand();
|
||||
if (custom != null) {
|
||||
System.out.println("Starting fork: " + custom);
|
||||
startFork(custom);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean tryStart() throws Exception {
|
||||
var daemonExecutable = getDaemonExecutable();
|
||||
if (daemonExecutable.isPresent()) {
|
||||
if (BeaconConfig.debugEnabled()) {
|
||||
|
@ -99,7 +95,7 @@ public class BeaconServer {
|
|||
|
||||
public static boolean tryStop(BeaconClient client) throws Exception {
|
||||
client.sendRequest(StopExchange.Request.builder().build());
|
||||
StopExchange.Response res =client.receiveResponse();
|
||||
StopExchange.Response res = client.receiveResponse();
|
||||
return res.isSuccess();
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@ public interface RawReadConnection extends DataSourceReadConnection {
|
|||
|
||||
default void forward(DataSourceConnection con) throws Exception {
|
||||
try (var tCon = (RawWriteConnection) con) {
|
||||
tCon.init();
|
||||
byte[] b;
|
||||
while ((b = readBytes(BUFFER_SIZE)).length > 0) {
|
||||
tCon.write(b);
|
||||
|
|
|
@ -11,7 +11,6 @@ public interface StructureReadConnection extends DataSourceReadConnection {
|
|||
|
||||
default void forward(DataSourceConnection con) throws Exception {
|
||||
try (var tCon = (StructureWriteConnection) con) {
|
||||
tCon.init();
|
||||
tCon.write(read());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@ public interface TextReadConnection extends DataSourceReadConnection {
|
|||
|
||||
default void forward(DataSourceConnection con) throws Exception {
|
||||
try (var tCon = (TextWriteConnection) con) {
|
||||
tCon.init();
|
||||
for (var it = lines().iterator(); it.hasNext(); ) {
|
||||
tCon.writeLine(it.next());
|
||||
}
|
||||
|
|
|
@ -78,9 +78,7 @@ public interface DataStoreProvider {
|
|||
return null;
|
||||
}
|
||||
|
||||
default DataStore defaultStore() {
|
||||
throw new ExtensionException("CLI Dialog not implemented by provider");
|
||||
}
|
||||
DataStore defaultStore();
|
||||
|
||||
default String display(DataStore store) {
|
||||
return store.toSummaryString();
|
||||
|
|
Loading…
Reference in a new issue