How to make readLine() timeout

前端 未结 2 971
走了就别回头了
走了就别回头了 2021-01-15 20:38

My application basically is a CLI with all the expected features like prompt, history etc., it needs to wait on STDIN for user input. For this I am using readLine system cal

2条回答
  •  [愿得一人]
    2021-01-15 21:22

    I am using readLine system call.

    libreadline

    You provide inconsistent information. What system would that be that has a system call readLine?
    If you use libreadline, you are rather calling library functions. But then, according to the GNU Readline Library Function and Variable Index, there is no function readLine, there's only readline. With it you could use either the

    • Variable: rl_hook_func_t * rl_event_hook
      If non-zero, this is the address of a function to call periodically when Readline is waiting for terminal input. By default, this will be called at most ten times a second if there is no keyboard input.

      (you'd set it to a function where you poll your network socket and respond to messages)

    or the

    • Alternate Interface
      An alternate interface is available to plain readline(). Some applications need to interleave keyboard I/O with file, device, or window system I/O, typically by using a main loop to select() on various file descriptors. To accommodate this need, readline can also be invoked as a `callback' function from an event loop. There are functions available to make this easy.

      There's an example program using the alternate interface: Alternate Interface Example.

提交回复
热议问题