Commit Graph

337 Commits

Author SHA1 Message Date
isaacs
049903e333 stream: Split Writable logic into small functions
1. Get rid of unnecessary 'finishing' flag
2. Dont check both ending and ended. Extraneous.

Also: Remove extraneous 'finishing' flag, and don't check both 'ending'
and 'ended', since checking just 'ending' is sufficient.
2013-03-05 14:26:34 -08:00
Ben Noordhuis
862f7b850d Merge remote-tracking branch 'origin/v0.8' 2013-03-05 15:43:03 +01:00
Ben Noordhuis
532d9929c7 cluster: propagate bind errors
This commit fixes a bug where the cluster module fails to propagate
EADDRINUSE errors.

When a worker starts a (net, http) server, it requests the listen socket
from its master who then creates and binds the socket.

Now, OS X and Windows don't always signal EADDRINUSE from bind() but
instead defer the error until a later syscall. libuv mimics this
behaviour to provide consistent behaviour across platforms but that
means the worker could end up with a socket that is not actually bound
to the requested addresss.

That's why the worker now checks if the socket is bound, raising
EADDRINUSE if that's not the case.

Fixes #2721.
2013-03-05 15:23:55 +01:00
isaacs
4ac73d2c99 net: s/closed/ended/ in write-after-fin message 2013-03-02 11:50:33 -08:00
isaacs
2106ef000c net: Provide better error when writing after FIN
The stock writable stream "write after end" message is overly vague, if
you have clearly not called end() yourself yet.

When we receive a FIN from the other side, and call destroySoon() as a
result, then generate an EPIPE error (which is what would happen if you
did actually write to the socket), with a message explaining what
actually happened.
2013-03-02 11:26:39 -08:00
isaacs
88644eaa2d stream: There is no _read cb, there is only push
This makes it so that `stream.push(chunk)` is the only way to signal the
end of reading, removing the confusing disparity between the
callback-style _read method, and the fact that most real-world streams
do not have a 1:1 corollation between the "please give me data" event,
and the actual arrival of a chunk of data.

It is still possible, of course, to implement a `CallbackReadable` on
top of this.  Simply provide a method like this as the callback:

    function readCallback(er, chunk) {
      if (er)
        stream.emit('error', er);
      else
        stream.push(chunk);
    }

However, *only* fs streams actually would behave in this way, so it
makes not a lot of sense to make TCP, TLS, HTTP, and all the rest have
to bend into this uncomfortable paradigm.
2013-02-28 17:38:17 -08:00
Ben Noordhuis
c11612026f net: omit superfluous 'connect' event
Don't emit a 'connect' event on sockets that are handed off to
net.Server 'connection' event listeners.

1. It's superfluous because the connection has already been established
   at that point.

2. The implementation is arguably wrong because the event is emitted on
   the same tick of the event loop while the rule of thumb is to always
   emit it on the next one.

This has been tried before in commit f0a440d but was reverted again in
ede1acc because the change was incomplete (at least one test hadn't
been updated).

Fixes #1047 (again).
2013-03-01 02:09:36 +01:00
Ben Noordhuis
12d0f0bd3a lib, src: remove errno global
Remove the errno global. It's a property on the process object now.

Fixes #3095.
2013-02-28 23:11:47 +01:00
isaacs
2789323902 net: Respect the 'readable' flag on sockets
Previously, we were only destroying sockets on end if their readable
side had already been ended.  This causes a problem for non-readable
streams, since we don't expect to ever see an 'end' event from those.

Treat the lack of a 'readable' flag the same as if it was an ended
readable stream.

Fix #4751
2013-02-12 16:49:26 -08:00
Ben Noordhuis
14a4245051 net: don't suppress ECONNRESET
Let ECONNRESET network errors bubble up so clients can detect them.

Commit c4454d2e suppressed and turned them into regular end-of-stream
events to fix the then-failing simple/test-regress-GH-1531 test. See
also issue #1571 for (scant) details.

It turns out that special handling is no longer necessary. Remove the
special casing and let the error bubble up naturally.

pummel/test-https-ci-reneg-attack and pummel/test-tls-ci-reneg-attack
are updated because they expected an EPIPE error code that is now an
ECONNRESET. Suppression of the ECONNRESET prevented the test from
detecting that the connection has been severed whereupon the next
write would fail with an EPIPE.

Fixes #1776.
2013-02-11 12:31:21 -08:00
isaacs
bda45a8be1 Revert "net: Avoid tickDepth warnings on small writes"
This commit breaks simple/test-stream2-stderr-sync.  Need to figure out
a better way, or just accept that `(function W(){stream.write(b,W)})()`
is going to be noisy.  People should really be using the `'drain'` event
for this use-case anyway.

This reverts commit 02f7d1bfd8.
2013-01-28 17:15:22 -08:00
isaacs
02f7d1bfd8 net: Avoid tickDepth warnings on small writes
Always defer the _write callback.  The optimization here was only
relevant in some oddball edge cases that we don't actually care about.

