Previously the getter would mutate the kDefaultTriggerAsncId value. This
refactor changes the setter to bind the current kDefaultTriggerAsncId to
a scope, such that the getter doesn't have to mutate its own value.
PR-URL: https://github.com/nodejs/node/pull/17273
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
rename initTriggerId to defaultTriggerAsyncId such it matches the rest
of our naming.
PR-URL: https://github.com/nodejs/node/pull/17273
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
The initials of expected in TypeError[ERR_INVALID_ARG_TYPE]
are inconsistent. This change is to unify them.
PR-URL: https://github.com/nodejs/node/pull/16401
Fixes: https://github.com/nodejs/node/issues/16383
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This change is to unify the declaration for constants into using
destructuring on the top-level-module scope, reducing some redundant
code.
PR-URL: https://github.com/nodejs/node/pull/16063
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Covert lib/net.js over to using lib/internal/errors.js
- Replace thrown errors in lib/net.js
with errors from lib/internal/errors.
The ERR_INVALID_OPT_VALUE error have been used
in the Server.prototype.listen() method
- Update tests according to the above modifications
PR-URL: https://github.com/nodejs/node/pull/14782
Refs: https://github.com/nodejs/node/issues/11273
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit refactors the get/set send/receive buffer size
methods in the following ways:
- Use booleans instead of strings and numbers to differentiate
between the send and receive buffers.
- Reduce the amount of branching and complexity in the C++ code.
Refs: https://github.com/nodejs/node/pull/13623
PR-URL: https://github.com/nodejs/node/pull/15483
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Add wrapper for uv's uv_udp_set_multicast_interface which provides the
sender side mechanism to explicitly select an interface. The
equivalent receiver side mechanism is the optional 2nd argument of
addMembership().
PR-URL: https://github.com/nodejs/node/pull/7855
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
* setRecvBufferSize(int) and setSendBufferSize(int)
* added docs for send/receive buffer sizes
* Added options support to set buffer sizes in
dgram.createSocket().
PR-URL: https://github.com/nodejs/node/pull/13623
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit adds support for custom DNS lookup functions in
dgram sockets. This is similar to the existing feature in net
sockets.
Refs: https://github.com/nodejs/node/issues/6189
PR-URL: https://github.com/nodejs/node/pull/14560
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Wyatt Preul <wpreul@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
* internal/errors - assert should already be in place when calling any
of the message generating functions.
* No lazy load if not necessary.
* Replace function calls with `if`s.
PR-URL: https://github.com/nodejs/node/pull/14167
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/13857
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Changed the parameter name in set(Multicast)TTL from "arg" to "ttl"
both within code and error messages and added the actual type of the
argument to the error message.
PR-URL: https://github.com/nodejs/node/pull/13747
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Covert lib/dgram.js over to using lib/internal/errors.js
for generating Errors. See
[using-internal-errors.md](https://github.com/nodejs/node/blob/master/doc/guides/using-internal-errors.md)
for more details.
I have not addressed the cases that use errnoException() and
exceptionWithHostPort() helper methods as changing these would require
fixing the tests across all of the different files that use them. In
addition, these helpers already add a `code` to the Error and we'll
have to discuss how that interacts with the `code` used by
lib/internal/errors.js. I believe we should convert all users
of errnoException and exceptionWithHostPort in a PR dedicated to
that conversion.
PR-URL: https://github.com/nodejs/node/pull/12926
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben.bridgewater@fintura.de>
Refactor dgram module to use the more efficient
module.exports = {} pattern.
PR-URL: https://github.com/nodejs/node/pull/11696
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Ron Korving <ron@ronkorving.nl>
- Do not require presence of `address` parameter to use `callback`
parameter; `address` is *always* optional
- Improve exception messaging if `address` is invalid type
- If `address` is an invalid type, guarantee a synchronously thrown
exception
- Update documentation to reflect signature changes
- Add coverage around valid, undocumented types for `address` parameter.
- Add coverage around known invalid, but uncovered, types for `address`
parameter.
PR-URL: https://github.com/nodejs/node/pull/10473
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit removes self = this style assignments from dgram.
PR-URL: https://github.com/nodejs/node/pull/11243
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
When send() triggers an implicit bind, the send operation is
added to an internal queue. If a DNS error occurs during the bind,
there is currently no mechanism for clearing the queue other than
sending more data. If DNS errors keep occurring, the queue will
continue to grow with no upper bound. This commit reports errors
with implicit binds, and clears the queue. This should be fine,
given the nature of UDP.
Refs: https://github.com/nodejs/node-v0.x-archive/pull/8705
Refs: https://github.com/nodejs/node/pull/10902
PR-URL: https://github.com/nodejs/node/pull/11036
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
There is no difference between alloc(0) and allocUnsafe(0), so there is
no reason to confuse anyone reading the code with an additional call to
allocUnsafe.
PR-URL: https://github.com/nodejs/node/pull/8751
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
- Enforces strict comparisons in dgram - bindState should
always be strictly equal to one of the defined constant states,
and newHandle type is a string.
- Check that the argument `type` in createSocket is not null
when it is of type 'object', before using its `type` property.
- Adds a test to check dgram.createSocket is properly
validating its `type` argument.
PR-URL: https://github.com/nodejs/node/pull/8011
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Yorkie Liu <yorkiefixer@gmail.com>
Reviewed-By: Jackson Tian <shvyo1987@gmail.com>
This commit fix a possible crash situation in dgram send().
A crash is possible if an array is passed, and then altered after the
send call, as the call to libuv is wrapped in process.nextTick().
It also avoid sending an empty array to libuv by allocating an empty
buffer. It also does some cleanup inside send() to increase readability.
It removes test flakyness by use common.mustCall and
common.platformTimeout. Fixes situations were some events were not
asserted to be emitted.
Fixes: https://github.com/nodejs/node/issues/6616
PR-URL: https://github.com/nodejs/node/pull/6804
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
The require('constants') module is currently undocumented and mashes
together unrelated constants. This refactors the require('constants')
in favor of distinct os.constants, fs.constants, and crypto.constants
that are specific to the modules for which they are relevant. The
next step is to document those within the specific modules.
PR-URL: https://github.com/nodejs/node/pull/6534
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Robert Lindstaedt <robert.lindstaedt@gmail.com>
Prior to c9fd9e2162, UDP sockets
would callback with a null error on successful send() calls. The
current behavior is to pass 0 as the error. This commit restores
the previous, more expected behavior.
PR-URL: https://github.com/nodejs/node/pull/5929
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
Several changes:
* Soft-Deprecate Buffer() constructors
* Add `Buffer.from()`, `Buffer.alloc()`, and `Buffer.allocUnsafe()`
* Add `--zero-fill-buffers` command line option
* Add byteOffset and length to `new Buffer(arrayBuffer)` constructor
* buffer.fill('') previously had no effect, now zero-fills
* Update the docs
PR-URL: https://github.com/nodejs/node/pull/4682
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Fixes a regression introduced by: https://github.com/nodejs/node/pull/4374.
Adds a new test to avoid similar issue in the future.
The test is disabled on windows, because this feature never worked
there.
Fixes: https://github.com/nodejs/node/issues/5398
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Rod Vagg <rod@vagg.org>
Reviewed-By: Evan Lucas <evanlucas@me.com>
A few variables in `lib/dgram.js` are redeclared with `var` in a scope
where they have already been declared. These instances can be scoped
more narrowly with `const`, so that's what this change does.
PR-URL: https://github.com/nodejs/node/pull/4940
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Added ability to dgram.send to send multiple buffers, _writev style.
The offset and length parameters in dgram.send are now optional.
Refactored the dgram benchmarks, and seperated them from net.
Added docs for the new signature.
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Fixes: https://github.com/nodejs/node/issues/4302
PR-URL: https://github.com/nodejs/node/pull/4374
Reassigning a named parameter while also using the arguments
object causes the entire function to never be optimized.
PR-URL: https://github.com/nodejs/node/pull/4613
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
When a string is passed to udpsock.send, it is automatically
converted to a Buffer. In that case, it is no longer needed
to test whether or not the argument is a Buffer or not.
PR-URL: https://github.com/nodejs/node/pull/4301
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Roman Reiss <me@silverwind.io>
This commit fixes some error messages that are not consistent with
some general rules which most of the error messages follow.
PR-URL: https://github.com/nodejs/node/pull/3374
Reviewed-By: Roman Reiss <me@silverwind.io>
The `events` module already exports `EventEmitter` constructor function
So, we don't have to use `events.EventEmitter` to access it.
Refer: https://github.com/nodejs/node/pull/2896
PR-URL: https://github.com/nodejs/node/pull/2921
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
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>