aboutsummaryrefslogtreecommitdiff
path: root/lib/net.js
AgeCommit message (Collapse)Author
2016-10-14net: fix ambiguity in EOF handlingFedor Indutny
`end` MUST always be emitted **before** `close`. However, if a handle will invoke `uv_close_cb` immediately, or in the same JS tick - `close` may be emitted first. PR-URL: https://github.com/nodejs/node/pull/9066 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rich Trott <rtrott@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>
2016-09-26http: socket connection timeout for http requestRene Weber
This allows passing the socket connection timeout to http#request such that it will be set before the socket is connecting PR-URL: https://github.com/nodejs/node/pull/8101 Fixes: https://github.com/nodejs/node/issues/7580 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com>
2016-09-12net: refactor Server.prototype.listenJan Schär
This PR simplifies Server.prototype.listen, removing some redundancy and inconsistency. Because listen and connect have a similar function signature, normalizeConnectArgs can be reused for listen. listenAfterLookup renamed to lookupAndListen for consistency with lookupAndConnect, and moved out of Server.prototype.listen. PR-URL: https://github.com/nodejs/node/pull/4039 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Glen Keane <glenkeane.94@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2016-08-27net: make holding the buffer in memory more robustAnna Henningsen
Set the `req.buffer` property, which serves as a way of keeping a `Buffer` alive that is being written to a stream, on the C++ side instead of the JS side. This closes a hole where buffers that were temporarily created in order to write strings with uncommon encodings (e.g. `hex`) were passed to the native side without being set as `req.buffer`. Fixes: https://github.com/nodejs/node/issues/8251 PR-URL: https://github.com/nodejs/node/pull/8252 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-08-23net: add length check when normalizing argsBrian White
This helps to prevent possible deoptimizations that arise when trying to access nonexistent indices. PR-URL: https://github.com/nodejs/node/pull/8112 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2016-08-23net: remove unnecessary variablesBrian White
V8 is smart enough to optimize the length property checking when iterating over an array with a for loop. PR-URL: https://github.com/nodejs/node/pull/8112 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2016-07-12lib,benchmark,test: implement consistent bracesRich Trott
This change is in preparation for lint-enforced brace style. PR-URL: https://github.com/nodejs/node/pull/7630 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Michaël Zasso <mic.besace@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Rod Vagg <rod@vagg.org>
2016-07-08net: export isIPv4, isIPv6 directly from caresSakthipriyan Vairamani
The function objects encapsulating `isIPv4` and `isIPv6` are not necessary. They can be directly exposed from `cares`. PR-URL: https://github.com/nodejs/node/pull/7481 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <mic.besace@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
2016-06-07buffer: introduce latin1 encoding termTrevor Norris
When node began using the OneByte API (f150d56) it also switched to officially supporting ISO-8859-1. Though at the time no new encoding string was introduced. Introduce the new encoding string 'latin1' to be more explicit. The previous 'binary' and documented as an alias to 'latin1'. While many tests have switched to use 'latin1', there are still plenty that do both 'binary' and 'latin1' checks side-by-side to ensure there is no regression. PR-URL: https://github.com/nodejs/node/pull/7111 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
2016-04-27net: introduce `Socket#connecting` propertyFedor Indutny
There is no official way to figure out if the socket that you have on hand is still connecting to the remote host. Introduce `Socket#connecting`, which is essentially an unprefixed `_connecting` property that we already had. PR-URL: https://github.com/nodejs/node/pull/6404 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
2016-04-20net: Validate port in createServer().listen()Dirceu Pereira Tiegs
Make sure we validate the port number in all kinds of `listen()` calls. Fixes: https://github.com/nodejs/node/issues/5727 PR-URL: https://github.com/nodejs/node/pull/5732 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2016-04-20net: replace __defineGetter__ with definePropertyFedor Indutny
`Object.prototype.__defineGetter__` is deprecated now, use `Object.defineProperty` instead. PR-URL: https://github.com/nodejs/node/pull/6284 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-04-20stream_base: expose `bytesRead` getterFedor Indutny
This will provide `bytesRead` data on consumed sockets. Fix: #3021 PR-URL: https://github.com/nodejs/node/pull/6284 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-04-20net: set ADDRCONFIG DNS hint in connectionscjihrig
b85a50b6da5bbd7e9c8902a13dfbe1a142fd786a removed the implicit setting of DNS hints when creating a connection. This caused some of the pi2 machines to become flaky. This commit restores the implicit dns.ADDRCONFIG hint, but not dns.V4MAPPED. Fixes: https://github.com/nodejs/node/issues/6133 PR-URL: https://github.com/nodejs/node/pull/6281 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Claudio Rodriguez <cjrodr@yahoo.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-04-05net: remove implicit setting of DNS hintscjihrig
This commit removes the implicit setting of the V4MAPPED and ADDRCONFIG DNS flags in createConnection(). As of 39de601e1c3eda92eb2e37eca4e6aa960f206f39, users that need these flags can set them explicitly. PR-URL: https://github.com/nodejs/node/pull/6021 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-04-01net: support DNS hints in createConnection()Colin Ihrig
This commit adds support for passing DNS lookup hints to createConnection(). PR-URL: https://github.com/nodejs/node/pull/6000 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
2016-04-01net: improve socket.write() error messagePhillip Johnsen
Informative error messages are very important for developers and could possibly save hours of debugging and frustration. This improves the error message thrown when writing invalid data into a socket, by communicating what's expected compared to what the developer just tried to write. PR-URL: https://github.com/nodejs/node/pull/5981 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2016-03-27net: refactor self=this to arrow functionsBenjamin Gruenbaum
Refactor unused self=this code to code without without this pattern making it more consistent with the rest of our code. PR-URL: https://github.com/nodejs/node/pull/5857 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Roman Klauke <romankl@users.noreply.github.com>
2016-03-21lib: reduce usage of `self = this`Jackson Tian
Remove unnecessary `self = this`. PR-URL: https://github.com/nodejs/node/pull/5231 Reviewed-By: James M Snell <jasnell@gmail.com>
2016-03-20net: remove unused `var self = this` from old codeBenjamin Gruenbaum
Removed an unused `var self = this` that is no longer required. PR-URL: https://github.com/nodejs/node/pull/5224 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
2016-03-18net: emit host in lookup eventHUANG Wei
Previously, we emitted ip and addressType. This change includes the host as the last argument to the lookup event. PR-URL: https://github.com/nodejs/node/pull/5598 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com>
2016-03-16buffer: add .from(), .alloc() and .allocUnsafe()James M Snell
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>
2016-03-15net: make `isIPv4` and `isIPv6` more efficientVladimir Kurchatkin
`isIPv4` and `isIPv6` are implemented on top of `isIP`, which in turn checks the sting for being both IPv4 and IPv6, which can be inefficient in some scenarios. This commit makes them use `uv_inet_pton` directly instead. PR-URL: https://github.com/nodejs/node/pull/5478 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
2016-03-15net: type check createServer options objectSam Roberts
net.createServer('aPipe') and net.createServer(8080) are mistakes, and now throw a TypeError instead of silently being treated as an object. PR-URL: https://github.com/nodejs/node/pull/2904 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2016-03-10lib: copy arguments object instead of leaking itNathan Woltman
Instead of leaking the arguments object by passing it as an argument to a function, copy it's contents to a new array, then pass the array. This allows V8 to optimize the function that contains this code, improving performance. PR-URL: https://github.com/nodejs/node/pull/4361 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
2016-02-17net: use `_server` for internal book-keepingFedor Indutny
The role of `this.server` is now split between `this._server` and `this.server`. Where the first one is used for counting active connections of `net.Server`, and the latter one is just a public API for users' consumption. The reasoning for this is simple, `TLSSocket` instances wrap `net.Socket` instances, thus both refer to the `net.Server` through the `this.server` property. However, only one of them should be used for `net.Server` connection count book-keeping, otherwise double-decrement will happen on socket destruction. Fix: #5083 PR-URL: https://github.com/nodejs/node/pull/5262 Reviewed-By: James M Snell <jasnell@gmail.com>
2016-02-01net: refactor redeclared variablesRich Trott
`lib/net.js` contained four variables that were redeclared with `var` in the same scope. This change refactors those redeclarations so they are scoped properly. PR-URL: https://github.com/nodejs/node/pull/4963 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Roman Klauke <romaaan.git@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2016-01-30net: move isLegalPort to internal/netEvan Lucas
isLegalPort can be used in more places than just net.js. This change moves it to a new internal net module in preparation for using it in the dns module. PR-URL: https://github.com/nodejs/node/pull/4882 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
2016-01-27tls_wrap: reach error reporting for UV_EPROTOFedor Indutny
Do not swallow error details when reporting UV_EPROTO asynchronously, and when creating artificial errors. Fix: #3692 PR-URL: https://github.com/nodejs/node/pull/4885 Reviewed-By: Shigeki Ohtsu <ohtsu@iij.ad.jp> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-01-21net: add net.listening boolean property over a getterJosé Moreira
Added a listening property into net.Server.prototype indicating if the server is listening or not for connections. Other Server constructors that rely on net.Server should also gain access to this property. Also included tests for net and http subsystems. PR-URL: https://github.com/nodejs/node/pull/4743 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2016-01-18Revert "stream: add bytesRead property for readable"cjihrig
This reverts commit bfb2cd0bfddd716366f1c89637cca9fc1234e592. The bytesRead property, as implemented, tracks characters instead of bytes when using an identity encoding. Refs: https://github.com/nodejs/node/pull/4372 PR-URL: https://github.com/nodejs/node/pull/4746 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
2016-01-16lib,test: remove extra semicolonsMichaël Zasso
PR-URL: https://github.com/nodejs/node/pull/2205 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
2016-01-14stream: add bytesRead property for readableJackson Tian
Add a bytesRead property for readable is useful in some use cases. When user want know how many bytes read of readable, need to caculate it in userland. If encoding is specificed, get the value is very slowly. PR-URL: https://github.com/nodejs/node/pull/4372 Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2016-01-13lib: fix style issues after eslint updateMichaël Zasso
With an indentation style of two spaces, it is not possible to indent multiline variable declarations by four spaces. Instead, the var keyword is used on every new line. Use const instead of var where applicable for changed lines. PR-URL: https://github.com/nodejs/io.js/pull/2286 Reviewed-By: Roman Reiss <me@silverwind.io>
2016-01-12net: remove hot path comment from connectEvan Lucas
This comment was added with an assumption that we could determine the IP address that localhost should resolve to without performing a lookup. This was a false assumption and should be removed. PR-URL: https://github.com/nodejs/node/pull/4648 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2016-01-08net, doc: fix line wrapping lint in net.jsJames M Snell
Missed on the previous review, minor line wrapping nit PR-URL: https://github.com/nodejs/node/pull/4588 Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2016-01-08net: fix dns lookup for androidJosh Dague
`V4MAPPED` isn't supported by Android either (as of 6.0) PR-URL: https://github.com/nodejs/node/pull/4580 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2015-12-17lib: use arrow functions instead of bindMinwoo Jung
use `arrow functions` instead of `bind(this)` in order to improve performance through optimizations. PR-URL: https://github.com/nodejs/node/pull/3622 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com>
2015-11-24net: add local address/port for better errorsJan Schär
Adds localAddress and localPort to req so we have better error messages. Also fixes a case where ex is used before it is declared. PR-URL: https://github.com/nodejs/node/pull/3946 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2015-11-20net: small code cleanupJan Schär
`options` is already a param of the function. PR-URL: https://github.com/nodejs/node/pull/3943 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Michaël Zasso <mic.besace@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2015-11-09lib: Consistent error messages in all modulesmicnic
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>
2015-10-12net: don't throw on bytesWritten accessTrevor Norris
If bytesWritten is accessed before the object has been properly constructed then return undefined. Fixes: https://github.com/nodejs/node/issues/3298 PR-URL: https://github.com/nodejs/node/pull/3305 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-09-23lib,src: remove usage of events.EventEmitterSakthipriyan Vairamani
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>
2015-09-07cluster: allow shared reused dgram socketsFedor Indutny
Allow listening on reused dgram ports in cluster workers. Fix: https://github.com/joyent/node/issues/9261 PR-URL: https://github.com/nodejs/node/pull/2548 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-08-28Revert "lib,src: add unix socket getsockname/getpeername"Ben Noordhuis
This reverts commit 6cd0e2664b1ce944e5e461457d160be83f70d379. This reverts commit 7a999a13766ac68049812fedbdfd15a0250f0f07. This reverts commit f337595441641ad36f6ab8ae770e56c1673ef692. It turns out that on Windows, uv_pipe_getsockname() is a no-op for client sockets. It slipped through testing because of a CI snafu. PR-URL: https://github.com/nodejs/node/pull/2584 Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
2015-08-27lib: add net.Socket#localFamily propertyBen Noordhuis
Complements the existing net.Socket#remoteFamily property. PR-URL: https://github.com/nodejs/node/pull/956 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com>
2015-08-27lib,src: add unix socket getsockname/getpeernameBen Noordhuis
The implementation is a minor API change in that socket.address() now returns a `{ address: '/path/to/socket' }` object, like it does for TCP and UDP sockets. Before this commit, it returned `socket._pipeName`, which is a string when present. Change common.PIPE on Windows from '\\\\.\\pipe\\libuv-test' to '\\\\?\\pipe\\libuv-test'. Windows converts the '.' to a '?' when creating a named pipe, meaning that common.PIPE didn't match the result from NtQueryInformationFile(). Fixes: https://github.com/nodejs/node/issues/954 PR-URL: https://github.com/nodejs/node/pull/956 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com>
2015-08-06net: ensure Socket reported address is currentRyan Graham
Any time the connection state or the underlying handle itself changes, the socket's name (aka, local address) can change. To deal with this we need to reset the cached sockname any time we set or unset the internal handle or an existing handle establishes a connection. PR-URL: https://github.com/nodejs/io.js/pull/2095 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2015-08-04net: do not set V4MAPPED on FreeBSDJulien Gilli
V4MAPPED is not supported on recent FreeBSD versions, at least on 10.1. Thus, do not set this flag in net.connect on FreeBSD. Fixes: https://github.com/joyent/node/issues/8540 Fixes: https://github.com/joyent/node/issues/9204 PR-URL: https://github.com/joyent/node/pull/18204 PR-URL: https://github.com/iojs/io.js/pull/1555 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Fedor Indutny <fedor@indutny.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-07-27net: don't throw on immediately destroyed socketEvan Lucas
Fixes regression introduced in af249fa8a15bad8996187e73b480b30dcd881bad. With connect being deferred to the next tick, Socket.destroy could be called before connect. Socket.destroy sets _connecting to false which would cause an assertion error. Fixes: https://github.com/nodejs/io.js/issues/2250 PR-URL: https://github.com/nodejs/io.js/pull/2251 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>