Commit Graph

274 Commits (1df222f179f3c7e6181a319ecc90a1e0fb0a2975)

Author SHA1 Message Date
Ben Noordhuis 03eb41c2ec net: don't emit 'close' event twice
Don't allow `socket.destroy()` to run twice. The self-destruct sequence itself
is idempotent but it makes the 'close' and 'error' events fire more than once,
which may confuse listeners.

Fixes #2223.
2011-12-01 14:57:06 +01:00
Ryan Dahl 86528489ec new cluster api 2011-11-04 15:12:11 -07:00
Ryan Dahl 4a8088a603 Socket.write should reset timeout timer.
Fixes #2002.
2011-11-03 12:37:04 -07:00
Ben Noordhuis 9c11e8a1ca net: implement Server.prototype.address() for pipes 2011-11-03 19:16:10 +01:00
Ryan Dahl 60818b957c Add missing copyright headers 2011-11-02 10:00:57 -07:00
Maciej Małecki 7ee29d1d5b net: `Server.listen`, `Server.close` and `Socket.connect` return `this`
Just a syntactic sugar for doing, for example:

    var server = net.createServer(function (c) {
      c.end('goodbye, cruel world!\r\n');
      server.close().on('close', function () {
        console.log('really, goodbye!');
      });
    }).listen(1337);

Fixes #1922.
2011-10-24 22:19:42 +09:00
Ben Noordhuis ac379b3be1 net: bring back .setNoDelay() and .setKeepAlive() 2011-10-21 18:09:23 -07:00
Ryan Dahl 6cc0c9e6a9 Remove superfluous nextTick during server binding
This breaks fork().send({}, server._handle) after server.listen() because
server._handle is not set.
2011-10-18 15:12:18 -07:00
koichik d6191f593d net: fix error handling in listen()
Fixes #1894.
2011-10-16 01:30:19 +09:00
Ben Noordhuis 0b92fa0e93 net: fix connect queue bugs
This commit fixes two bugs in the handling of write requests when the connect()
call is still in progress.

1. The deferred write request's size was counted twice towards `.bytesWritten`.

2. The callback was not called. After connecting, `Socket.write()` was called
   with three arguments (data, encoding, cb) but it ignored the third argument.

Coincidentally fixes test/simple/test-net-connect-buffer.js.
2011-10-15 03:34:09 +02:00
Ben Noordhuis 6df574b744 net: properly account multi-byte chars in .bytesWritten 2011-10-15 03:24:34 +02:00
Simen Brekken 4b0e36810a net: register net.Server callback only once
Only register once for listening when passing a callback to Server.listen(),
this prevents servers recycled using close() from invoking the callback when
Server.listen() is called later.
2011-10-13 16:09:14 +02:00
Ryan Dahl 25ff181300 Revert some changes made in 12486a6
Some of the perf improvements from many-writes-fix branch were accidentally
undone in that commit. This puts them back in.
2011-10-12 12:49:58 -07:00
Ryan Dahl 87339a22b1 introduce node cluster 2011-10-12 02:58:35 -07:00
Ryan Dahl be0bb2dc13 Remove net_legacy timers_legacy 2011-10-11 13:11:54 -07:00
Ryan Dahl 710f8e2acc Add --use-uv command-line flag to use libuv backend 2011-06-17 13:51:40 +02:00
Felix Geisendörfer f0a440d886 Remove 'connect' event from server side sockets
Sockets emitted by the 'connection' event are always connected, having
them emit the 'connect' event makes no sense. It only confused people,
as it's not clear if you have to listen to 'connect' or not.

That try..catch block was also very scary. It would silently swallow
exceptions in 'connect' listeners and destroy the socket. Makes no
sense.

Fixes #1047.
2011-05-24 11:22:59 -07:00
Ryan Dahl 9e6498d5fa Merge branch 'v0.4'
Conflicts:
	src/node_version.h
