Previous Chapter Next Section Table of Contents Glossary Index

Chapter 19. Questions and Answers

19.1. How can I do nonblocking (aka "unbuffered" and "raw") IO?

There's some code for manipulating TTY modes in "ccl:library;pty.lisp".

? (require "PTY")

? (ccl::disable-tty-local-modes 0 #$ICANON)
T
      

will turn off "input canonicalization" on file descriptor 0, which is at least part of what you need to do here. This disables the #$ICANON mode, which tells the OS not to do any line-buffering or line-editing. Of course, this only has any effect in situations where the OS ever does that, which means when stdin is a TTY or PTY.

If the #$ICANON mode is disabled, you can do things like:

? (progn (read-char) (read-char))
a
#\a
      

(where the first READ-CHAR consumes the newline, which isn't really necessary to make the reader happy anymore.) So, you can do:

? (read-char)
#\Space

(where there's a space after the close-paren) without having to type a newline.


Previous Chapter Next Section Table of Contents Glossary Index