iolib icon indicating copy to clipboard operation
iolib copied to clipboard

`read` blocking forever on local sockets?

Open Ambrevar opened this issue 2 years ago • 1 comments

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?

Ambrevar avatar Jun 15 '23 12:06 Ambrevar

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.

aadcg avatar Jul 10 '24 20:07 aadcg