Skip to content

Commit

Permalink
Only reply keep-alive if expecting it
Browse files Browse the repository at this point in the history
  • Loading branch information
barspi authored and ar committed Jul 7, 2023
1 parent d82313a commit 9e9c110
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
5 changes: 5 additions & 0 deletions jpos/src/main/java/org/jpos/iso/BaseChannel.java
Expand Up @@ -678,6 +678,11 @@ public void sendKeepAlive () throws IOException {
serverOutLock.unlock();
}
}

public boolean isExpectKeepAlive() {
return expectKeepAlive;
}

protected boolean isRejected(byte[] b) {
// VAP Header support - see VAPChannel
return false;
Expand Down
14 changes: 9 additions & 5 deletions jpos/src/main/java/org/jpos/iso/channel/ASCIIChannel.java
Expand Up @@ -76,7 +76,7 @@ public ASCIIChannel (ISOPackager p) throws IOException {
* @exception IOException
* @see ISOPackager
*/
public ASCIIChannel (ISOPackager p, ServerSocket serverSocket)
public ASCIIChannel (ISOPackager p, ServerSocket serverSocket)
throws IOException
{
super(p, serverSocket);
Expand Down Expand Up @@ -110,11 +110,15 @@ protected int getMessageLength() throws IOException, ISOException {
while (l == 0) {
serverIn.readFully(b, 0, lengthDigits);
try {
if ((l=Integer.parseInt(new String(b))) == 0) {
serverOut.write(b);
serverOut.flush();
if ((l=Integer.parseInt(new String(b))) == 0 &&
isExpectKeepAlive()) {

synchronized (serverOutLock) {
serverOut.write(b);
serverOut.flush();
}
}
} catch (NumberFormatException e) {
} catch (NumberFormatException e) {
throw new ISOException ("Invalid message length "+new String(b));
}
}
Expand Down

0 comments on commit 9e9c110

Please sign in to comment.