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

unix: set non-block mode in uv_{pipe,tcp,udp}_open #134

Closed
wants to merge 2 commits into from
Closed

unix: set non-block mode in uv_{pipe,tcp,udp}_open #134

wants to merge 2 commits into from

Conversation

bnoordhuis
Copy link
Member

R=@saghul

I didn't have time to write a test. Feel free to steal this PR and put your own changes in.

The contract specifies that the file descriptor should already be in
non-blocking mode before passing it to libuv.

However, node users don't really have an opportunity to do so, never
mind the fact that the call to uv_pipe_open() or uv_tcp_open() is an
implementation detail that most users won't be aware of.

Let's be nice and set the non-blocking flag explicitly.  It's a cheap
operation anyway.

Fixes: #124
The mode argument is an enum now and the signedness of an enum is
implementation-defined when it doesn't have negative members.

Cast it to int in the comparison to tty->mode because the latter is
still an int.
@saghul
Copy link
Member

saghul commented Jan 13, 2015

Thanks, Ben! I'll add some versionchanged thing to the docs and update some tests a bit later then.

@saghul
Copy link
Member

saghul commented Jan 13, 2015

@bnoordhuis can you PTAL at this? saghul/libuv@libuv:v1.x...do_you_even_open Pay special attention to the change to test-spawn.c, we used to set the fd to non-blocking before spawning a child process, it would now be after.

Also, I wonder if we should do the same for poll handles, WDYT? Windows doesn't do it either. /cc @piscisaureus

@piscisaureus
Copy link
Contributor

@saghul

For windows:

  • Doesn't matter for poll handles
  • For imported tcp handles it gets done:
    if (ioctlsocket(socket, FIONBIO, &yes) == SOCKET_ERROR) {

@saghul
Copy link
Member

saghul commented Jan 14, 2015

Why doesn't it matter for poll handles? I see we do put the fd as
nonblocking in the tests.
On Jan 13, 2015 10:52 PM, "Bert Belder" [email protected] wrote:

@saghul https://github.com/saghul

For windows:

  • Doesn't matter for poll handles
  • For imported tcp handles it gets done:
    if (ioctlsocket(socket, FIONBIO, &yes) == SOCKET_ERROR) {


Reply to this email directly or view it on GitHub
#134 (comment).

bnoordhuis added a commit that referenced this pull request Jan 14, 2015
The mode argument is an enum now and the signedness of an enum is
implementation-defined when it doesn't have negative members.

Cast it to int in the comparison to tty->mode because the latter is
still an int.

PR: #134
Reviewed-by: Saúl Ibarra Corretgé <[email protected]>
@saghul
Copy link
Member

saghul commented Jan 14, 2015

I added another patch for poll handles. PTAL: saghul/libuv@libuv:v1.x...do_you_even_open

@piscisaureus
Copy link
Contributor

Why doesn't it matter for poll handles? I see we do put the fd as nonblocking in the tests.

The problem with uv_pipe_open() arises because libuv itself tries to do a nonblocking operation, but the fd is not in nonblocking mode. With uv_poll() we don't actually do any nonblocking stuff, we just do epoll-like things for the user.

The test must set SOCK_NONLBLOCK because it does nonblocking sends and receives.

@saghul
Copy link
Member

saghul commented Jan 14, 2015

The problem with uv_pipe_open() arises because libuv itself tries to do a nonblocking operation, but the fd is not in nonblocking mode. With uv_poll() we don't actually do any nonblocking stuff, we just do epoll-like things for the user.

The test must set SOCK_NONLBLOCK because it does nonblocking sends and receives.

I'm a bit confused :-/ AFAIK, all uv_{pipe, tcp, udp}_open work correctly on Windows. Apparently there are tricks on uv_pipe_open but It Just Works (TM), right?

Now, on poll handles the user needs to set the fd to non-blocking mode manually, which is what one of the patches here solves, for consistency with the other functions where the user doesn't need to do it.

Is there anything I'm missing? Thanks!

@piscisaureus
Copy link
Contributor

Had some discussion with Saùl on IRC.
This PR lgtm.

bnoordhuis added a commit that referenced this pull request Jan 14, 2015
The contract specifies that the file descriptor should already be in
non-blocking mode before passing it to libuv.

However, node users don't really have an opportunity to do so, never
mind the fact that the call to uv_pipe_open() or uv_tcp_open() is an
implementation detail that most users won't be aware of.

Let's be nice and set the non-blocking flag explicitly.  It's a cheap
operation anyway.

Fixes: #124

PR: #134
Reviewed-by: Saúl Ibarra Corretgé <[email protected]>
@saghul
Copy link
Member

saghul commented Jan 14, 2015

As discussed with @piscisaureus on IRC, the PR landed, I'll take the poll handles thing to another PR.

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

Successfully merging this pull request may close these issues.

3 participants