2011-04-18 18:58:16 -07:00
Ryan Dahl 8417870f51 Don't emit error on ECONNRESET - just close
Fix #670
2011-04-14 10:42:57 -07:00
Ryan Dahl 598792ba91 Merge branch 'v0.4'
Conflicts:
	src/platform_sunos.cc
	test/simple/test-os.js
2011-04-14 01:11:21 +00:00
Brian White ac1da4b407 Add remoteAddress and remotePort for client TCP connections
https://groups.google.com/d/topic/nodejs-dev/Asr87_YFSkg/discussion
2011-04-13 10:24:28 -07:00
Ryan Dahl 9ccf0e527f Don't error on ENOTCONN from shutdown() 2011-04-11 15:33:24 -07:00
Ryan Dahl 7a8c729830 Merge branch 'v0.4'
Conflicts:
	src/node_version.h
2011-03-22 13:12:07 -07:00
Ryan Dahl d7a86ff05e Fix GH-819. Drop out if connection destroyed before connect() 2011-03-21 14:48:26 -07:00
Daniel Ennis 911cbd0cef Add support for file descriptor type detection.
setImplementationMethods checks the type of a socket and defines different
behavior based on the type, so auto detect it if type not implicitly
specified.
2011-03-17 10:35:47 -07:00
Ryan Dahl 55048cdf79 Update copyright headers 2011-03-14 17:37:05 -07:00
koichik 414fa4abae Better type checks for fd in net.js 2011-03-11 16:34:12 -08:00
koichik 113b1e6e0c Fix GH-746 process.stdin.destroy() breaks http server 2011-03-11 16:33:07 -08:00
Andreas Reich 5e91042fcb Don't decrease server connection counter again if destroy() is called more than once
Test: Anders Conbere <aconbere@gmail.com>
Fix: Andreas Reich <andreas@reich.name>

Closes GH-431.
Closes GH-502.
2011-03-04 15:45:12 -08:00
Ryan Dahl e9257b859d New DTrace probes from CA team 2011-02-09 18:50:26 -08:00
Ryan Dahl a48a075535 better debug messages in net and tls 2011-02-09 10:23:26 -08:00
Ryan Dahl 4733d0b1f0 http: handle aborts 2011-02-04 18:07:00 -08:00
Ryan Dahl 9f3a20c76d net: Add hook for when writeQueue changes 2011-01-31 11:01:59 -08:00
Ryan Dahl 6ede26cb9c Add socket.bufferSize 2011-01-31 10:41:52 -08:00
Ryan Dahl bfb6a67d60 Another fix for process.assert 2011-01-27 16:59:28 -08:00
Ali Farhadi c70dd70301 Adding callback parameter to Socket's setTimeout method. 2011-01-26 12:13:03 -08:00
Ryan Dahl 068b733583 Land Cantrill's DTrace patch
only works on solaris
2011-01-24 18:59:06 -08:00
Ryan Dahl 9e976abad9 lint 2011-01-24 10:55:30 -08:00
Ryan Dahl b22b5e341b listen/bind errors should close net.Server 2011-01-18 16:22:43 -08:00
Bert Belder 0eb4c2157d Define winsock error numbers 2011-01-18 04:58:30 +01:00
Ryan Dahl 5f5201db2f Fix test-net-connect-buffer
Change to end() behavior in 33c339 was breaking it. end() should wait for
connection before dumping. Changed test-net-connect-timeout to use destroy()
instead.
2011-01-12 13:29:45 -08:00
Ryan Dahl 5f795efd4e net: Timeouts should work before DNS resolution 2011-01-12 12:59:58 -08:00
Ryan Dahl 33c33949b2 Add test for connection timeouts
Also make socket.end() destroy connection if still trying to connect.
Previously was ignoring.
2011-01-12 10:57:03 -08:00
Ryan Dahl 5a05992155 Lint 2011-01-06 16:06:27 -08:00
Ryan Dahl b62152bc84 Rename net.Stream to net.Socket 2011-01-05 11:53:56 -08:00
Ryan Dahl bc1d758408 net.js: Check that readWatcher exists before pause, resume 2011-01-04 11:25:36 -08:00
Ryan Dahl 2957382991 Implement new stream method, destroySoon
Still missing on fs.WriteStream
2011-01-04 11:22:19 -08:00
Ryan Dahl e4dd5cd6fd NODE_DEBUG uses strings instead of bitflags 2011-01-03 15:41:58 -08:00
Ryan Dahl 632da2a393 Add callback paramenter to socket.connect() 2010-12-15 15:57:41 -08:00
Ryan Dahl c4161f32f5 Add callback to socket.write() 2010-12-15 15:47:02 -08:00
Ryan Dahl c970968ee6 better option parsing for socket.write() 2010-12-15 15:15:27 -08:00
Ryan Dahl 92789b16e5 Fix global leaks 2010-12-04 16:36:21 -08:00
Ryan Dahl e232f6e735 more lint 2010-12-01 20:28:28 -08:00
Ryan Dahl ec1589875c Stop watcher before calling .set() in Stream.prototype.resume 2010-12-01 12:52:34 -08:00
Ryan Dahl a6f6532dfb Fix test-securepair-server 2010-11-23 18:30:52 -08:00
Ryan Dahl 2320497992 Revert "Merge branch 'writev'"
This reverts commit cd9515efd9, reversing
changes made to df46c8e698.

Too slow. Needs more work.
2010-11-20 20:55:15 -08:00
Ryan Dahl 1f18648394 Fix typo 2010-11-18 16:47:38 -08:00
Ryan Dahl 2ba3c10d62 Only try to flush big buffers once 2010-11-18 16:47:38 -08:00
Ryan Dahl 849792e46b Add todo about test-pipe.js and throwing on resume() 2010-11-18 16:47:38 -08:00
Ryan Dahl 544877d12e Fix socket.end() problem on non-empty queue 2010-11-18 16:47:38 -08:00
Ryan Dahl 3884b4185a Small clean ups 2010-11-18 16:47:38 -08:00
Ryan Dahl 02039c9b53 'connect' event may disconnect socket 2010-11-18 16:47:38 -08:00
Ryan Dahl fa556a1425 Add callback to socket.write(), fix test-sendfds 2010-11-18 16:47:38 -08:00
Ryan Dahl a6d8425382 make sure unix sockets are tagged correctly 2010-11-18 16:47:38 -08:00
Ryan Dahl 5d6a03c9fe Don't append buckets of zero length 2010-11-18 16:47:38 -08:00
Ryan Dahl 10ff559ec3 Add IOWatcher.flush()
To be called if sockets get too much data. This is to force a flush before
the tick ends.
2010-11-18 16:47:37 -08:00
Ryan Dahl 7c3c5c6861 Maintain queueSize for each socket 2010-11-18 16:47:37 -08:00
Ryan Dahl 5a84461e46 Also do ondrain callback for socket (needed by http) 2010-11-18 16:47:37 -08:00
Ryan Dahl e1250a3333 Reset _eof on socket reuse 2010-11-18 16:47:37 -08:00
Ryan Dahl 5ba0be6166 Don't send null data segments 2010-11-18 16:47:37 -08:00
Ryan Dahl dcc547d798 Dumper net.js integration 2010-11-18 16:47:37 -08:00
Ryan Dahl df46c8e698 Rip out the old TLS implementation 2010-11-18 16:46:37 -08:00
Ryan Dahl cf05257fb7 Test for server.listen() more carefully, fix bug 2010-11-16 15:33:21 -08:00
Ryan Dahl 4144024e6b Test and fix for self-assigned port from net.Server 2010-11-15 20:22:54 -08:00
Ryan Dahl f1391f33cd Add missing require('fs') 2010-11-01 14:56:21 -07:00
Ryan Dahl 1eb547fec1 Lazy load modules in net.js 2010-10-28 13:15:53 -07:00
Ryan Dahl 5171da5a6c Remove a little redundancy 2010-10-28 13:11:42 -07:00
Ryan Dahl 65dced730f Handle one more onReadable call from crypto
MUST get rid of this calledByIOWatcher stuff. Hopefully will be able to when
securepair stuff lands.
2010-10-28 12:34:48 -07:00
Ryan Dahl 73cfda12bb Abstract out a Server.prototype.pause method 2010-10-28 11:42:22 -07:00
Ryan Dahl ad61d77fa3 Abstract out net.Server.prototype._rejectPending
Does the same timeout action for maxConnections as it does for EMFILE.
2010-10-28 11:33:35 -07:00
Jonas Pfenniger 74d0a077ec Module-level EMFILE handling
All net servers now share the same dummy socket. The ulimit warning is
throttled for all servers.
2010-10-28 11:12:59 -07:00
Ryan Dahl 67652ddf27 Refactor callbacks in net.Stream for fewer closures 2010-10-27 16:43:16 -07:00
Ryan Dahl 38dde9684f Add extra anti-DoS tech to net.Server 2010-10-27 12:09:16 -07:00
Ryan Dahl ac54272218 Gracefully handle EMFILE
Implementing a tip from Marc Lehmann:
http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#The_special_problem_of_accept_ing_wh

