> I need non-blocking sockets for a project I am working on,
> sb-bsd-sockets seems to provide this but I can't seem to find any
> select call. Does anyone have any ideas?
(People with clues don't seem to have chimed in overtly, so I'll break
cover...)
Yes, SB-BSD-SOCKETS provides non-blocking sockets and doesn't provide
a SELECT-a-like. The CLHS defines LISTEN, which might do what you
want. It works on streams, not only socket streams:
(progn
(require "ASDF")
(require "sb-bsd-sockets")
(use-package "SB-BSD-SOCKETS"))
(defparameter *string-stream*
(make-string-input-stream "foo bar baz"))
(defparameter *socket-stream*
(let ((socket (make-instance 'inet-socket :type :stream :protocol :tcp)))
(socket-connect socket #(127 0 0 1) 1975)
(socket-make-stream socket)))
(defun simple-select (streams)
(dolist (stream streams)
(when (listen stream)
(return-from simple-select stream))))
;; Starts netcat: "nc -l localhost -p 1975" in another window, types "foo
bar" and hits return.
(let ((stream (simple-select (list *socket-stream* *string-stream*))))
(print stream)
(read-line stream))
=> #<FILE-STREAM for "a constant string" {9139EF1}>
"foo bar"
NIL
;; Evaluates last form again.
=> #<SB-IMPL::STRING-INPUT-STREAM {9F1C3B1}>
"foo bar baz"
T
Note that ACCEPT and RECEIVE will signal an error if called on
non-blocking sockets in current SBCL. There's a diff somewhere in the
sbcl-devel archives, but it hasn't yet made it into the source tree.
Hope this helps,
--Tony
|