Skip to content
Snippets Groups Projects
Commit c3d1fbcc authored by Terry D. Norbraten's avatar Terry D. Norbraten
Browse files

attempt to close Sever by normal thread death

parent 8594ef31
No related branches found
No related tags found
No related merge requests found
......@@ -61,8 +61,7 @@ public class LiFiBenchmark
public static void main(String[] args)
{
LiFiBenchmark bm = new LiFiBenchmark(args);
bm.start();
new LiFiBenchmark(args).start();
}
public LiFiBenchmark(String[] args)
......@@ -110,16 +109,19 @@ public class LiFiBenchmark
}
int repsCount = reps;
int discardsCount = discards;
long readAcc;
long startms;
int read;
byte[] buff;
while (repsCount-- > 0) {
long readAcc;
long startms = System.currentTimeMillis();
startms = System.currentTimeMillis();
try (Socket sock = new Socket(targetIp, targetPort)) {
readAcc = 0l;
byte[] buff = new byte[READ_BUFFER_SIZE];
buff = new byte[READ_BUFFER_SIZE];
while (true) {
int read = sock.getInputStream().read(buff);
read = sock.getInputStream().read(buff);
if (read == -1)
break;
readAcc += read;
......@@ -140,8 +142,10 @@ public class LiFiBenchmark
private void doServer()
{
ServerSocket ssock = null;
try {
ServerSocket ssock = new ServerSocket(targetPort);
ssock = new ServerSocket(targetPort);
System.out.println("Serving from "+Inet4Address.getLocalHost().getHostAddress());
System.out.println("Waiting on port "+targetPort);
......@@ -155,27 +159,46 @@ public class LiFiBenchmark
catch (IOException ex) {
System.err.println("Exception waiting for connections: "+ex.getMessage());
System.exit(-1);
}
}
} finally {
try {
if (ssock != null)
ssock.close();
} catch (IOException ex) {}
}
}
private void handleConnection(Socket sock)
{
new Thread(() -> {
Thread thread = new Thread(() -> {
byte[] ba = new byte[WRITE_BUFFER_SIZE];
int wrote=0;
byte fill = 0;
try {
while (true) {
Arrays.fill(ba, fill++);
// The pipe will be broken by the networkRead method due to read limit
// imposed
sock.getOutputStream().write(ba);
wrote+=ba.length;
}
}
catch (IOException ex) {
System.err.println("Shutting down: " + ex.getClass().getSimpleName() + ": " + ex.getLocalizedMessage());
System.err.println("Wrote "+wrote);
String pre = "Shutting down";
String msg = ex.getClass().getSimpleName() + ": " + ex.getLocalizedMessage();
if (msg.contains("Broken pipe"))
System.out.print(pre);
else
System.err.println(pre + ": " + msg);
} finally {
try {
sock.close();
} catch (IOException ex) {}
System.out.println("\nWrote "+wrote + " bytes");
}
}).start();
});
thread.setDaemon(true);
thread.start();
}
private long handleSize(String s)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment