summaryrefslogtreecommitdiff
path: root/clientserver
diff options
context:
space:
mode:
authorRobby <robby@santoslab.org>2018-03-29 11:32:27 -0500
committerGitHub <noreply@github.com>2018-03-29 11:32:27 -0500
commit41ca6c22894e863f5042cd8f49f5c3c6d52acc23 (patch)
treefdb4c025137047a8dbe17b31544f67c0ee5a3a93 /clientserver
parent680364fa3658027ff494dc4fac1d2fcdb8fec8b3 (diff)
downloadmill-41ca6c22894e863f5042cd8f49f5c3c6d52acc23.tar.gz
mill-41ca6c22894e863f5042cd8f49f5c3c6d52acc23.tar.bz2
mill-41ca6c22894e863f5042cd8f49f5c3c6d52acc23.zip
Windows client/server improvements (#262)
Diffstat (limited to 'clientserver')
-rw-r--r--clientserver/src/mill/clientserver/Client.java30
-rw-r--r--clientserver/src/mill/clientserver/ClientServer.java3
2 files changed, 22 insertions, 11 deletions
diff --git a/clientserver/src/mill/clientserver/Client.java b/clientserver/src/mill/clientserver/Client.java
index e2a92f7f..c4cbc265 100644
--- a/clientserver/src/mill/clientserver/Client.java
+++ b/clientserver/src/mill/clientserver/Client.java
@@ -25,7 +25,7 @@ public class Client {
}
current = current.getParent();
}
- if (!System.getProperty("java.specification.version").startsWith("1.")) {
+ if (ClientServer.isJava9OrAbove) {
selfJars.addAll(Arrays.asList(System.getProperty("java.class.path").split(File.pathSeparator)));
}
ArrayList<String> l = new java.util.ArrayList<String>();
@@ -166,14 +166,15 @@ class ClientOutputPumper implements Runnable{
this.dest2 = dest2;
}
- boolean running = true;
public void run() {
byte[] buffer = new byte[1024];
int state = 0;
- try {
- while(running){
-
+ boolean running = true;
+ boolean first = true;
+ while (running) {
+ try {
int n = src.read(buffer);
+ first = false;
if (n == -1) running = false;
else {
int i = 0;
@@ -197,12 +198,21 @@ class ClientOutputPumper implements Runnable{
dest1.flush();
dest2.flush();
}
+ } catch (IOException e) {
+ // Win32NamedPipeSocket input stream somehow doesn't return -1,
+ // instead it throws an IOException whose message contains "ReadFile()".
+ // However, if it throws an IOException before ever reading some bytes,
+ // it could not connect to the server, so exit.
+ if (ClientServer.isWindows && e.getMessage().contains("ReadFile()")) {
+ if (first) {
+ System.err.println("Failed to connect to server");
+ System.exit(1);
+ } else running = false;
+ } else {
+ e.printStackTrace();
+ System.exit(1);
+ }
}
- }catch(IOException e){
- // Win32NamedPipeSocket input stream somehow doesn't return -1,
- // but throw IOException whose message contains "ReadFile()" with a ccode
- if (ClientServer.isWindows && e.getMessage().contains("ReadFile()")) running = false;
- else throw new RuntimeException(e);
}
}
diff --git a/clientserver/src/mill/clientserver/ClientServer.java b/clientserver/src/mill/clientserver/ClientServer.java
index 7af5845b..e2e63dcf 100644
--- a/clientserver/src/mill/clientserver/ClientServer.java
+++ b/clientserver/src/mill/clientserver/ClientServer.java
@@ -5,8 +5,9 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-class ClientServer {
+public class ClientServer {
public static boolean isWindows = System.getProperty("os.name").toLowerCase().startsWith("windows");
+ public static boolean isJava9OrAbove = !System.getProperty("java.specification.version").startsWith("1.");
// Windows named pipe prefix (see https://github.com/sbt/ipcsocket/blob/v1.0.0/README.md)
// Win32NamedPipeServerSocket automatically adds this as a prefix (if it is not already is prefixed),