0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 07:27:22 +01:00
Commit Graph

80 Commits

Author SHA1 Message Date
Roman Reiss
b5b8ff117c lib: don't use global Buffer
Port of https://github.com/joyent/node/pull/8603

The race condition present in the original PR didn't occur, so no
workaround was needed.

PR-URL: https://github.com/nodejs/io.js/pull/1794
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
2015-06-11 20:24:44 +02:00
Saúl Ibarra Corretgé
b5cd2f0986 dgram: partially revert 18d457b
Revert "dgram: call send callback asynchronously" partially, since the
fix is now done in libuv.

Refs: https://github.com/nodejs/io.js/pull/1313
Refs: https://github.com/libuv/libuv/pull/371
PR-URL: https://github.com/nodejs/io.js/pull/1889
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2015-06-04 00:09:39 +02:00
Brian White
5abd4ac079 lib: simplify nextTick() usage
This commit removes unnecessary nextTick() closures and adds some
shared nextTick() callbacks for better re-use.

PR-URL: https://github.com/nodejs/io.js/pull/1612
Reviewed-By: Yosuke Furukawa <yosuke.furukawa@gmail.com>
Reviewed-By: Brendan Ashworth <brendan.ashworth@me.com>
2015-05-25 10:14:18 -04:00
Roman Reiss
39dde3222e net,dgram: return this from ref and unref methods
Modifies the following methods to return the instance instead
of undefined, to allow for chaining these methods:

- net.Server.ref
- net.Server.unref
- net.Socket.ref
- net.Socket.unref
- dgram.Socket.ref
- dgram.Socket.unref

PR-URL: https://github.com/nodejs/io.js/pull/1768
Reviewed-By: Evan Lucas <evanlucas@me.com>
2015-05-23 06:57:00 +02:00
Yosuke Furukawa
18d457bd34 dgram: call send callback asynchronously
dgram#send callback was changed synchronously.
The PR-URL is here https://github.com/joyent/libuv/pull/1358

This commit is temporary fix until libuv issue is resolved.
https://github.com/libuv/libuv/issues/301

PR-URL: https://github.com/iojs/io.js/pull/1313
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
2015-05-10 12:03:21 +09:00
Yosuke Furukawa
19ffb5cf1c lib: fix eslint styles
PR-URL: https://github.com/iojs/io.js/pull/1539
Fixes: https://github.com/iojs/io.js/issues/1253
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
2015-05-09 12:10:02 +09:00
Trevor Norris
10e31ba56c node: allow multiple arguments passed to nextTick
PR-URL: https://github.com/iojs/io.js/pull/1077
Reviewed-by: Colin Ihrig <cjihrig@gmail.com>
2015-04-15 17:02:21 -06:00
Brendan Ashworth
1219e7466c lib: reduce process.binding() calls
This commit better handles calls to process.binding() in lib/ by
no longer lazy loading the bindings (the load times themselves are
rather miniscule compared to the load time of V8) and never reloading
the bindings (which is 172 times slower than referencing a variable with
the same value).

PR-URL: https://github.com/iojs/io.js/pull/1367
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-04-09 10:51:19 -07:00
Yosuke Furukawa
207e48c934 dgram: check close callback is function
PR-URL: https://github.com/iojs/io.js/pull/609
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Evan Lucas <evanlucas@me.com>
2015-02-02 18:44:05 +01:00
cjihrig
6ac8bdc0ab lib: reduce util.is*() usage
Many of the util.is*() methods used to check data types
simply compare against a single value or the result of
typeof. This commit replaces calls to these methods with
equivalent checks. This commit does not touch calls to the
more complex methods (isRegExp(), isDate(), etc.).

Fixes: https://github.com/iojs/io.js/issues/607
PR-URL: https://github.com/iojs/io.js/pull/647
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-31 23:47:29 -05:00
Sam Roberts
65b1e4f56f dgram: implicit binds should be exclusive
Server sockets should be shared by default, and client sockets should be
exclusive by default. For net/TCP, this is how it is, for dgram/UDP, its
a little less clear what a client socket is, but a socket that is
auto-bound during a dgram.send() is not usefully shared among cluster
workers, any more than an outgoing TCP connection would be usefully
shared.

Since implicit binds become exclusive, implicit/client dgram sockets can
now be used with cluster on Windows. Before, neither explicit nor
implicitly bound sockets could be used, causing dgram to be completely
unsupported with cluster on Windows. After this change, they become half
supported.

PR: https://github.com/iojs/io.js/pull/325
PR: https://github.com/joyent/node/pull/8643
Reviewed-by: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-by: Bert Belder <bertbelder@gmail.com>
2015-01-31 00:10:39 +01:00
cjihrig
804e7aa9ab lib: use const to define constants
This commit replaces a number of var statements throughout
the lib code with const statements.

PR-URL: https://github.com/iojs/io.js/pull/541
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-21 16:21:31 -05:00
isaacs
3e1b1dd4a9 Remove excessive copyright/license boilerplate
The copyright and license notice is already in the LICENSE file.  There
is no justifiable reason to also require that it be included in every
file, since the individual files are not individually distributed except
as part of the entire package.
2015-01-12 15:30:28 -08:00
Ben Noordhuis
0526d834f9 Revert "dgram: implicit binds should be exclusive"
This reverts commit a32b92dbcf.

Reverted for breaking the parallel/test-cluster-dgram-2 test on all
platforms.

PR-URL: https://github.com/iojs/io.js/pull/279
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rod Vagg <rod@vagg.org>
2015-01-10 16:34:18 +01:00
Sam Roberts
a32b92dbcf dgram: implicit binds should be exclusive
Server sockets should be shared by default, and client sockets should be
exclusive by default. For net/TCP, this is how it is, for dgram/UDP, its
a little less clear what a client socket is, but a socket that is
auto-bound during a dgram.send() is not usefully shared among cluster
workers, any more than an outgoing TCP connection would be usefully
shared.

Since implicit binds become exclusive, implicit/client dgram sockets can
now be used with cluster on Windows. Before, neither explicit nor
implicitly bound sockets could be used, causing dgram to be completely
unsupported with cluster on Windows. After this change, they become half
supported.

PR-URL: https://github.com/joyent/node/pull/8643
Reviewed-by: Bert Belder <bertbelder@gmail.com>
2015-01-10 04:50:50 +01:00
Evan Lucas
c9fd9e2162 dgram: make error messages more informative
PR-URL: https://github.com/iojs/io.js/pull/250
Reviewed-By: Bert Belder <bertbelder@gmail.com>
2015-01-08 20:16:39 +01:00
Sam Roberts
63005ee10b dgram: close() should accept a callback
Like net, http, and https server.close, and socket.end(), etc.

PR-URL: https://github.com/iojs/io.js/pull/217
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2014-12-30 21:40:43 +01:00
Sam Roberts
7349d7fd99 dgram: make 'close' event async
Emit the close event asynchronously, after the close, as it is with the
net/http close events.

PR-URL: https://github.com/iojs/io.js/pull/217
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2014-12-30 21:40:28 +01:00
Brendan Ashworth
4444b7b52c dgram: changes Socket.close() to return itself
This commit adds a return statement to the dgram.Socket.close()
function that returns itself after it finishes. This follows along
the functionality of the more popular and, dare I say, father-library
`lib/net.js`.

PR-URL: https://github.com/iojs/io.js/pull/214
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2014-12-29 17:25:45 +01:00
Brendan Ashworth
3e0057dd61 dgram: change Socket.bind() to return itself
This commit changes `lib/dgram.js` Sockets to, when
they are bound to a port / IP, return themselves. This
is done in order to allow chaining of methods and be
in accordance with the `lib/net.js` library.

PR-URL: https://github.com/iojs/io.js/pull/214
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2014-12-29 17:25:27 +01:00
Trevor Norris
819690fd98 src: all wraps now use actual FunctionTemplate
Instead of simply creating a new v8::Object to contain the connection
information, instantiate a new instance of a FunctionTemplate. This will
allow future improvements for debugging and performance probes.

Additionally, the "provider" argument in the ReqWrap constructor is no
longer optional.

PR-URL: https://github.com/joyent/node/pull/8110
Signed-off-by: Trevor Norris <trev.norris@gmail.com>
Reviewed-by: Fedor Indutny <fedor@indutny.com>
Reviewed-by: Alexis Campailla <alexis@janeasystems.com>
Reviewed-by: Julien Gilli <julien.gilli@joyent.com>
2014-12-09 17:57:15 +01:00
Ben Noordhuis
21130c7d6f lib: turn on strict mode
Turn on strict mode for the files in the lib/ directory.  It helps
catch bugs and can have a positive effect on performance.

PR-URL: https://github.com/node-forward/node/pull/64
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Fedor Indutny <fedor@indutny.com>
2014-11-22 17:23:30 +01: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
Jackson Tian
a8845ebd45 dgram: remove new keyword from errnoException
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
2014-08-12 21:43:20 -07:00
Andrius Bentkus
a382c9a97c udp: make it possible to receive empty udp packets
A udp packet can have 0 content. In that case nread will be equal to 0,
but addr != NULL.

Add test case for empty data gram packets and fixed test that checked
for OOB when length == 0.

Signed-off-by: Trevor Norris <trev.norris@gmail.com>
2014-07-02 20:59:27 -07:00
Fedor Indutny
592be014b6
dgram: introduce reuseAddr option
Introduce new signature for both `dgram.createSocket` method and
`dgram.Socket` constructor:

    dgram.createSocket(options, [listener])

Options should contain `type` property and may contain `reuseAddr`
property. When `reuseAddr` is `true` - SO_REUSEADDR will be issued on
socket on bind.

fix #7415

Signed-off-by: Fedor Indutny <fedor@indutny.com>
2014-04-10 19:39:49 +04:00
Timothy J Fontaine
a4436bab7b dgram: pass the bytes sent to the send callback
Fixes #6953
2014-02-15 19:24:42 -08:00
Trevor Norris
8130744044 dgram: send() can accept strings
Strings passed to Socket#send() will be passed to Buffer and parsed as
UTF8.
2013-10-28 16:18:18 -07: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
Ben Noordhuis
1449739de0 dgram: don't call into js when send cb is omitted
Speed up dgram.Socket#send()-heavy code a little by omitting the call
into JS land when the user doesn't pass us a completion callback.
2013-08-09 18:56:45 +02:00
Ben Noordhuis
41ec6d0580 dgram: fix regression in string argument handling
v0.10 allows strings for the offset, length and port arguments to
dgram.send() and dgram.sendto() but master before this commit would
abort with the following assert:

    node: ../../src/udp_wrap.cc:227: static void
    node::UDPWrap::DoSend(const v8::FunctionCallbackInfo<v8::Value>&,
    int): Assertion `args[2]->IsUint32()' failed.

Go beyond what v0.10 does and also add range checks: offset and length
should be >= 0, port should be between 1 and 65535.

That particular change needs to be back-ported to v0.10 because passing
a negative offset or length number aborts with the following assertions:

    node: ../../src/udp_wrap.cc:264: static v8::Handle<v8::Value>
    node::UDPWrap::DoSend(const v8::Arguments&, int): Assertion
    `offset < Buffer::Length(buffer_obj)' failed.

