diff --git a/src/main/java/at/downardo/j3270Server/Telnet.java b/src/main/java/at/downardo/j3270Server/Telnet.java index bbc6be6..d862f9f 100644 --- a/src/main/java/at/downardo/j3270Server/Telnet.java +++ b/src/main/java/at/downardo/j3270Server/Telnet.java @@ -139,44 +139,44 @@ public static int[] TelnetRead(BufferedInputStream in, int[] buf) throws IOExcep int state = NORMAL; int n = 0; while(n <= (buf.length-1)) { - int bufRead = in.read(); - - - - if(bufRead == 0) { - continue; - } - - - switch(state) { - case NORMAL: - if(bufRead == IAC) { - state = COMMAND; - }else { - buf[n] = bufRead; - n++; + if(in.available() > 0) { + int bufRead = in.read(); + + if(bufRead == 0) { + continue; } - break; - case COMMAND: - if(bufRead == 0xff) { - buf[n] = 0xff; + + + switch(state) { + case NORMAL: + if(bufRead == IAC) { + state = COMMAND; + }else { + buf[n] = bufRead; + n++; + } + break; + case COMMAND: + if(bufRead == 0xff) { + buf[n] = 0xff; + + n++; + state = NORMAL; + }else if(bufRead == SB) { + state = SUBNEG; + }else { + state = NORMAL; + } + break; + case SUBNEG: + if(bufRead == SE) { + state = NORMAL; + }else { + //remain in subnegotiation consumin bytes until we get SE + } + break; - n++; - state = NORMAL; - }else if(bufRead == SB) { - state = SUBNEG; - }else { - state = NORMAL; } - break; - case SUBNEG: - if(bufRead == SE) { - state = NORMAL; - }else { - //remain in subnegotiation consumin bytes until we get SE - } - break; - } }