Skip to content

Commit

Permalink
jPOS-94 set SO_KEEPALIVE as well as SO_TIMEOUT
Browse files Browse the repository at this point in the history
Hijacked the applyTimeout() method in order to call setKeepAlive too.

I was keen to rename the method to applyTimeoutAndKeepAlive but

   a) it was too long and
   b) it's protected and a published API so I guess we can live with
      the slightly incorrect name instead of potentially breaking
      user code.
  • Loading branch information
ar committed Oct 16, 2012
1 parent df5e9fe commit caeac71
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions jpos/src/main/java/org/jpos/iso/BaseChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,17 @@ public void setTimeout (int timeout) throws SocketException {
public int getTimeout () {
return timeout;
}

/**
* sets timeout, and also keep alive
* @throws SocketException
*/
protected void applyTimeout () throws SocketException {
if (timeout >= 0 && socket != null)
socket.setSoTimeout (timeout);
if (socket != null) {
socket.setKeepAlive(keepAlive);
if (timeout >= 0)
socket.setSoTimeout(timeout);
}
}
/**
* Socket SO_LINGER option to use when closing the socket.
Expand Down Expand Up @@ -390,8 +398,6 @@ public void connect () throws IOException {
connect(newSocket (hosts, ports, evt));
}
applyTimeout();
if (socket != null)
socket.setKeepAlive (keepAlive);
Logger.log (evt);
setChanged();
notifyObservers();
Expand Down

0 comments on commit caeac71

Please sign in to comment.