Skip to content

Instantly share code, notes, and snippets.

@ar
Created January 17, 2011 23:13
Show Gist options
  • Save ar/783675 to your computer and use it in GitHub Desktop.
Save ar/783675 to your computer and use it in GitHub Desktop.
BaseChannel.socketClose
private void closeSocket() throws IOException {
Socket s = null;
synchronized (this) {
if (socket != null) {
s = socket; // we don't want more than one thread
socket = null; // attempting to close the socket
}
}
if (s != null) {
try {
s.setSoLinger (true, 5);
s.shutdownOutput(); // This will force a TCP FIN to be sent.
} catch (SocketException e) {
// safe to ignore - can be closed already
// e.printStackTrace();
}
s.close ();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment