slight modification to support reliable blocking inputstream.