Skip to content
Advertisement

Can GNU Readline handle multiple streams?

I’m building a telnet application which uses GNU Readline to handle console input. Current implementation forks a new child for every new client connection – this assigns one readline instance for each child process.

Fork-type network servers are not the most efficient, so I’d like to use poll/epoll instead, but for that readline would have to be configured to work with multiple stream buffers and history, one for each client connection.

I read the GNU readline documentation in search of such configuration, but didn’t find it. Is this possible, or is there some kind of readline alternative that would eneble this feature? Shall I give up this idea?

Advertisement

Answer

Readline is documented to read specifically from the terminal. It has no documented mechanism to maintain state for multiple inputs at the same time, and you’re already on thin ice using it to read from a stream that is not, in fact, a terminal.

Moreover, the semantics of readline do not match a multiplex style service because on each call it blocks until it can read a complete line. This is simply not a viable alternative, nor would be any work-alike that has similar line-at-a-time blocking behavior.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement