0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
Commit Graph

409 Commits

Author SHA1 Message Date
cjihrig
c2b4f4809b net: add pauseOnConnect option to createServer()
Currently when a server receives a new connection the underlying socket
handle begins reading data immediately. This causes problems when
sockets are passed between processes, as data can be read by the first
process and thus never read by the second process.

This commit allows sockets that are constructed with a handle to be
paused initially.

PR-URL: https://github.com/joyent/node/pull/8576
Fixes: https://github.com/joyent/node/issues/7905
Fixes: https://github.com/joyent/node/issues/7784
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
2014-10-27 14:11:20 -07:00
Patrick Mooney
b26dd4e5ab net: Make server.connections un-enumerable
The property server.connections should no longer be enumerable because
it has been deprecated. This will prevent deprecation warnings when
server objects are accessed by functions such as JSON.stringify.

Fixes: https://github.com/joyent/node/issues/8373
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
2014-09-24 16:06:46 -07:00
cjihrig
029cfc12a0 net,dgram: workers can listen on exclusive ports
Allow cluster workers to listen on exclusive ports for TCP and UDP,
instead of forcing all calls to go through the cluster master.

Fixes: #3856
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
Reviewed-by: Fedor Indutny <fedor@indutny.com>
2014-09-03 15:16:16 -07:00
Trevor Norris
9b8837b355 src: be more intelligent about use of "arguments"
Use 'use strict' when there are named arguments and the arguments object
is passed to apply(). Also pass named arguments to call() when the named
argument is modified by the function.

Suggested in
https://github.com/joyent/node/pull/8302#issuecomment-54331801

Confirmed in
https://github.com/joyent/node/pull/8302#issuecomment-54364818

Signed-off-by: Trevor Norris <trev.norris@gmail.com>
2014-09-03 14:24:50 -07:00
Jackson Tian
4bd396a9bf net: Improve Socket.prototype.write()
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
2014-09-03 04:43:01 -07:00
Trevor Norris
a054f8eb29 stream_wrap: Add support to write binary strings
node::StringBytes::Write() has appropriate support to write strings with
'binary' encoding. So expose that API through StreamWrap and allow
inheriting classes to use it.

Signed-off-by: Trevor Norris <trev.norris@gmail.com>
2014-09-03 03:36:17 -07:00
Chris Dickinson
4ef2a5a672 net,stream: add isPaused, don't read() when paused
net Sockets were calling read(0) to start reading, without
checking to see if they were paused first. This would result
in paused Socket objects keeping the event loop alive.

Fixes #8200

Reviewed-by: Trevor Norris <trev.norris@gmail.com>
2014-08-20 13:58:12 -07:00
Alexis Campailla
7ca4fa56d0 Cluster: fix shared handles on Windows
This is the Node side of the fix for Node's cluster module on Windows.
https://github.com/joyent/node/issues/7691

The other required part is
https://github.com/joyent/libuv/pull/1384

Windows and Unix return certain socket errors (i.e. EADDRINUSE) at
different times: bind on Windows, and listen on Unix.
In an effort to hide this difference, libuv on Windows stores such
errors in the bind_error field of uv_tcp_t, to defer raising it at
listen time.
This worked fine except for the case in which a socket is shared in
a Node cluster and a bind error occurs.

A previous attempt to fix this (
d1e6be1460
3da36fe00e
) was flawed becaused in an attempt to relay the error at the JS level
it caused the master to start accepting connections.

With this new approach, libuv itself is relaying the bind errors,
providing for a uniform behavior of uv_tcp_listen.

Reviewed-By: Fedor Indutny <fedor@indutny.com>
2014-08-07 15:03:54 +04:00
cjihrig
430678640c net: don't prefer IPv4 addresses during resolution
Currently the address resolution family defaults to IPv4. Instead remove
the preference and instead resolve to a family suitable for the host.

Expose the getaddrinfo flags and allow them to be passed.

Add documentation about new flags.

Reviewed-by: Trevor Norris <trev.norris@gmail.com>
2014-08-04 16:57:18 -07:00
Fedor Indutny
ff6117b8ed Revert "Cluster: fix shared handles on Windows"
This reverts commit 4e68a28e20.
2014-07-31 12:38:46 +04:00
Alexis Campailla
4e68a28e20 Cluster: fix shared handles on Windows
This is the Node side of the fix for Node's cluster module on Windows.
https://github.com/joyent/node/issues/7691

The other required part is
https://github.com/joyent/libuv/pull/1384

Windows and Unix return certain socket errors (i.e. EADDRINUSE) at
different times: bind on Windows, and listen on Unix.
In an effort to hide this difference, libuv on Windows stores such
errors in the bind_error field of uv_tcp_t, to defer raising it at
listen time.
This worked fine except for the case in which a socket is shared in
a Node cluster and a bind error occurs.

A previous attempt to fix this (
d1e6be1460
3da36fe00e
) was flawed becaused in an attempt to relay the error at the JS level
it caused the master to start accepting connections.

