Lines 103-116
Link Here
|
103 |
// TelnetOutputStream writing through the telnet client at same time |
103 |
// TelnetOutputStream writing through the telnet client at same time |
104 |
// as a processDo/Will/etc. command invoked from TelnetInputStream |
104 |
// as a processDo/Will/etc. command invoked from TelnetInputStream |
105 |
// tries to write. |
105 |
// tries to write. |
106 |
private int __read() throws IOException |
106 |
private int __read(boolean mayBlock) throws IOException |
107 |
{ |
107 |
{ |
108 |
int ch; |
108 |
int ch; |
109 |
|
109 |
|
110 |
_loop: |
110 |
_loop: |
111 |
while (true) |
111 |
while (true) |
112 |
{ |
112 |
{ |
113 |
// Exit only when we reach end of stream. |
113 |
|
|
|
114 |
// If there is no more data AND we were told not to block, just return -2. (More efficient than exception.) |
115 |
if(!mayBlock && super.available() == 0) |
116 |
return -2; |
117 |
|
118 |
// Otherwise, exit only when we reach end of stream. |
114 |
if ((ch = super.read()) < 0) |
119 |
if ((ch = super.read()) < 0) |
115 |
return -1; |
120 |
return -1; |
116 |
|
121 |
|
Lines 357-368
Link Here
|
357 |
//__alreadyread = false; |
362 |
//__alreadyread = false; |
358 |
__readIsWaiting = true; |
363 |
__readIsWaiting = true; |
359 |
int ch; |
364 |
int ch; |
360 |
|
365 |
boolean mayBlock = true; // block on the first read only |
|
|
366 |
|
361 |
do |
367 |
do |
362 |
{ |
368 |
{ |
363 |
try |
369 |
try |
364 |
{ |
370 |
{ |
365 |
if ((ch = __read()) < 0) |
371 |
if ((ch = __read(mayBlock)) < 0) |
366 |
if(ch != -2) |
372 |
if(ch != -2) |
367 |
return (ch); |
373 |
return (ch); |
368 |
} |
374 |
} |
Lines 396-401
Link Here
|
396 |
if (__isClosed) |
402 |
if (__isClosed) |
397 |
return (-1); |
403 |
return (-1); |
398 |
} |
404 |
} |
|
|
405 |
|
406 |
// Reads should not block on subsequent iterations. Potentially, this could happen if the |
407 |
// remaining buffered socket data consists entirely of Telnet command sequence and no "user" data. |
408 |
mayBlock = false; |
409 |
|
399 |
} |
410 |
} |
400 |
// Continue reading as long as there is data available and the queue is not full. |
411 |
// Continue reading as long as there is data available and the queue is not full. |
401 |
while (super.available() > 0 && __bytesAvailable < __queue.length - 1); |
412 |
while (super.available() > 0 && __bytesAvailable < __queue.length - 1); |
Lines 541-547
Link Here
|
541 |
{ |
552 |
{ |
542 |
try |
553 |
try |
543 |
{ |
554 |
{ |
544 |
if ((ch = __read()) < 0) |
555 |
if ((ch = __read(true)) < 0) |
545 |
break; |
556 |
break; |
546 |
} |
557 |
} |
547 |
catch (InterruptedIOException e) |
558 |
catch (InterruptedIOException e) |