Keep an extra FD around for every server. When you hit EMFILE, destroy that
FD, accept a connection, close it; in this way you can clear the connection
queue and let people know that you're overload.

No more timeout needed.
2010-10-27 02:12:25 -07:00
Ryan Dahl 5cc29b80f2 Move idle timers into its own module 2010-10-26 14:53:17 -07:00
Ryan Dahl 2470d2ee92 allowHalfOpen disabled by default
Users too often would forget to add

  socket.on('end', function () {
    socket.end();
  });

Which is a mistake. Therefore we default to this behavior and
only optionally let people handle the 'end' case themselves.
2010-10-26 01:10:18 -07:00
Micheil Smith 8da020d39e Update node_net.cc to make us of node_constants.cc
also affects dgram which uses a constant from node_net.cc
2010-10-25 12:14:47 -07:00
Ryan Dahl 0ac2ef924f Do not spin on aceept() with EMFILE
When a server hit EMFILE it would continue to try to accept new connections
from the queue. This patch introduces a timeout of one second where it will
stop trying to accept new files. After the second is over it tries again.

This is a rather serious bug that has been effecting many highly concurrent
programs. It was introduced in 4593c0, version v0.2.0.

TODO: A test for this situation. Currently I test it like this

  termA% cd projects/node
  termA% ulimit -n 256
  termA% ./node benchmark/idle_server.js

  termB% cd projects/node
  termB% ./node benchmark/idle_clients.js

And watch how the server process behaves.
2010-10-23 12:28:20 -07:00
Ryan Dahl d9a5edb2b0 Fix test-net-eaddrinuse 2010-10-23 11:22:24 -07:00
Jorge Chamorro Bieling 99e19aa398 Remove unneeded function wrappers 2010-10-21 17:11:59 -07:00
Johan Euphrosine 5d400cfd3a net listen should emit eaddrinuse error 2010-10-18 17:00:13 -07:00
Joshua Peek 73b29d79b9 Don't flush net writeQueue on end() if its still connecting 2010-10-13 02:37:53 -07:00
Ryan Dahl 6691aca229 Allow people to set backlog. Need a better API. 2010-10-13 01:47:29 -07:00
Micheil Smith a3604cf233 Removed deprecated methods from lib/net.js 2010-10-11 16:20:08 -07:00
Micheil Smith 83db91be41 Removed deprecated alias to lib/fs.js 2010-10-11 16:20:04 -07:00
Ryan Dahl 7e24a05cba Fix test-http-buffer-sanity 2010-10-11 16:00:36 -07:00
Micheil Smith e38eb0c5a4 Soft migration of sys -> util, Removal of deprecated utils module. 2010-10-11 15:21:36 -07:00
Ryan Dahl 1d3142a882 TCP clients should buffer writes before connection 2010-10-10 23:09:14 -07:00
Ryan Dahl bc695475b9 Add Stream base class with stream.pipe 2010-10-10 17:27:03 -07:00
Joshaven Potter 3d4e4d8909 syntax fixes to pass jslint 2010-10-06 20:40:57 -07:00