-
Notifications
You must be signed in to change notification settings - Fork 37
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
cqueues.socket.fdopen always uses dup(); which still shares things with the original socket #13
Comments
That's an interesting case. Although a socket having O_NONBLOCK unset is arguably less problematic than a descriptor becoming invalidated, at least from the perspective of the library. OTOH, with luasocket it's an inevitability rather than a possibility. I'm already committed to adding the option to take ownership; still not sure about changing the default behavior. I would also file a bug report with luasocket. O_NONBLOCK has nothing to do with whether close blocks, nor whether it returns without closing the descriptor. Per POSIX, "the requirement for close() on a socket to block for up to the current linger interval is not conditional on the O_NONBLOCK setting." Also, neither POSIX, Linux, OS X, FreeBSD, NetBSD, OpenBSD, Solaris, nor AIX document an EAGAIN/EWOULDBLOCK error for the close system call. The next issue of POSIX excludes EAGAIN/EWOULDBLOCK as a possibility, entirely. (See http://austingroupbugs.net/view.php?id=529) That really drives home the point that O_NONBLOCK is irrelevant in the context of close. |
@diegonehab, are you able to comment?
Looking at the original commit, that might not be the case on windows? Which seems to have been copied across to https://github.com/diegonehab/luasocket/blob/0c9f420a3549df3fb331bb24157b65a3301641d4/src/usocket.c#L51 In any case, that code has been there since 2004; and will likely live on in packages for a long time. |
This was added long enough ago that I do not remember why it was added. You seem to be using LuaSocket in a way it was not designed for. Can you explain the usage scenario where this is a problem? |
It looks like it was in the initial commit of new code, so quite possibly it was just what came first to mind at the time?
I'm writing additional implementations of a couple of apis using cqueues. |
Can it block on Windows? I would accept a pull request for this change. |
On windows it appers that it can nonblock; so I'll leave the call in there for now. |
This results in unexpected behaviour if the socket has been `dup()`d, as O_NONBLOCK is shared. Close is always 'blocking' anyway See wahern/cqueues#13 for an example use case
👍 |
I encountered an issue today, where the descriptor that got
dup()
d was setting!O_NONBLOCK
on closeFrom here
First and foremost, this issue is to track this potential patch
However, contrary to what you wrote:
I think it is a more sensible default to have cqueue's
fdopen
just take over the existing file descriptor; as we can't know what is going to happen to the old one.My current 'take over from luasocket' code:
What it could be instead:
The text was updated successfully, but these errors were encountered: