Interactive terminal application
Posted: Mon Oct 10, 2011 5:04 pm
I've been writing an IRC library, but I'm a bit stuck on the best way to arrange things so that you can type input at a terminal while still running an event loop that polls the server periodically. As we know, there's no way you can have a non-blocking read-line, so how would it be possible to combine both 'read' and 'write' tasks into a single terminal window? (My previous attempt - using fork - doesn't seem to be what I'm looking for.)
My 'read' code looks like this:
My 'read' code looks like this:
Code: Select all
(define (read-irc)
(let ((buffer {}))
(while (not (net-select Iserver "read" 500))
(sleep 500))
(net-receive Iserver buffer 8192 "\n")
(unless (empty? buffer)
(parse-buffer buffer))))
(define (read-irc-loop)
(let ((buffer {}))
(while Iconnected
(read-irc))))