Our benchmarks confirm that just always deferring the Socket._write cb
is perfectly fine to do, and in some cases, even slightly more
performant.
2013-01-28 16:16:21 -08:00
Fedor Indutny
c13354e339 child_process: move binding init in constructor
Doing this in net.Socket constructor has much more overhead, and
error is actually may happen before the construction of socket object.
2013-01-28 21:24:45 +04:00
isaacs
4c78a52a3a net: Initialize _connection, _handle in Socket ctor
The better to reduce the hidden classes
2013-01-28 09:09:34 -08:00
Fedor Indutny
0d7a0216dc net: initialize TCPWrap when receiving socket
TCPWrap::Initialize() and PipeWrap::Initialize() should be called before
any data will be read from received socket. But, because of lazy
initialization of these bindings, Initialize() method isn't called.

Init bindings manually upon socket receiving.

See #4669
2013-01-28 16:37:09 +04:00
Fedor Indutny
4488a69fac child_process: do not keep list of sent sockets
Keeping list of all sockets that were sent to child process causes memory
leak and thus unacceptable (see #4587). However `server.close()` should
still work properly.

This commit introduces two options:

* child.send(socket, { track: true }) - will send socket and track its status.
  You should use it when you want to receive `close` event on sent sockets.
* child.send(socket) - will send socket without tracking it status. This
  performs much better, because of smaller number of RTT between master and
  child.

With both of these options `server.close()` will wait for all sent
sockets to get closed.
2013-01-18 03:13:41 +04:00
Fedor Indutny
44cd121c63 Revert "child_process: do not keep list of sent sockets"
This reverts commit db5ee0b3de.
2013-01-18 03:13:10 +04:00
Fedor Indutny
db5ee0b3de child_process: do not keep list of sent sockets
Keeping list of all sockets that were sent to child process causes memory
leak and thus unacceptable (see #4587). However `server.close()` should
still work properly.

This commit introduces two options:

* child.send(socket, { track: true }) - will send socket and track its status.
  You should use it when you want `server.connections` to be a reliable
  number, and receive `close` event on sent sockets.
* child.send(socket) - will send socket without tracking it status. This
  performs much better, because of smaller number of RTT between master and
  child.

With both of these options `server.close()` will wait for all sent
sockets to get closed.
2013-01-17 13:46:31 -08:00
isaacs
1528de2373 stdio: Set readable/writable flags properly
Set the readable/writable flags properly in net streams that have
a handle passed in (such as TTY streams).

Fix #4606
2013-01-17 10:42:44 -08:00
isaacs
840401c024 net: Use readable.push() instead of private methods 2013-01-10 13:50:05 -08:00
Shigeki Ohtsu
9b363b022f net: fix bufferSize include writableStream length
socket.bufferSize missed to include the length of internal buffers in
writableStream.
2013-01-08 04:59:50 +01:00
isaacs
df3563aa65 child_process: Pull through untouched stdio streams
Otherwise child procs will never emit a 'close' event if you don't
ever consume their streams, because they will never hit the EOF.
2013-01-07 08:36:49 -08:00
James Hight
3f76419a04 net: add localAddress and localPort to Socket 2013-01-05 17:05:13 +01:00
isaacs
e11668b244 net: Don't go through Stream API when ondata is used
This speeds up http_simple by around 6%.
2012-12-29 15:32:25 -08:00
isaacs
aec2f733f9 net: Move createWriteReq to separate function 2012-12-29 15:32:25 -08:00
bentaber
e576208eba net: socket.readyState corrections
socket.readyState, .readable, and .writable behavior changed as
a result of the new streaming interfaces. Updated to be backwards
compatible with current API and adds regression test.

closes #4461
2012-12-27 17:53:28 -08:00
Ben Taber
526d852565 net: allow socket end before connect
Fix a bug where calling .end() on a socket without calling .connect() first
throws a TypeError:

  TypeError: Cannot read property 'shutdown' of undefined
      at Socket.onSocketFinish (net.js:194:20)
      at Socket.EventEmitter.emit (events.js:91:17)
      at Socket.Writable.end (_stream_writable.js:281:10)
      at Socket.end (net.js:352:31)

Fixes #4463.
2012-12-25 22:18:56 +01:00
isaacs
244924823e stdio: Do not read from stdout/err
This fixes windows stdio pipes in streams2 land.
2012-12-21 11:05:46 -08:00
isaacs
cab22644a5 net: Properly read buffer in Socket.bytesWritten 2012-12-19 10:55:23 -08:00
isaacs
82c7c84e25 net: Handle sync writable streams synchronously
This fixes the case where stderr doesn't flush before the process exits.
2012-12-17 15:08:57 -08:00
isaacs
8a3befa0c6 net: Refactor to use streams2
This is a combination of 6 commits.

* XXX net fixup lcase stream

* net: Refactor to use streams2

    Use 'socket.resume()' in many tests to trigger old-mode behavior.

* net: Call destroy() if shutdown() is not provided

    This is important for TTY wrap streams

* net: Call .end() in socket.destroySoon if necessary

    This makes the http 1.0 keepAlive test pass, also.

* net wtf-ish stuff kinda busted

* net fixup
2012-12-14 10:52:30 -08:00
isaacs
77ed12fe7a Merge remote-tracking branch 'ry/v0.8' into master
Conflicts:
	AUTHORS
	ChangeLog
	deps/uv/test/test-spawn.c
	deps/uv/uv.gyp
	src/cares_wrap.cc
	src/node.cc
	src/node_version.h
	test/simple/test-buffer.js
	tools/gyp/pylib/gyp/common.py
	tools/install.py
2012-12-13 16:57:58 -08:00
Joshua Erickson
c9f2531ae0 net: More accurate IP address validation and IPv6 dotted notation.
* Added isIP method to make use of inet_pton to cares_wrap.cc
* Modified net.isIP() to make use of new C++ isIP method.
* Added new tests to test-net-isip.js.

This is a back-port of commit fb6377e from the master branch.
2012-11-28 21:51:27 +01:00
Ben Noordhuis
4cb17cb219 net: fix net.connect() resource leak
The 'connect' event listener was attached with .on(), which blocked it from
getting garbage collected. Use .once() instead.

Fixes #4308.
2012-11-24 15:27:14 +01:00
Scott Blomquist
f657ce685d windows: add tracing with performance counters
Patch by Henry Rawas and Scott Blomquist.
2012-11-21 01:21:53 +01:00
Joshua Erickson
fb6377ebd0 net: More accurate IP address validation and IPv6 dotted notation.
* Added isIP method to make use of inet_pton to cares_wrap.cc
* Modified net.isIP() to make use of new C++ isIP method.
* Added new tests to test-net-isip.js.
2012-11-06 16:49:21 +01:00
isaacs
061f2075cf string_decoder: Add 'end' method, do base64 properly 2012-10-11 16:46:18 -07:00
Ben Noordhuis
972cdf82f1 Merge remote-tracking branch 'origin/v0.8'
Conflicts:
	deps/uv/include/uv.h
	src/node_crypto.cc
2012-09-04 15:02:20 +02:00
Shigeki Ohtsu
f347077e78 tls: support unix domain socket/named pipe in tls.connect 2012-08-31 00:23:36 +02:00
Bert Belder
bf16d9280e Merge branch 'v0.8'
Conflicts:
	ChangeLog
	deps/openssl/openssl.gyp
	src/node_version.h
2012-08-28 02:54:22 +02:00
Ben Noordhuis
422772f23b net: fix asserts
Fixes a 'Converting circular structure to JSON' TypeError.
2012-08-23 16:03:48 +02:00
Ben Noordhuis
a177f55b0c Merge remote-tracking branch 'origin/v0.8'
Conflicts:
	ChangeLog
	src/node_version.h
	test/message/stdin_messages.out
	tools/install.py
2012-08-17 13:05:20 +02:00
Ben Noordhuis
4c150ca0d0 net: fix listen() regression, revert patches
This commit reverts the following commits (in reverse chronological order):

  74d076c errnoException must be done immediately
  ddb02b9 net: support Server.listen(Pipe)
  085a098 cluster: do not use internal server API
  d138875 net: lazy listen on handler

Commit d138875 introduced a backwards incompatible change that broke the
simple/test-net-socket-timeout and simple/test-net-lazy-listen tests - it
defers listening on the target port until the `net.Server` instance has at
least one 'connection' event listener.

The other patches had to be reverted in order to revert d138875.

Fixes #3832.
2012-08-06 23:55:38 +02:00
Josh Erickson
7b367a93ce net: add support for IPv6 addresses ending in ::
Modified net.isIP Ipv6 regex to allow for addresses ending in "::".
Added tests for new IPv6 matching reqex.
2012-08-06 22:25:55 +02:00
isaacs
7bb814f9db errnoException must be done immediately 2012-08-05 14:42:22 -07:00
isaacs
74d076caf1 errnoException must be done immediately 2012-08-05 14:22:44 -07:00
Andreas Madsen
ddb02b978d net: support Server.listen(Pipe) 2012-08-05 13:53:31 -07:00
Andreas Madsen
085a09874b cluster: do not use internal server API 2012-08-05 13:53:31 -07:00
Andreas Madsen
d13887512e net: lazy listen on handler
This allow the server to be shared without the need to handle connection
from master
2012-08-04 22:13:07 -07:00
isaacs
3bf1846bb7 Merge remote-tracking branch 'ry/v0.8'
Conflicts:
	ChangeLog
	deps/uv/src/unix/sunos.c
	deps/uv/test/test-tcp-unexpected-read.c
	src/node_version.h
2012-08-03 16:23:14 -07:00