is net-select support file descriptor like stdin ?

Started by chylli, February 20, 2009, 03:07:39 AM

Previous topic - Next topic

chylli

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 ?

Lutz

#1
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

chylli

#2
thanks for your reply. then the net-select still didn't support file descriptor ?

Lutz

#3
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.