network connector to reconnect on proxy timeout

This commit is contained in:
rusefi 2020-07-25 20:05:37 -04:00
parent ec2accd9d7
commit 7d495c4824
3 changed files with 5 additions and 3 deletions

View File

@ -20,7 +20,7 @@ public interface ByteReader {
Logging log = getLogging(ByteReader.class); Logging log = getLogging(ByteReader.class);
static void runReaderLoop(String loggingPrefix, DataListener listener, ByteReader reader, TcpIoStream.DisconnectListener disconnectListener, AbstractIoStream ioStream) { static void runReaderLoop(String loggingPrefix, DataListener listener, ByteReader reader, AbstractIoStream ioStream) {
/** /**
* Threading of the whole input/output does not look healthy at all! * Threading of the whole input/output does not look healthy at all!
* *
@ -40,7 +40,7 @@ public interface ByteReader {
listener.onDataArrived(Arrays.copyOf(inputBuffer, result)); listener.onDataArrived(Arrays.copyOf(inputBuffer, result));
} catch (IOException e) { } catch (IOException e) {
log.error("TcpIoStream: End of connection " + e); log.error("TcpIoStream: End of connection " + e);
disconnectListener.onDisconnect(); ioStream.close();
return; return;
} }
} }

View File

@ -53,6 +53,7 @@ public class TcpIoStream extends AbstractIoStream {
public void close() { public void close() {
super.close(); super.close();
FileUtil.close(socket); FileUtil.close(socket);
disconnectListener.onDisconnect();
} }
@Override @Override
@ -78,7 +79,7 @@ public class TcpIoStream extends AbstractIoStream {
@Override @Override
public void setInputListener(final DataListener listener) { public void setInputListener(final DataListener listener) {
ByteReader.runReaderLoop(loggingPrefix, listener, input::read, disconnectListener, this); ByteReader.runReaderLoop(loggingPrefix, listener, input::read, this);
} }
public interface DisconnectListener { public interface DisconnectListener {

View File

@ -59,6 +59,7 @@ public class BaseBroadcastingThread {
} }
} catch (IOException e) { } catch (IOException e) {
log.error("exiting thread " + e); log.error("exiting thread " + e);
stream.close();
} }
}); });
} }