I am little confused about what you think is the problem here. Are you saying that if serverConnection.read(bytesReceived) returns 0, we are improperly closing the connection? That does not match with how I read the code. Based on how I read the original code (see snippet below), we should only execute the "else" clause (which performs the close and throws the exception) if bytesRead is *less than* 0 (essentially if it is -1). A bytesRead value of 0 should result in the "if" clause being executed because the test for the "if" clause is that bytesRead is *greater-than-or-equal*.
Am I mis-understanding something here?
int bytesRead = serverConnection.read(bytesReceived);
if (bytesRead >= 0) {
...
} else {
if (isOpen())
close();
//TODO do something smarter here
throw new IOException("Connection to job server severed");
}
Omry:
I am little confused about what you think is the problem here. Are you saying that if serverConnectio n.read( bytesReceived) returns 0, we are improperly closing the connection? That does not match with how I read the code. Based on how I read the original code (see snippet below), we should only execute the "else" clause (which performs the close and throws the exception) if bytesRead is *less than* 0 (essentially if it is -1). A bytesRead value of 0 should result in the "if" clause being executed because the test for the "if" clause is that bytesRead is *greater- than-or- equal*.
Am I mis-understanding something here?
int bytesRead = serverConnectio n.read( bytesReceived) ; "Connection to job server severed");
if (bytesRead >= 0) {
...
} else {
if (isOpen())
close();
//TODO do something smarter here
throw new IOException(
}