I want to read from stdin and a socket, but it is tedious and urgly to do so like
(while 1 (if (peek 0) ....) (if (net-peek socket) ...) (sleep 10))
I think there is an select function in linux, man 2 select. is there way to do that in newlisp ?
You can use 'peek' on sockets as well, and then process channels in a loop:
(while listening
(dolist (ch channels)
(if-not (zero? (peek ch))
(process ch))
)
)
'channels' is a list of numbers including 0 for stdin
thanks for your reply. then the net-select still didn't support file descriptor ?
Actually it should, I just never have tried it. The underlying code uses plain UNIX select(), so 'net-select' should work for any file descriptors.
Vice versa on Unix you could use newLISP file functions (read-line, read/write-buffer etc.) on sockets, and I have tried this successfully. On Windows sockets and file descriptors are not identical and cannot always be used in an interchangeable way.
In newLISP all net-functions also set/reset 'net-error', which would not happend when using normal file functions.