Commit Graph

29 Commits

Author SHA1 Message Date
Ben Noordhuis
1282d64868 unix: remove dependency on libev 2012-11-16 17:33:25 +01:00
Ben Noordhuis
be2a2176ce unix: rethink relaxed accept() approach
Benchmarks demonstrated that the idle timer handle approach didn't balance the
load quite fair enough, the majority of new connections still ended up in one
or two processes.

The new approach voluntarily gives up a scheduler timeslice by calling
nanosleep() with a one nanosecond timeout.

Why not sched_yield()? Because on Linux (and this is probably true for other
Unices as well), sched_yield() only yields if there are other processes running
on the same CPU.

nanosleep() on the other hand always forces the process to sleep, which gives
other processes a chance to accept our pending connections.
2012-09-18 00:16:43 +02:00
Saúl Ibarra Corretgé
cc1c1912ca unix, windows: add uv_tcp_open and uv_udp_open 2012-09-17 18:09:51 +02:00
Bert Belder
27b11abcc0 unix: mark accept idle handle as internal 2012-09-08 17:52:57 +02:00
Ben Noordhuis
3bbe8f9754 Merge branch 'v0.8' 2012-09-04 01:23:18 +02:00
Ben Noordhuis
b101a53e6e sunos: don't set TCP_KEEPALIVE
The system headers advertise the socket option but the actual syscall fails
with ENOPROTOOPT.

Fixes joyent/node#3937.
2012-09-04 01:20:33 +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
9f7cdb20aa unix: add relaxed accept() setting
Mitigates unfair scheduling in multi-process setups that share a single listen
socket across multiple processes.
2012-08-02 15:58:55 +02:00
Ben Noordhuis
cc1b3de247 unix: revert 0971598, obsoleted by 889ab21 2012-07-02 00:00:20 +02:00
Ben Noordhuis
0971598d02 unix: fix EINPROGRESS busy loop
Don't make the event loop spin when connect() returns EINPROGRESS.

Test case:

  #include "uv.h"

  static void connect_cb(uv_connect_t* req, int status) {
    // ...
  }

  int main() {
    uv_tcp_t handle;
    uv_connect_t req;
    struct sockaddr_in addr;
    addr = uv_ip4_addr("8.8.8.8", 1234); // unreachable
    uv_tcp_init(uv_default_loop(), &handle);
    uv_tcp_connect(&req, (uv_stream_t*)&handle, addr, connect_cb);
    uv_run(uv_default_loop()); // busy loops until connection times out
    return 0;
  }

After EINPROGRESS, there are zero active handles and one active request. That
in turn makes uv__poll_timeout() believe that it should merely poll, not block,
in epoll() / kqueue() / port_getn().

Sidestep that by artificially starting the handle on connect() and stopping it
again once the TCP handshake completes / is rejected / times out.

It's a slightly hacky approach because I don't want to change the ABI of the
stable branch. I'll address it properly in the master branch.
2012-06-29 19:16:40 +02:00
Ben Noordhuis
1a6b6b781c unix: deduplicate socket creation code in tcp.c
Incidentally fixes a rather obscure bug where uv_tcp_connect() reconnected
and leaked a file descriptor when the handle was already busy connecting,
handle->fd was zero (unlikely) and uv_tcp_connect() got called again.
2012-06-29 18:47:30 +02:00
Ben Noordhuis
e4a68bb5cb unix: move uv__connect() to tcp.c 2012-06-29 18:21:50 +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
Bert Belder
e38755485e Unix: namespace stream handle flags 2012-05-03 01:47:13 +02: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
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
Igor Zinkovsky
9c6103a479 windows: add tests for uv_tcp_simultaneous_accepts 2011-11-01 01:13:13 -07:00
Igor Zinkovsky
78f4b120a1 windows: knob for tuning number of concurrent accept requests 2011-10-31 23:37:45 -07:00
Ben Noordhuis
ec825ffc62 unix: add TCP keepalive and no-delay control knobs 2011-10-21 16:08:26 -07:00
Erick Tryzelaar
4c329060ca unix,win: Start unifying shared bind code. 2011-10-04 16:46:39 -07:00
Erick Tryzelaar
85368e8d45 unix,win: Start unifying shared tcp connect 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
Erick Tryzelaar
c260a39645 unix,win: Check connect receives right socket type 2011-09-27 19:05:33 -07:00
Ben Noordhuis
eb987bcc5c unix: deduplicate stream init logic
Move shared init logic into uv__stream_init().
2011-09-10 01:40:47 +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
6fd340b8ca unix: split out stream into its own file 2011-08-31 13:41:22 -07:00
Ryan Dahl
510407c03d unix: split out tcp module 2011-08-31 13:11:38 -07:00