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

Why do native reads that return 0 bytes read, return -1? #57

Closed
huntc opened this issue Aug 4, 2018 · 1 comment
Closed

Why do native reads that return 0 bytes read, return -1? #57

huntc opened this issue Aug 4, 2018 · 1 comment

Comments

@huntc
Copy link
Contributor

huntc commented Aug 4, 2018

I noticed that when reading from a Unix socket, if the return value of a native read call is 0 then it is returned to the caller as -1. Relevant code:

https://github.com/jnr/jnr-unixsocket/blob/master/src/main/java/jnr/enxio/channels/Common.java#L59

I'm left curious as to why particularly given that I'm having a problem with half-closing Unix sockets. My understanding is that a native read could return zero on receipt of a FIN. I'm not sure if my problem is related, but I'd still like to understand why the translation is performed.

Thanks.

@huntc
Copy link
Contributor Author

huntc commented Aug 6, 2018

Not to worry. I’d forgotten that the Unix read returns 0 on EOF where NIO’s read returns -1. Hence the translation.

@huntc huntc closed this as completed Aug 6, 2018
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

1 participant