Commit Graph

120 Commits

Author SHA1 Message Date
Saúl Ibarra Corretgé
7a4c42a054 unix: add UV_HANDLE_IPV6 flag to tcp and udp handles 2014-04-02 01:24:39 +02:00
Saúl Ibarra Corretgé
3558d65d2f unix, windows: do not set SO_REUSEADDR by default on udp
Add UV_UDP_REUSEADDR flag instead, which can be passed to uv_udp_bind.
If the udp handle is unbound when uv_udp_set_memberhsip or
uv_udp_set_multicast_interface is called, the handle will be bound with
UV_UDP_REUSEADDR set.
2014-04-02 01:21:35 +02:00
Saúl Ibarra Corretgé
08327a7cbd unix, windows: add IPv6 support for uv_udp_multicast_interface 2014-03-28 00:39:09 +01:00
Saúl Ibarra Corretgé
7c5ab1a73e unix, windows: add IPv6 support to uv_udp_set_membership
Reworked from initial version by @snoj
2014-03-17 22:11:28 +01:00
Austin Foxley
451de61b72 unix, win: add uv_udp_set_multicast_interface() 2014-02-07 09:07:11 +01:00
Ben Noordhuis
359d667893 unix: sanity-check fds before closing
Ensure that close() system calls don't close stdio file descriptors
because that is almost never the intention.

This is also a partial workaround for a kernel bug that seems to affect
all Linux kernels when stdin is a pipe that gets closed: fd 0 keeps
signalling EPOLLHUP but a subsequent call to epoll_ctl(EPOLL_CTL_DEL)
fails with EBADF.  See joyent/node#6271 for details and a test case.
2013-10-01 03:55:54 +02:00
Ben Noordhuis
263da51967 include: uv_udp_send{6} now takes sockaddr_in*
Passing or returning structs as values makes life hard for people that
work with libuv through a foreign function interface. Switch to a
pointer-based approach.

Fixes #684.
2013-09-01 08:02:20 +02:00
Ben Noordhuis
525dbb5e31 include: uv_udp_bind{6} now takes sockaddr_in*
Passing or returning structs as values makes life hard for people that
work with libuv through a foreign function interface. Switch to a
pointer-based approach.

Fixes #684.
2013-09-01 08:02:18 +02:00
Ben Noordhuis
0f7b2963ad include: uv_udp_recv_cb now takes const uv_buf_t*
Passing or returning structs as values makes life hard for people that
work with libuv through a foreign function interface. Switch to a
pointer-based approach.

Fixes #684.
2013-09-01 08:02:17 +02:00
Ben Noordhuis
3fb6612233 include: uv_alloc_cb now takes uv_buf_t*
Passing or returning structs as values makes life hard for people that
work with libuv through a foreign function interface. Switch to a
pointer-based approach.