Or:

    node: ../../src/udp_wrap.cc:265: static v8::Handle<v8::Value>
    node::UDPWrap::DoSend(const v8::Arguments&, int): Assertion
    `length <= Buffer::Length(buffer_obj) - offset' failed.

Interestingly enough, a negative port number is accepted in v0.10 but
is silently ignored.

This commit exposed a bug in the simple/test-dgram-close test which
has also been fixed.
2013-08-09 03:05:46 +02:00
isaacs
22c68fdc1d src: Replace macros with util functions 2013-08-01 15:08:01 -07:00
Ben Noordhuis
6bd922fce8 dgram: report send errors to cb, don't pass bytes
Passing the number of sent bytes to the callback is superfluous;
datagram sockets operate in atomic mode: either the sendmsg() system
call succeeds or it fails but it never does partial writes.

Instead, report send errors to the callback. UDP error reporting is
fairly haphazard on most platforms. You should not expect reliable
delivery of anything besides EMSGSIZE and (possibly) ENETDOWN and
ENETUNREACH.

Fixes #2608.
2013-07-29 06:48:46 +02: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
Trevor Norris
278183a902 {stream,udp,tls}_wrap: remove unused offset/length
The function arguments offset and length are now no longer used since
all I/O requests now use discretely allocated memory.
2013-07-03 15:03:41 -07:00
Ben Noordhuis
92023b4b37 dgram: fix no address bind()
I broke dgram.Socket#bind(port, cb) almost a year ago in 332fea5a but
it wasn't until today that someone complained and none of the tests
caught it because they all either specify the address or omit the
callback.

Anyway, now it works again and does what you expect: it binds the
socket to the "any" address ("0.0.0.0" for IPv4 and "::" for IPv6.)
2013-04-18 00:54:57 +02:00
Andreas Madsen
bdf7ac2c5d child_process: support sending dgram socket
child.send can send net servers and sockets. Now that we have support
for dgram clusters this functionality should be extended to include
dgram sockets.
2013-03-07 17:51:17 +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
Bert Belder
6311f1c30a dgram: avoid EventEmitter leak warning
When a datagram socket hasn't been bound yet, node will defer `send()`
operations until binding has completed. Before this patch a `listening`
listener would be installed every time `send` was called. This triggered
an EventEmitter leak warning when more than 10 packets were sent in a
tight loop. Therefore switch to using a single `listening` listener, and
use an array to enqueue outbound packets.
2013-01-28 22:19:02 +01:00
Bert Belder
5e7e51c2fe cluster: support datagram sockets 2013-01-28 22:12:21 +01:00
isaacs
97db62b4d9 Merge remote-tracking branch 'ry/v0.8' into master
Conflicts:
	AUTHORS
	ChangeLog
	Makefile
	src/node_version.h
2013-01-11 10:18:07 -08:00
Ben Noordhuis
ad6769fc92 dgram: don't assert on send('string')
Raise a TypeError when the argument to send() or sendto() is anything
but a Buffer.

Fixes the following assertion:

  $ node -e 'require("dgram").createSocket("udp4").send("BAM")'
  node: ../../src/udp_wrap.cc:220: static v8::Handle<v8::Value>
  node::UDPWrap::DoSend(const v8::Arguments&, int): Assertion
  `Buffer::HasInstance(args[0])' failed.
  Aborted (core dumped)

Fixes #4496.
2013-01-08 04:32:40 +01:00
Ben Noordhuis
9e32c2ef3e dgram: fix double implicit bind error
Calling send() on an unbound socket forces an implicit bind to
a random port.

332fea5 made the 'listening' event asynchronous. Unfortunately,
it also introduced a bug where the implicit bind was tried more
than once if send() was called again before the first bind operation
completed.

Address that by keeping track of the bind status and making sure that
bind() is called only once.

Fixes #4499.
2012-12-31 17:53:00 +01:00
Ben Noordhuis
61978f57e6 dgram: remove stale code 2012-10-13 01:27:15 +02:00
Ben Noordhuis
332fea5ac1 dgram: make .bind() always asynchronous 2012-07-26 23:55:25 +02:00
Timothy J Fontaine
2637b5c261 ref/unref for net.Socket net.Server dgram.Socket 2012-07-23 18:31:30 +02:00