mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-24 12:46:45 +00:00
ensure socket inputstream is buffered
This commit is contained in:
parent
3134a9ad42
commit
17bb442c78
1 changed files with 13 additions and 3 deletions
|
@ -130,9 +130,11 @@ public class TcpTransport implements Transport, Closeable {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||||
|
|
||||||
while(running) {
|
while(running) {
|
||||||
try {
|
try {
|
||||||
String received = readInputStream();
|
String received = readInputStream(in);
|
||||||
if(received.contains("method") && !received.contains("error")) {
|
if(received.contains("method") && !received.contains("error")) {
|
||||||
//Handle subscription notification
|
//Handle subscription notification
|
||||||
jsonRpcServer.handle(received, subscriptionService);
|
jsonRpcServer.handle(received, subscriptionService);
|
||||||
|
@ -157,13 +159,21 @@ public class TcpTransport implements Transport, Closeable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch(IOException e) {
|
||||||
|
log.error("Error opening socket inputstream", e);
|
||||||
|
if(running) {
|
||||||
|
lastException = e;
|
||||||
|
reading = false;
|
||||||
|
readingCondition.signal();
|
||||||
|
//Allow this thread to terminate as we will need to reconnect with a new transport anyway
|
||||||
|
running = false;
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
readLock.unlock();
|
readLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String readInputStream() throws IOException {
|
protected String readInputStream(BufferedReader in) throws IOException {
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
|
||||||
String response = in.readLine();
|
String response = in.readLine();
|
||||||
|
|
||||||
if(response == null) {
|
if(response == null) {
|
||||||
|
|
Loading…
Reference in a new issue