fix stopping of reader

This commit is contained in:
zzz
2015-11-26 15:02:47 +00:00
parent 807e5bf966
commit e5f186f61a
3 changed files with 14 additions and 13 deletions

View File

@@ -98,7 +98,7 @@ public class SAMEventHandler extends SAMClientEventListenerImpl {
else else
return _helloOk.booleanValue() ? _version : null; return _helloOk.booleanValue() ? _version : null;
} }
} catch (InterruptedException ie) {} } catch (InterruptedException ie) { return null; }
} }
} }
@@ -116,7 +116,7 @@ public class SAMEventHandler extends SAMClientEventListenerImpl {
else else
return _sessionCreateOk.booleanValue(); return _sessionCreateOk.booleanValue();
} }
} catch (InterruptedException ie) {} } catch (InterruptedException ie) { return false; }
} }
} }
@@ -134,7 +134,7 @@ public class SAMEventHandler extends SAMClientEventListenerImpl {
else else
return _streamStatusOk.booleanValue(); return _streamStatusOk.booleanValue();
} }
} catch (InterruptedException ie) {} } catch (InterruptedException ie) { return false; }
} }
} }
@@ -161,7 +161,7 @@ public class SAMEventHandler extends SAMClientEventListenerImpl {
return val; return val;
} }
} }
} catch (InterruptedException ie) {} } catch (InterruptedException ie) { return null; }
} }
} }
} }

View File

@@ -42,6 +42,7 @@ public class SAMReader {
if (_thread != null) { if (_thread != null) {
_thread.interrupt(); _thread.interrupt();
_thread = null; _thread = null;
try { _inRaw.close(); } catch (IOException ioe) {}
} }
} }
@@ -98,7 +99,7 @@ public class SAMReader {
baos.write(c); baos.write(c);
} }
if (c == -1) { if (c == -1) {
_log.error("Error reading from the SAM bridge"); _log.info("EOF reading from the SAM bridge");
break; break;
} }
} catch (IOException ioe) { } catch (IOException ioe) {
@@ -106,14 +107,12 @@ public class SAMReader {
break; break;
} }
String line = new String(baos.toByteArray()); String line = "";
try {
line = new String(baos.toByteArray(), "ISO-8859-1");
} catch (IOException ioe) {}
baos.reset(); baos.reset();
if (line == null) {
_log.info("No more data from the SAM bridge");
break;
}
if (_log.shouldDebug()) if (_log.shouldDebug())
_log.debug("Line read from the bridge: " + line); _log.debug("Line read from the bridge: " + line);
@@ -121,7 +120,6 @@ public class SAMReader {
if (tok.countTokens() < 2) { if (tok.countTokens() < 2) {
_log.error("Invalid SAM line: [" + line + "]"); _log.error("Invalid SAM line: [" + line + "]");
_live = false;
break; break;
} }
@@ -145,6 +143,7 @@ public class SAMReader {
processEvent(major, minor, params); processEvent(major, minor, params);
} }
_live = false;
if (_log.shouldWarn()) if (_log.shouldWarn())
_log.warn("SAMReader exiting"); _log.warn("SAMReader exiting");
} }

View File

@@ -181,12 +181,14 @@ public class SAMStreamSend {
} }
} }
private void send(OutputStream samOut, SAMEventHandler eventHandler) { private void send(OutputStream samOut, SAMEventHandler eventHandler) throws IOException {
Sender sender = new Sender(samOut, eventHandler); Sender sender = new Sender(samOut, eventHandler);
boolean ok = sender.openConnection(); boolean ok = sender.openConnection();
if (ok) { if (ok) {
I2PAppThread t = new I2PAppThread(sender, "Sender"); I2PAppThread t = new I2PAppThread(sender, "Sender");
t.start(); t.start();
} else {
throw new IOException("Sender failed to connect");
} }
} }