Skip to content

Commit

Permalink
Refactoring: SocketReader is Thread instead of Runnable.
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmipt committed Nov 24, 2023
1 parent 271ba71 commit 506a125
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/kx/KConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class KConnection {
private final int port;
private final String userPassword;
private final boolean useTLS;
private boolean closed = true;
private volatile boolean closed = true;

private DataInputStream inputStream;
private OutputStream outputStream;
Expand All @@ -29,7 +29,11 @@ void io(Socket s) throws IOException {
}

public void close() {
// this will force k() to break out i hope
if (socketReader != null) {
socketReader.interrupt();
socketReader = null;
}

if (closed) return;

closed = true;
Expand Down Expand Up @@ -79,9 +83,9 @@ private void connect() throws IOException, K4AccessException {
closed = false;

socketReader = new SocketReader(s);
Thread socketReaderThread = new Thread(socketReader, "Reader " + host + ":" + port);
socketReaderThread.setDaemon(true);
socketReaderThread.start();
socketReader.setName("Reader " + host + ":" + port);
socketReader.setDaemon(true);
socketReader.start();
}

public KConnection(String h, int p, String userPassword, boolean useTLS) {
Expand Down Expand Up @@ -122,9 +126,9 @@ public K.KBase k(K.KBase x) throws K4Exception, IOException, InterruptedExceptio
return k(x, null);
}

private class SocketReader implements Runnable {
private class SocketReader extends Thread {

private DataInputStream inputStream;
private final DataInputStream inputStream;
private KMessage message = null;
private ProgressCallback progress = null;

Expand Down

0 comments on commit 506a125

Please sign in to comment.