is net-select support file descriptor like stdin ?

Q&A's, tips, howto's
Locked
chylli
Posts: 5
Joined: Wed Feb 18, 2009 7:44 pm

is net-select support file descriptor like stdin ?

Post by 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
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

You can use 'peek' on sockets as well, and then process channels in a loop:

Code: Select all

(while listening
  (dolist (ch channels) 
      (if-not (zero? (peek ch)) 
          (process ch))
  )
)
'channels' is a list of numbers including 0 for stdin

chylli
Posts: 5
Joined: Wed Feb 18, 2009 7:44 pm

Post by chylli »

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

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

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.

Locked