8000 Unable to detect a closed socket in a non-blocking way · Issue #12 · usocket/usocket · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Unable to detect a closed socket in a non-blocking way #12
Open
@phoe

Description

@phoe

The API tells me what to do in two cases:

  • ...check whether reading from a socket stream will block, and
  • ...check whether the other end has closed my socket stream.

I find it impossible to:

  • ...check whether the other end has closed my socket stream without blocking.

Let's assume a following situation:

> (defparameter *socket* (socket-listen "localhost" 65035)) ;; => *SOCKET*
> (defparameter *stream* (socket-stream (socket-accept (wait-for-input *socket* :timeout 3000)))) ;; => *STREAM* ;after ncat localhost 65035
;; Ctrl-C on the ncat, socket gets closed, OR NOT, socket still open
> (listen *stream*) ;; => NIL

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:

  • when there is no data on the stream (usual case),
  • when there is an EOF on the stream (problematic case).
    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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0