With this new approach, libuv itself is relaying the bind errors,
providing for a uniform behavior of uv_tcp_listen.

Reviewed-By: Fedor Indutny <fedor@indutny.com>
2014-07-31 12:32:28 +04:00
Fedor Indutny
f310c0f16b Merge remote-tracking branch 'origin/v0.10' into master
Conflicts:
	doc/api/buffer.markdown
	lib/_stream_readable.js
	lib/assert.js
	lib/buffer.js
	lib/child_process.js
	lib/http.js
	lib/string_decoder.js
	lib/zlib.js
	node.gyp
	test/simple/test-buffer.js
	test/simple/test-https-foafssl.js
	test/simple/test-stream2-compatibility.js
	test/simple/test-tls-server-verify.js
2014-07-29 12:51:27 +04:00
Jackson Tian
e1ce8ba639 net: add remoteFamily for socket
Signed-off-by: Fedor Indutny <fedor@indutny.com>
2014-07-23 23:44:57 +04:00
cjihrig
b87ca794e3 lib: remove and restructure calls to isNaN()
Switch condition order to check for null before calling isNaN().
Also remove two unnecessary calls to isNaN() that are already
covered by calls to isFinite(). This commit targets v0.10, as
opposed to #7891, which targets master (suggested by
@bnoordhuis). Closes #7840.

Signed-off-by: Fedor Indutny <fedor@indutny.com>
2014-07-10 15:21:50 +03:00
Ed Umansky
df205360f5 net: reset errorEmitted on reconnect
Fix for `error` events emitting only once when reconnecting
a single instance of net.Socket.

Fixes joyent/node#7888

Signed-off-by: Fedor Indutny <fedor@indutny.com>
2014-07-03 15:06:33 +04:00
Eli Skeggs
1100f3de7a net: don't emit listening if handle is closed
Fixes #7834

Signed-off-by: Trevor Norris <trev.norris@gmail.com>
2014-07-02 12:35:06 -07:00
Brian White
03e9f84933 lib: remove unused variables
Signed-off-by: Fedor Indutny <fedor@indutny.com>
2014-06-11 20:41:12 -07:00
Raymond Feng
57c5655885 net: Ensure consistent binding to IPV6 if address is absent
See https://github.com/joyent/node/issues/7675
net.server.listen() behaves inconsistently depending on whether the port
number is provided.

1. port === 0 && host == '' (i.e. false-y), node creates an AF_INET
socket but does not call bind().

2. port > 0 && host == '', node creates an AF_INET6 socket and calls
bind().

The fix makes 1 consistent with 2.

Signed-off-by: Fedor Indutny <fedor@indutny.com>
2014-05-29 02:05:19 +04:00
cjihrig
f1dc55d701 net: don't throw on net.Server.close()
When close() is called on a non-listening server, a synchronous
error is thrown. This commit causes the error to be passed to
the asynchronous callback function instead.

Signed-off-by: Fedor Indutny <fedor@indutny.com>
2014-05-18 17:59:52 +04:00
Yazhong Liu
940974ed03 net: deduplicate Socket.prototype.address
Signed-off-by: Fedor Indutny <fedor@indutny.com>
2014-04-14 20:12:38 +04:00
Fedor Indutny
2272052461 net: bind to :: TCP address by default
Try binding TCP socket to `::` first before falling back to
`0.0.0.0`.
2014-04-14 20:11:57 +04:00
Alexis Campailla
20176a9841 src: make stdout/sterr pipes blocking
Expose `setBlocking` on Pipe's and if a pipe is being created for stdio
on windows then make the pipes blocking.

This fixes test-stream2-stderr-sync.js on Windows.

Fixes #3584
2014-02-26 10:36:58 -08:00
Alexis Campailla
2ca4d9d662 net: fix listening on FDs on Windows
Fix a bug introduced by 3da36fe of a missed early return of a handle
that needed to be passed to listen.

Fixes test-net-listen-fd0.js on Windows
2014-02-25 13:44:38 -08:00
Timothy J Fontaine
59baab2776 net: add localPort to connect options
Expose localPort for binding to a specific port for outbound
connections.

If localAddress is not specified '0.0.0.0' is used for ip4 and '::'
for ip6 connections.

Fixes #7092
2014-02-18 15:55:04 +04:00
Alexis Campailla
3da36fe00e cluster: handle bind errors on Windows
Before sending a socket from a cluster master to a worker,
we would call listen in UV but not handle the error.

I made createServerHandle call listen on Windows so we get a chance
the handle any bind/listen errors early.

