-
Notifications
You must be signed in to change notification settings - Fork 53
Unable to detect a closed socket in a non-blocking way #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Let me show what I do: CL-USER> (use-package :usocket)
T
CL-USER> (defparameter *socket-no-data* (socket-listen "localhost" 65001))
*SOCKET-NO-DATA*
CL-USER> (defparameter *socket-closed* (socket-listen "localhost" 65002))
*SOCKET-CLOSED*
CL-USER> (defparameter *socket-no-data-accepted* (socket-accept (wait-for-input *socket-no-data* :timeout 3000)))
;; I connect using ncat localhost 65001
*SOCKET-NO-DATA-ACCEPTED*
CL-USER> (defparameter *socket-closed-accepted* (socket-accept (wait-for-input *socket-closed* :timeout 3000)))
;; I connect using ncat localhost 65002
*SOCKET-CLOSED-ACCEPTED*
;; Ctrl-C is sent to ncat localhost 65002, socket gets closed
CL-USER> (defparameter *socket-no-data-stream* (socket-stream *socket-no-data-accepted*))
*SOCKET-NO-DATA-STREAM*
CL-USER> (defparameter *socket-closed-stream* (socket-stream *socket-no-data-accepted*))
*SOCKET-CLOSED-STREAM*
CL-USER> (listen *socket-no-data-stream*)
NIL
CL-USER> (listen *socket-closed-stream*)
NIL
CL-USER> (wait-for-input *socket-no-data* :timeout 0)
#<STREAM-SERVER-USOCKET {10050D9163}>
NIL
CL-USER> (wait-for-input *socket-closed* :timeout 0)
#<STREAM-SERVER-USOCKET {10051DFD23}>
NIL
CL-USER> (wait-for-input *socket-no-data* :timeout 0 :ready-only t)
NIL
NIL
CL-USER> (wait-for-input *socket-closed* :timeout 0 :ready-only t)
NIL
NIL
CL-USER> (wait-for-input *socket-no-data-accepted* :timeout 0 :ready-only t)
NIL
NIL
CL-USER> (wait-for-input *socket-closed-accepted* :timeout 0 :ready-only t)
NIL
NIL
CL-USER> I see no way to tell the two sockets' state apart. |
For a character stream, you could use something like:
For a binary stream, it might be more difficult as there is no |
For SBCL on Windows,
returns NIL regardless of whether the socket is closed or just blocking. It gives :eof for closed streams on SBCL/Linux and CCL/Linux when I tested those. |
The API tells me what to do in two cases:
I find it impossible to:
Let's assume a following situation:
In a situation portrayed above, I should NOT do a
(read-line *stream*)
because(listen *stream*)
gives me a NIL.The issue I see is,
(listen *stream*)
gives a NIL in two cases:And I am unable to separate these two cases.
In other words: is there any way to separate these two cases mentioned above?
In yet other words: in the situation portrayed within the code block, what command will reliably tell me whether the NIL given to me by the
(listen *socket*)
is because of lack of data or an EOF?The text was updated successfully, but these errors were encountered: