This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts Menu
(define (digital_root n)
(+ 1 (% (- n 1) 9))
> (digital_root 236753647864)
7
Quote
If our server only makes calls which select has indicated will not block, will everything be OK? No! These two operations - select followed by the hopefully non-blocking call - are non-atomic. By the time the server makes the call, the situation may have changed! A pending connection may disappear before we try to accept it. A client attempting to send data may disappear before we try to read its data. Data may be read from a socket by a different process before we get to it.
Why doesQuote from: "Lutz"net-selectnot work for you? Maybe I don't understand the question.
Quote
Hmm, that's a well-known race condition - the accept(2) will block if client drops connection attempt between two syscalls. You need the listening socket to be non-blocking. – Nikolai Fetissov Aug 10 '10 at 0:35
This is correct - you can add your listening file descriptor to the readfds in your select() call, and select() will tell you the file descriptor is "readable" if it has a connection ready to accept(). @Nikolai is correct too - the listening socket should be nonblocking and the accept() call prepared to handle EAGAIN. – caf Aug 10 '10 at 0:35
try to work withQuote from: "Lutz"net-listen: http://www.newlisp.org/downloads/newlisp_manual.html#net-listen"> http://www.newlisp.org/downloads/newlis ... net-listen">http://www.newlisp.org/downloads/newlisp_manual.html#net-listen
;; pseudocode
(net-listen port "nonblocking")
(set 'active-connections (list))
;; event loop
(while true
(set 'newclient (net-accept)) ;; non-blocking
(if newclient (push newclient active-connections))
(do-something-with (net-select active-connections))
(close-and-remove-inactive-connections)
)