Skip to content

Commit

Permalink
[neohub] eliminate once in a blue moon fin-ack fin-ack issues
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Fiddian-Green <[email protected]>
  • Loading branch information
andrewfg committed Apr 13, 2021
1 parent 9e4b67e commit 022513e
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public NeoHubSocket(final String hostname, final int portNumber, final int timeo
* @param requestJson the message to be sent to the NeoHub
* @return responseJson received from NeoHub
* @throws NeoHubException, IOException
*
*
*/
public String sendMessage(final String requestJson) throws IOException, NeoHubException {
IOException caughtException = null;
Expand All @@ -84,15 +84,20 @@ public String sendMessage(final String requestJson) throws IOException, NeoHubEx
writer.write(requestJson);
writer.write(0); // NULL terminate the command string
writer.flush();
socket.shutdownOutput();

if (logger.isTraceEnabled()) {
logger.trace("sent {} characters..", requestJson.length());
}

int inChar;
// NULL termination, end of stream (-1), or newline
while (((inChar = reader.read()) > 0) && (inChar != '\n')) {
builder.append((char) inChar);
boolean done = false;
// read until end of stream
while ((inChar = reader.read()) != -1) {
// a JSON block is terminated by a newline or NULL
if (!(done |= (inChar == '\n') || (inChar == 0))) {
builder.append((char) inChar);
}
}
}
} catch (IOException e) {
Expand Down

0 comments on commit 022513e

Please sign in to comment.