Fixes #684.
2013-09-01 07:57:31 +02:00
Ben Noordhuis
9d60f1ebda linux: don't turn on SO_REUSEPORT socket option
On the BSDs, SO_REUSEPORT is pretty much SO_REUSEADDR with some special
casing for IP multicast.  When two processes (that don't do multicast)
bind to the same address, only the last one receives traffic.  It allows
one to "steal" the bound address from another process.  (Both processes
have to enable SO_REUSEPORT though, so it only works in a cooperative
setting.)

On Linux however, it enables port sharing, not stealing - both processes
receive a share of the traffic.  This is a desirable trait but pre-3.9
kernels don't support the socket option and a libuv program therefore
behaves differently with older kernels or on another platform.

The difference in behavior (sharing vs. stealing) is, in my opinion,
big enough and confusing enough that it merits a rollback.  People
that want this kind of functionality can prepare the socket manually
and hand it off to uv_udp_open().

This commit effectively reverts commit 17452cd.
2013-08-25 21:38:39 +02:00
Ben Noordhuis
17452cd0e2 linux: fix setsockopt(SO_REUSEPORT) error handling
Linux as of 3.9 has a SO_REUSEPORT option that is similar but not
identical to its BSD counterpart.

On the BSDs, it turns on SO_REUSEADDR _and_ makes it possible to share
the address and port across processes.

On Linux, it "merely" enables fair load distribution - port sharing
still requires that you set SO_REUSEADDR.

Fair distribution is a desirable trait but not an essential one.
We don't know in advance whether the kernel actually supports
SO_REUSEPORT so don't treat EINVAL or ENOPROTOOPT as errors.

As an aside, on the BSDs we now omit the setsockopt(SO_REUSEADDR)
system call because it's implied by SO_REUSEPORT.

Fixes #870.
2013-08-24 15:26:51 +02:00
Ben Noordhuis
1acbd768b0 unix, windows: don't read/recv if buf.len==0
Make it possible for the libuv user to handle out of memory conditions
gracefully. When alloc_cb() returns a buffer with len==0, call the read
or recv callback with nread=UV_ENOBUFS. It's up to the user to stop or
close the handle.

Fixes #752.
2013-07-25 01:32:04 +02:00
Ben Noordhuis
3ee4d3f183 unix, windows: return error codes directly
This commit changes the libuv API to return error codes directly rather
than storing them in a loop-global field.

A code snippet like this one:

    if (uv_foo(loop) < 0) {
      uv_err_t err = uv_last_error(loop);
      fprintf(stderr, "%s\n", uv_strerror(err));
    }

Should be rewritten like this:

    int err = uv_foo(loop);
    if (err < 0)
      fprintf(stderr, "%s\n", uv_strerror(err));

The rationale for this change is that it should make creating bindings
for other languages a lot easier: dealing with struct return values is
painful with most FFIs and often downright buggy.
2013-07-07 09:51:00 +02:00
Ben Noordhuis
5879c61394 unix: remove errno preserving code
Remove the errno preserving code. Libuv only implemented it in a
haphazard way and there seems to be a general consensus that no one
really cares anyway. Therefore, remove it.
2013-05-12 11:03:19 +02:00
Ben Noordhuis
23947fdabb Merge remote-tracking branch 'origin/v0.10' 2013-03-29 15:57:10 +01:00
Saúl Ibarra Corretgé
a9a23dc28e unix: don't clear flags after closing UDP handle 2013-03-28 16:08:42 +01:00
Ben Noordhuis
0635e29714 unix, windows: remove ngx-queue.h
Avoids an extra #include in public headers and stops the ngx_queue_*
types and macros from leaking into user code.
2013-03-27 00:09:36 +01:00
Ben Noordhuis
e0df7b6873 unix: fix strict aliasing warning in udp.c 2013-03-07 00:53:06 +01:00
Andrius Bentkus
c5101ae9b5 unix, windows: add common uv_udp_* error checking 2013-02-26 16:57:20 +01:00
Ben Noordhuis
93f61b7c3f unix: fix style issues in udp.c 2013-01-27 14:50:09 +01:00
Andrius Bentkus
bdb498f8b1 unix, windows: return UV_EINVAL, not UV_EFAULT
A wrong multicast membership should return EINVAL.
2013-01-22 15:41:55 +01:00
Ben Noordhuis
edd10071eb unix: fix up #if defined checks
`#if FOO` (where FOO is undefined) is a legal construct in C89 and C99
but gcc, clang and sparse complain loudly about it at higher warning
levels.

Squelch those warnings. Makes the code more consistent as well.
2013-01-06 22:31:47 +01:00
Ben Noordhuis
273cecc56f unix: don't memset(0) in uv_udp_init()
It's inconsistent with other init functions. In particular, it clobbers the
data field.

Fixes #655.
2012-12-15 21:14:39 +01:00
Ben Noordhuis
e079a99abd unix: fix event loop stall
Fix a rather obscure bug where the event loop stalls when an I/O watcher is
stopped while an artificial event, generated with uv__io_feed(), is pending.
2012-12-13 20:17:12 +01:00
Ben Noordhuis
190db15638 unix: set proper loop errno for udp write req cb
Harmonize with stream.c and tcp.c: when a handle is closed that has pending
writes queued up, run the callbacks with loop->err.code set to UV_ECANCELED,
not UV_EINTR.
2012-11-19 04:02:42 +01:00
Ben Noordhuis
65bb6f068e unix: rename UV__IO_* constants 2012-11-16 17:33:29 +01:00
Ben Noordhuis
1282d64868 unix: remove dependency on libev 2012-11-16 17:33:25 +01:00
Saúl Ibarra Corretgé
cc1c1912ca unix, windows: add uv_tcp_open and uv_udp_open 2012-09-17 18:09:51 +02:00
Ben Noordhuis
a3c6a485c6 Merge branch 'v0.8'
Conflicts:
	include/uv.h
2012-08-25 22:33:17 +02:00
Ben Noordhuis
ad7b48aeec unix: fix memory leak in udp.c
Some memory was leaked when the uv_udp_t handle was closed when there were
in-flight send requests with a heap allocated buffer list.

That doesn't happen much in practice. In the common case (writing < 5 buffers),
the buffer list is stored inside the uv_udp_send_t structure, not allocated on
the heap.
2012-08-25 22:28:52 +02:00
Ben Noordhuis
b81e67a19c unix: fix aliasing warning in udp.c 2012-08-23 15:51:06 +02:00
Ben Noordhuis
a7f7696a8d unix: remove UV_REQ_BUFSML_SIZE 2012-08-17 15:19:40 +02:00
Ben Noordhuis
837edf4c0f unix, windows: remove handle init counters
Remove the handle init counters, no one uses them.
2012-08-10 02:00:11 +02:00
Ben Noordhuis
c8c9fe1c74 unix: move memset out of recvmsg inner loop 2012-06-05 15:42:20 +02:00
Ben Noordhuis
738b31eb3a unix: fix loop starvation under high network load
uv__read() and uv__udp_recvmsg() read incoming data in a loop. If data comes
in at high speeds, the kernel receive buffer never drains and said functions
never terminate, stalling the event loop indefinitely. Limit the number of
consecutive reads to 32 to stop that from happening.

The number 32 was chosen at random. Empirically, it seems to maintain a high
throughput while still making the event loop move forward at a reasonable pace.
2012-06-05 15:27:51 +02:00
Ben Noordhuis
890d443558 unix: shave about 100 bytes off uv_udp_send_t 2012-05-23 23:21:08 +02:00
Ben Noordhuis
2609e43632 unix: remove unnecessary functions in udp.c 2012-05-23 21:18:40 +02:00
Ben Noordhuis
2b09cc2246 unix: fix up asserts in udp.c 2012-05-23 21:08:40 +02:00
Ben Noordhuis
3bc9707054 unix: replace ev_io with uv__io_t
Replace ev_io usage with wrapper constructs.

This is preliminary work for the transition to a libev-less linux backend.
2012-05-23 03:42:32 +02:00
Ben Noordhuis
9efa8b3571 unix, windows: rework reference counting scheme
This commit changes how the event loop determines if it needs to stay alive.

Previously, an internal counter was increased whenever a handle got created
and decreased again when the handle was closed.

While conceptually simple, it turned out hard to work with: you often want
to keep the event loop alive only if the handle is actually doing something.
Stopped or inactive handles were a frequent source of hanging event loops.

That's why this commit changes the reference counting scheme to a model where
a handle only references the event loop when it's active. 'Active' means
different things for different handle types, e.g.:

 * timers: ticking
 * sockets: reading, writing or listening
 * processes: always active (for now, subject to change)
 * idle, check, prepare: only active when started

This commit also changes how the uv_ref() and uv_unref() functions work: they
now operate on the level of individual handles, not the whole event loop.

The Windows implementation was done by Bert Belder.
2012-05-17 07:07:53 +02:00
Ben Noordhuis
ab3b307df3 unix: clean up uv__req_init() 2012-04-18 22:30:20 +02:00
Ben Noordhuis
42d3533487 unix: fix udp_options test on OS X and Solaris
setsockopt(IP_TTL) will happily let you set a TTL > 255 on OS X, cap it.

-1 or 0 is a valid TTL on Linux but not portable, deny it.
2012-04-11 14:51:46 +00:00
Ben Noordhuis
5a8446c309 unix: move handle specific close logic out of core.c 2012-04-04 05:30:15 -07:00
Ben Noordhuis
4ff0898c5f unix: replace uv__close() with close()
uv__close() was deprecated a while ago. It's been an alias for close() ever
since. Remove it.
2012-03-21 02:11:18 +01:00
isaacs
243cfcd078 Merge remote-tracking branch 'ry/v0.6' 2012-01-31 18:00:59 -08:00
Ben Noordhuis
45d7bd88c9 unix: explain SO_REUSEADDR and SO_REUSEPORT 2012-01-31 16:52:27 +01:00
Ben Noordhuis
332b72e589 sunos: fix uv_udp_set_ttl and uv_udp_set_multicast_loop
It turns out that setsockopt(IP_TTL) *does* expect an int, whereas
setsockopt(IP_MULTICAST_LOOP) needs a char.
2012-01-28 01:19:49 +01:00
Ben Noordhuis
16124bb34e sunos: fix uv_udp_set_ttl and uv_udp_multicast_ttl
The argument to setsockopt(IP_TTL|IP_MULTICAST_TTL) should be a char, not an int
like on other Unices.
2012-01-28 00:11:47 +01:00
Ben Noordhuis
3de0411591 Merge remote-tracking branch 'origin/v0.6' 2012-01-27 22:23:26 +01:00
Ben Noordhuis
9c76d0d742 unix: turn on SO_REUSEPORT for UDP sockets
Required on BSD-like systems for local UDP multicast. Without it, the bind()
call fails with EADDRINUSE.
2012-01-27 00:49:57 +01:00
Ben Noordhuis
b88bc43543 unix: implement uv_udp_set_multicast_loop() 2012-01-24 00:07:22 +01:00
Ben Noordhuis
e710fdb518 unix: implement uv_udp_set_ttl() 2012-01-24 00:07:22 +01:00
Dan VerWeire
497b1ecd00 unix: add uv_udp_set_broadcast() and uv_udp_set_multicast_ttl() 2012-01-21 03:06:47 +01:00
Dan VerWeire
b674187c38 unix: set SO_REUSEADDR before binding 2012-01-21 03:06:43 +01:00
Ben Noordhuis
0e6e4abedc unix: fix udp recv_start refcount
Calling uv_udp_recv_start() should not bump the event loop's reference count.

Fixes failing test udp_ref2.
2012-01-14 01:44:27 +01:00
Ben Noordhuis
52fba1a38f unix: fix compiler warning 2012-01-12 16:00:31 +01:00
Shigeki Ohtsu
ba52023ef3 Fix missing increments of loop->counters 2011-12-12 18:01:26 +01:00
Roman Shtylman
a3d1f6fd6f add uv_udp_set_membership for unix multicast support
- test-udp-multicast-join tests that multicast packets can be received
- stub src/win/udp.c until support added
2011-10-11 21:25:20 +02:00
Erick Tryzelaar
4c329060ca unix,win: Start unifying shared bind code. 2011-10-04 16:46:39 -07:00
Erick Tryzelaar
23796d208c Fixes #76. Unify OS error reporting
As a nice fringe benefit, this also shaves a word
off of a windows TCP handle by replacing "uv_err_t
bind_error" with "int bind_error".
2011-09-27 19:05:33 -07:00
Erick Tryzelaar
1d7e61fafa unix,win: Check bind receives right socket type 2011-09-27 19:05:33 -07:00
Ben Noordhuis
c89a75f5a2 unix: fix compiler warning in kqueue.c, tcp.c, udp.c
Include <unistd.h>, it contains the definition of close().
2011-09-28 00:57:20 +02:00
Ben Noordhuis
1cca230d76 Merge remote-tracking branch 'origin/v0.6' 2012-01-23 13:27:47 +01:00
Ben Noordhuis
454e0212b0 unix: clean up udp read/write watchers 2012-01-18 20:19:59 +01:00
Ben Noordhuis
28b0867f03 unix: clean up udp shutdown sequence 2012-01-18 20:18:57 +01:00
Ben Noordhuis
01441ab02f unix: fix close() of potentially uninitialized fd 2011-09-25 02:49:21 +02:00
Bert Belder
360f4119e4 Make getsockname/getpeername handle uninitialized sockets better 2011-09-04 19:18:56 +02:00
Bert Belder
12b01e95f9 Specialize uv_xxx_getsockname, add uv_tcp_getpeername 2011-09-04 04:49:13 +02:00
Ryan Dahl
58461d5ae7 split out unix's udp source 2011-08-31 11:23:29 -07:00