Skip to content

Commit

Permalink
Merge pull request #5449 from salachi/TIMOB-14874
Browse files Browse the repository at this point in the history
[TIMOB-14874] Check for closed state before closing the socket again
  • Loading branch information
hieupham007 committed Apr 18, 2014
2 parents f79c13f + c279bd7 commit 37dac39
Showing 1 changed file with 12 additions and 2 deletions.
Expand Up @@ -235,6 +235,10 @@ public void run()
while(true) {
if(accepting) {
try {
// Check if serverSocket is valid, if not exit
if (serverSocket == null) {
break;
}
Socket acceptedSocket = serverSocket.accept();

TCPProxy acceptedTcpProxy = new TCPProxy();
Expand Down Expand Up @@ -403,8 +407,10 @@ public int read(Object args[]) throws IOException

} catch (IOException e) {
e.printStackTrace();
closeSocket();
updateState(SocketModule.ERROR, "error", buildErrorCallbackArgs("Unable to read from socket, IO error", 0));
if (state != SocketModule.CLOSED) {
closeSocket();
updateState(SocketModule.ERROR, "error", buildErrorCallbackArgs("Unable to read from socket, IO error", 0));
}
throw new IOException("Unable to read from socket, IO error");
}
}
Expand Down Expand Up @@ -484,6 +490,10 @@ public boolean isReadable()
@Kroll.method
public void close() throws IOException
{
if (state == SocketModule.CLOSED) {
return;
}

if((state != SocketModule.CONNECTED) && (state != SocketModule.LISTENING)) {
throw new IOException("Socket is not connected or listening, unable to call close on socket in <" + state + "> state");
}
Expand Down

0 comments on commit 37dac39

Please sign in to comment.