Skip to content
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

Detect/check if inet_stream is closed #57

Open
nemo9955 opened this issue Sep 29, 2018 · 1 comment
Open

Detect/check if inet_stream is closed #57

nemo9955 opened this issue Sep 29, 2018 · 1 comment

Comments

@nemo9955
Copy link

I want to be notified or at least check periodically if a libsocket::inet_stream created by a libsocket::inet_stream_server::accept() is closed.
I tried fcntl but it does not seem to work.

int r;
r = fcntl(cli_sock->getfd(), F_GETFL);
if (r == -1)
    is_ok = false;
@dermesser
Copy link
Owner

I don't think your fcntl call would work, as a socket is not a file. In general, once a call to recv(2) returns 0, you can expect the socket to be closed/the connection to have been terminated.

If you really need to detect a closed stream without reading anything from the socket, you can use epoll: the EPOLLRDHUP event flag should indicate the situation you're looking for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants