-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Add ability to create sockets early #400
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
Conversation
|
I'd probably make the There are only about 40-something address families and every platform I know of numbers them incrementally starting from zero, so you'd only need 6 bits to cover them all. Make it 8 or 10 bits to play it safe. (Although that's wasting a lot of bits... |
|
Can you elaborate a bit on why? Extensibility? FWIW, this is the first time that we modify some uv_*_init in years (if memory serves right), since they tend to basically do nothing, so I'm not really concerned about that. |
|
Extensibility, yes. Always leave an escape hatch if at all possible. |
|
Let's assume there is some UV_NO_CLOEXEC flag which prevents the sockets from being created with O_CLOEXEC set. This API would then be used as follows: Is that right? Looks a bit weird to me :-S I can add a dummy flags thing if you really feel strong about it: WDYT? |
|
The three arg version looks alright to me and it's easier to remember, you can't accidentally swap the domain and the flags arguments. You can alias AF_INET as UV_AF_INET if using plain AF_INET bothers you. |
|
@bnoordhuis is saghul@9e02f49 what you were suggesting? |
d59699b to
7eff28f
Compare
|
@bnoordhuis I'm chasing some failures on Windows, but can you PTAL the unix side? |
7eff28f to
9f176e5
Compare
test/test-tcp-create-socket-early.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Femto-nit: the parens aren't necessary here.
9f176e5 to
6b4e0a0
Compare
test/test-udp-create-socket-early.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sizeof(addr.sin_addr)?
|
UNIX side LGTM minus some nits. Windows side looks okay to me too. |
92d7f26 to
fb63597
Compare
fb63597 to
388098f
Compare
|
Ok, addressed everything and the build is "green" (surprisingly we've been keeping it that way on Windows for a while \o/). If nobody has any further comments I'll land this and the LEP later tonight. Thanks again for the review Ben! |
PR-URL: libuv#400 Reviewed-By: Ben Noordhuis <[email protected]>
Introduce two new APIs:
int uv_tcp_init_ex(uv_loop_t*, uv_tcp_t* handle, int flags)
int uv_udp_init_ex(uv_loop_t*, uv_udp_t* handle, int flags)
The lower 8 bits of the flags field are used for the socket domain.
AF_INET, AF_INET6 and AF_UNSPEC are supported. If AF_UNSPEC is specified
the socket is created lazily, just like uv_{tcp,udp}_init.
Some Windows notes:
getsockname fails with WSAEINVAL if the socket is not bound. This could
potentially be improved by detecting the socket family and filling
the sockaddr_in/6 struct manually.
bind returns WSAEFAULT if we try to bind a socket to the wrong family.
Unix returns EINVAL.
PR-URL: libuv#400
Reviewed-By: Ben Noordhuis <[email protected]>
388098f to
f8f5982
Compare
|
Landed! |
|
Just a followup, can you do an API bump in the |
|
@vavrusa we bump the version when making a release (the tool does it), so you'll have to wait until we make a 1.7.0 release, sorry. |
|
Okay, a small request then - could you make a macro in Example: Decimal is neater, but it requires you must use 1 digit per minor release at most. |
|
@vavrusa you can now use UV_VERSION_HEX. |
PR-URL: libuv#400 Reviewed-By: Ben Noordhuis <[email protected]>
PR-URL: libuv#400 Reviewed-By: Ben Noordhuis <[email protected]>
Introduce two new APIs:
int uv_tcp_init_ex(uv_loop_t*, uv_tcp_t* handle, int flags)
int uv_udp_init_ex(uv_loop_t*, uv_udp_t* handle, int flags)
The lower 8 bits of the flags field are used for the socket domain.
AF_INET, AF_INET6 and AF_UNSPEC are supported. If AF_UNSPEC is specified
the socket is created lazily, just like uv_{tcp,udp}_init.
Some Windows notes:
getsockname fails with WSAEINVAL if the socket is not bound. This could
potentially be improved by detecting the socket family and filling
the sockaddr_in/6 struct manually.
bind returns WSAEFAULT if we try to bind a socket to the wrong family.
Unix returns EINVAL.
PR-URL: libuv#400
Reviewed-By: Ben Noordhuis <[email protected]>
PR-URL: libuv#400 Reviewed-By: Ben Noordhuis <[email protected]>
PR-URL: libuv#400 Reviewed-By: Ben Noordhuis <[email protected]>
Introduce two new APIs:
int uv_tcp_init_ex(uv_loop_t*, uv_tcp_t* handle, int flags)
int uv_udp_init_ex(uv_loop_t*, uv_udp_t* handle, int flags)
The lower 8 bits of the flags field are used for the socket domain.
AF_INET, AF_INET6 and AF_UNSPEC are supported. If AF_UNSPEC is specified
the socket is created lazily, just like uv_{tcp,udp}_init.
Some Windows notes:
getsockname fails with WSAEINVAL if the socket is not bound. This could
potentially be improved by detecting the socket family and filling
the sockaddr_in/6 struct manually.
bind returns WSAEFAULT if we try to bind a socket to the wrong family.
Unix returns EINVAL.
PR-URL: libuv#400
Reviewed-By: Ben Noordhuis <[email protected]>
PR-URL: libuv#400 Reviewed-By: Ben Noordhuis <[email protected]>
PR-URL: libuv#400 Reviewed-By: Ben Noordhuis <[email protected]>
Introduce two new APIs:
int uv_tcp_init_ex(uv_loop_t*, uv_tcp_t* handle, int flags)
int uv_udp_init_ex(uv_loop_t*, uv_udp_t* handle, int flags)
The lower 8 bits of the flags field are used for the socket domain.
AF_INET, AF_INET6 and AF_UNSPEC are supported. If AF_UNSPEC is specified
the socket is created lazily, just like uv_{tcp,udp}_init.
Some Windows notes:
getsockname fails with WSAEINVAL if the socket is not bound. This could
potentially be improved by detecting the socket family and filling
the sockaddr_in/6 struct manually.
bind returns WSAEFAULT if we try to bind a socket to the wrong family.
Unix returns EINVAL.
PR-URL: libuv#400
Reviewed-By: Ben Noordhuis <[email protected]>
|
BTW, the change to src/win/pipe.c in this change: Is causing this problem: Removing this code from src/win/pipe.c:uv_set_pipe_handle() fixes the problem: if (handle->handle != INVALID_HANDLE_VALUE) |
|
This error is triggered in this code path: int uv_pipe_accept(uv_pipe_t* server, uv_stream_t* client) {
...
if (server->ipc) {
...
} else {
...
if (!(server->flags & UV__HANDLE_CLOSING)) {
uv_pipe_queue_accept(loop, server, req, FALSE);
}
}
}
static void uv_pipe_queue_accept(uv_loop_t* loop, uv_pipe_t* handle,
uv_pipe_accept_t* req, BOOL firstInstance) {
...
if (!firstInstance) {
...
if (uv_set_pipe_handle(loop, handle, req->pipeHandle, -1, 0)) {
...
}
}
}I could set |
|
I just had a nice chat with @saghul about this which probably triggered a lot of memories for him :-) (for some implementations of Loop::GetLoop() |
As per the LEP: libuv/leps#5
This is still WIP, I's just like a bit of early feedback.
ToDo:
R=@bnoordhuis