This fix is 100% windows specific.
It fixes test-cluster-bind-twice and
test-cluster-shared-handle-bind-error on Windows.
2014-02-13 16:41:59 -08:00
Fedor Indutny
e2a1d9a9ac stream: use errorEmitted from _writableState 2014-02-10 11:06:03 -08:00
Fedor Indutny
dee5270a6c net: do not re-emit stream errors
fix #7015
2014-02-10 10:59:52 -08:00
Thom Seddon
657cd2c4e5 lib: fix unnecessary coercion in lib/net.js
Original patch by @skypjack in #6627
2014-01-29 03:08:06 +04:00
Fedor Indutny
9836a4eeda stream_wrap: use uv_try_write where possible
Use `uv_try_write` for string and buffer writes, thus avoiding to do
allocations and copying in some of the cases.
2014-01-29 02:49:03 +04:00
Timothy J Fontaine
c37e1b7c4b Merge remote-tracking branch 'upstream/v0.10'
Conflicts:
	src/node_crypto.cc
	test/simple/test-crypto.js
2014-01-27 11:02:59 -08:00
Jun Ma
d2de8ba34d net: make Socket destroy() re-entrance safe
So that we are free to call socket.destroy() in error event handler.

fix #6769
2014-01-27 22:12:29 +04:00
Fedor Indutny
00efcb4cd7 net: reset endEmitted on reconnect
fix #6908
2014-01-25 12:20:45 -08:00
Fedor Indutny
640912d18a tls_wrap: propagate errors to write callbacks
fix #6903
2014-01-24 22:09:42 +04:00
Fedor Indutny
d019eac5b5 tls: emit clientError on early socket close
fix #6903
2014-01-24 22:09:17 +04:00
Timothy J Fontaine
b0e5f195df src: lint lib/net.js 2014-01-22 21:05:51 -08:00
Trevor Norris
828f14556e src: revert domain using AsyncListeners
This is a slightly modified revert of bc39bdd.

Getting domains to use AsyncListeners became too much of a challenge
with many edge cases. While this is still a goal, it will have to be
deferred for now until more test coverage can be provided.
2014-01-09 13:25:20 -08:00
Fedor Indutny
3e9f2e61db cluster: report more errors to workers
Some errors for listening and binding to a socket were not properly
delivered to workers.

fix #6767
2013-12-31 09:47:33 -08:00
Trevor Norris
bc39bdd995 domain: use AsyncListener API
The domain module has been switched over to use the domain module API as
much as currently possible. There are still some hooks in the
EventEmitter, but hopefully we can remove those in the future.
2013-10-31 16:34:35 -07:00
Fedor Indutny
5977cba985 tls: reuse hostname from underlying net.Socket
When `tls.connect()` is called with `socket` option, it should try to
reuse hostname previously passed to `net.connect()` and only after that
fall back to `'localhost'`.

fix #6409
2013-10-31 01:57:17 +04:00
Maciej Małecki
d80d131c75 net: add a port validation to connect
Fix "Assertion failed" when trying to connect to non-int ports:

    Assertion failed: (args[2]->Uint32Value()), function Connect,
    file ../src/tcp_wrap.cc, line 379.
    Abort trap: 6
2013-09-19 12:38:29 +02:00
Vsevolod Strukchinsky
edd2fcccf0 net: family option in net.connect
`dns.lookup` defaults to selecting IPv4 record even if IPv6 is available
for the desired zone. Generally, this approach works, but if IPv4
address is unavailable - there'll be no other way to opt-out and connect using
IPv6 address than calling `dns.lookup` and passing it to `.connect()`
directly.

This commit adds `family` option to `net.connect` method to figure out
this issue.
2013-08-20 21:03:52 +04:00
Brian White
6d842897c5 lib: remove unused variables and functions 2013-08-15 17:19:17 -07:00
Ben Noordhuis
f9b7714b4b src: don't call v8::Object::SetHiddenValue()
Don't use v8::Object::SetHiddenValue() to keep a reference alive to the
buffer, we can just as easily do that from JS land and it's a lot faster
to boot.

Because the buffer is now a visible property of the write request
object, it's essential that we do *not* log it - we'd be effectively
serializing the whole buffer to a pretty-printed string.
2013-08-09 08:16:58 +02:00
isaacs
967b5dbb45 http: Use streams3 directly, not .ondata/end 2013-08-08 13:01:09 -07:00
isaacs
22c68fdc1d src: Replace macros with util functions 2013-08-01 15:08:01 -07:00
Ben Noordhuis
04f87de3da cluster: fix shared handle bind error propagation
A failed bind() was already being correctly reported in round-robin
mode. This commit fixes bind() error reporting in shared handle mode.

Fixes #5774.
2013-07-28 14:50:17 +02:00
Ben Noordhuis
0330bdf519 lib: macro-ify type checks
Increases the grep factor. Makes it easier to harmonize type checks
across the code base.
2013-07-24 21:49:35 +02:00
Ben Noordhuis
ca9eb718fb src, lib: update after internal api change
Libuv now returns errors directly.  Make everything in src/ and lib/
follow suit.

The changes to lib/ are not strictly necessary but they remove the need
for the abominations that are process._errno and node::SetErrno().
2013-07-20 12:09:29 +02:00
Ben Noordhuis
0161ec87af src, lib: deduplicate errnoException 2013-07-20 12:04:35 +02:00
isaacs
40e92650bb http: Add agent.get/request methods 2013-07-09 22:31:11 -07:00