sionescu / iolib

Common Lisp I/O library
http://common-lisp.net/project/iolib/
MIT License
141 stars 31 forks source link

`read` blocking forever on local sockets? #79

Open Ambrevar opened 1 year ago

Ambrevar commented 1 year ago

When using read-line and write-line it seems to work:

(let ((path "/tmp/foo.socket"))
  (unwind-protect (iolib:with-open-socket (s :address-family :local
                                             :connect :passive
                                             :local-filename (uiop:native-namestring path))
                    (iolib:with-accept-connection (conn s)
                      (values (read-line conn)
                              (progn (write-line "result" conn)))))
    (uiop:delete-file-if-exists path)))

;; Other REPL
(iolib:with-open-socket (s :address-family :local
                           :remote-filename (uiop:native-namestring "/tmp/foo.socket"))
  (write-line "foo" s)
  (finish-output s)
  (read-line s))

Now switch to read and write:


(let ((path "/tmp/foo.socket"))
  (unwind-protect (iolib:with-open-socket (s :address-family :local
                                             :connect :passive
                                             :local-filename (uiop:native-namestring path))
                    (iolib:with-accept-connection (conn s)
                      (values (read conn)
                              (progn (write "result" :stream conn)))))
    (uiop:delete-file-if-exists path)))

;; Other REPL
(iolib:with-open-socket (s :address-family :local
                           :remote-filename (uiop:native-namestring "/tmp/foo.socket"))
  (write "foo" :stream s)
  (finish-output s)
  (read s))

It hangs forever.

Bug?

aadcg commented 1 month ago

If the goal is to send a single message from the client to the server over a local socket, then the following seems to work as intended:

;; server
(let ((path "/tmp/foo.socket"))
  (unwind-protect (iolib:with-open-socket (s :address-family :local
                                             :connect :passive
                                             :local-filename path)
                    (iolib:with-accept-connection (connection s)
                      (write (read connection))
                      nil))
    (uiop:delete-file-if-exists path)))
;; client
(iolib:with-open-socket (s :address-family :local
                           :remote-filename "/tmp/foo.socket")
  (write "foo" :stream s)
  nil)

@sionescu I think the issue can be closed.