summaryrefslogtreecommitdiff
path: root/src/tcp_wrap.cc
AgeCommit message (Collapse)Author
2016-05-24src: no abort from getter if object isn't wrappedTrevor Norris
v8::Object::GetAlignedPointerFromInternalField() returns a random value if Wrap() hasn't been run on the object handle. Causing v8 to abort if certain getters are accessed. It's possible to access these getters and functions during class construction through the AsyncWrap init() callback, and also possible in a subset of those scenarios while running the persistent handle visitor. Mitigate this issue by manually setting the internal aligned pointer field to nullptr in the BaseObject constructor and add necessary logic to return appropriate values when nullptr is encountered. PR-URL: https://github.com/nodejs/node/pull/6184 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net>
2016-05-11handle_wrap: IsRefed() -> HasRef()Jeremiah Senkpiel
Rename slightly to HasRef() at bnoordhuis’ request. Better reflects what we actually do for this check. Refs: https://github.com/nodejs/node/pull/6395 Refs: https://github.com/nodejs/node/pull/6204 Refs: https://github.com/nodejs/node/pull/6401 Refs: https://github.com/nodejs/node/pull/6382 Refs: https://github.com/nodejs/node/pull/6381 PR-URL: https://github.com/nodejs/node/pull/6546 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Trevor Norris <trev.norris@gmail.com>
2016-05-11Revert "handle_wrap: IsRefed -> Unrefed, no isAlive check"Jeremiah Senkpiel
This reverts commit 9bb5a5e2a127010807f5b8a8bf4cf34109271c55. This API is not suitable because it depended on being able to potentially access the handle's flag after the handle was already cleaned up. Since this is not actually possible (obviously, oops) this newer API no longer makes much sense, and the older API is more suitable. API comparison: IsRefed -> Has a strong reference AND is alive. (Deterministic) Unrefed -> Has a weak reference OR is dead. (Less deterministic) Refs: https://github.com/nodejs/node/pull/6395 Refs: https://github.com/nodejs/node/pull/6204 Refs: https://github.com/nodejs/node/pull/6401 Refs: https://github.com/nodejs/node/pull/6382 Fixes: https://github.com/nodejs/node/pull/6381 PR-URL: https://github.com/nodejs/node/pull/6546 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Conflicts: src/handle_wrap.cc test/parallel/test-handle-wrap-isrefed-tty.js test/parallel/test-handle-wrap-isrefed.js
2016-04-25handle_wrap: IsRefed -> Unrefed, no isAlive checkJeremiah Senkpiel
This fixes my perceived usability issues with 7d8882b. Which, at the time of writing, has not landed in any release except v6 RCs. This should not be considered a breaking change due to that. It is useful if you have a handle, even if it has been closed, to be able to inspect whether that handle was unrefed or not. As such, this renames the method accordingly. If people need to check a handle's aliveness, that is a separate API we should consider exposing. Refs: https://github.com/nodejs/node/pull/5834 PR-URL: https://github.com/nodejs/node/pull/6204 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com>
2016-04-25src: fix check-imports.py linter errorsSakthipriyan Vairamani
This patch fixes all the linter errors. PR-URL: https://github.com/nodejs/node/pull/6105 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2016-04-07handle_wrap: expose an `isRefed()` check to JSJeremiah Senkpiel
This allows third-party tools to check whether or not a handle that can be unreferenced is unreferenced at a particular time. Notably, this should be helpful for inspection via AsyncWrap. Also, this is useful even to node's internals, particularly timers. Refs: https://github.com/nodejs/node/pull/5828 Refs: https://github.com/nodejs/node/pull/5827 PR-URL: https://github.com/nodejs/node/pull/5834 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com>
2016-04-05src: replace ARRAY_SIZE with typesafe arraysizeBen Noordhuis
To prevent `ARRAY_SIZE(&arg)` (i.e., taking the array size of a pointer) from happening again. PR-URL: https://github.com/nodejs/node/pull/5969 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2016-03-03src: fix NewInstance deprecation warningsMichaël Zasso
PR-URL: https://github.com/nodejs/node/pull/4722 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
2015-10-01async_wrap: update providers and add testTrevor Norris
Several provider ids have been removed that are no longer in use. Others have been updated to match their class constructors. Add test to ensure all internally listed providers are used. PR-URL: https://github.com/nodejs/node/pull/3139 Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-by: Stephen Belanger <admin@stephenbelanger.com>
2015-09-06src: replace usage of v8::Handle with v8::LocalMichaël Zasso
v8::Handle is deprecated: https://codereview.chromium.org/1224623004 PR-URL: https://github.com/nodejs/io.js/pull/2202 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-08-27src: DRY getsockname/getpeername codeBen Noordhuis
Extract the common logic into a template function. No functional changes, just code cleanup. 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-06-17async-wrap: add provider id and object info cbTrevor Norris
Re-add the wrapper class id to AsyncWrap instances so they can be tracked directly in a heapdump. Previously the class id was given without setting the heap dump wrapper class info provider. Causing a segfault when a heapdump was taken. This has been added, and the label_ set to the given provider name so each instance can be identified. The id will not be set of the passed object has no internal field count. As the class pointer cannot be retrieved from the object. In order to properly report the allocated size of each class, the new pure virtual method self_size() has been introduces. PR-URL: https://github.com/nodejs/io.js/pull/1896 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-03-05net: allow port 0 in connect()cjihrig
The added validation allows non-negative numbers and numeric strings. All other values result in a thrown exception. Fixes: https://github.com/joyent/node/issues/9194 PR-URL: https://github.com/joyent/node/pull/9268 Reviewed-By: Julien Gilli <julien.gilli@joyent.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: James M Snell <jasnell@users.noreply.github.com>
2015-02-28stream_base: `.writev()` has limited supportFedor Indutny
Only TCP and JSStream do support `.writev()` on all platforms at the moment. Ensure that it won't be enabled everywhere. Fix: https://github.com/iojs/io.js/issues/995 PR-URL: https://github.com/iojs/io.js/pull/1008 Reviewed-by: Bert Belder <bertbelder@gmail.com> Reviewed-By: Rod Vagg <rod@vagg.org>
2015-02-22stream_base: introduce StreamBaseFedor Indutny
StreamBase is an improved way to write C++ streams. The class itself is for separting `StreamWrap` (with the methods like `.writeAsciiString`, `.writeBuffer`, `.writev`, etc) from the `HandleWrap` class, making possible to write abstract C++ streams that are not bound to any uv socket. The following methods are important part of the abstraction (which mimics libuv's stream API): * Events: * `OnAlloc(size_t size, uv_buf_t*)` * `OnRead(ssize_t nread, const uv_buf_t*, uv_handle_type pending)` * `OnAfterWrite(WriteWrap*)` * Wrappers: * `DoShutdown(ShutdownWrap*)` * `DoTryWrite(uv_buf_t** bufs, size_t* count)` * `DoWrite(WriteWrap*, uv_buf_t*, size_t count, uv_stream_t* handle)` * `Error()` * `ClearError()` The implementation should provide all of these methods, thus providing the access to the underlying resource (be it uv handle, TLS socket, or anything else). A C++ stream may consume the input of another stream by replacing the event callbacks and proxying the writes. This kind of API is actually used now for the TLSWrap implementation, making it possible to wrap TLS stream into another TLS stream. Thus legacy API calls are no longer required in `_tls_wrap.js`. PR-URL: https://github.com/iojs/io.js/pull/840 Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
2015-02-11src: switch from QUEUE to intrusive listBen Noordhuis
This commit also breaks up req_wrap.h into req-wrap.h and req-wrap-inl.h to work around a circular dependency issue in env.h. PR-URL: https://github.com/iojs/io.js/pull/667 Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com>
2015-01-12Remove excessive copyright/license boilerplateisaacs
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-07src: pass Isolate to node::Utf8Value constructorTrevor Norris
Initial attempt to remove all uses of Isolate::GetCurrent(). Still exists a few locations, but this works out a heavy usage. PR-URL: https://github.com/iojs/io.js/pull/244 Reviewed-by: Ben Noordhuis <info@bnoordhuis.nl>
2014-12-09async-wrap: explicitly pass parentTrevor Norris
When instantiating a new AsyncWrap allow the parent AsyncWrap to be passed. This is useful for cases like TCP incoming connections, so the connection can be tied to the server receiving the connection. Because the current architecture instantiates the *Wrap inside a v8::FunctionCallback, the parent pointer is currently wrapped inside a new v8::External every time and passed as an argument. This adds ~80ns to instantiation time. A future optimization would be to add the v8::External as the data field when creating the v8::FunctionTemplate, change the pointer just before making the call then NULL'ing it out afterwards. This adds enough code complexity that it will not be attempted until the current approach demonstrates it is a bottle neck. 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-09src: remove unnecessary template parameterTrevor Norris
The template class information is received via the type of the first argument. So there is no need to use Wrap<T>(handle). 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-09src: all wraps now use actual FunctionTemplateTrevor Norris
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-10-23src: replace NULL with nullptrBen Noordhuis
Now that we are building with C++11 features enabled, replace use of NULL with nullptr. The benefit of using nullptr is that it can never be confused for an integral type because it does not support implicit conversions to integral types except boolean - unlike NULL, which is defined as a literal `0`.
2014-10-13src: attach env directly to api functionsBen Noordhuis
Attach the per-context execution environment directly to API functions. Rationale: * Gets node one step closer to multi-isolate readiness. * Avoids multi-context confusion, e.g. when the caller and callee live in different contexts. * Avoids expensive calls to pthread_getspecific() on platforms where V8 does not know how to use the thread-local storage directly. (Linux, the BSDs.) PR-URL: https://github.com/node-forward/node/pull/18 Reviewed-By: Fedor Indutny <fedor@indutny.com>
2014-10-12src: replace assert() with CHECK()Ben Noordhuis
Mechanically replace assert() statements with UNREACHABLE(), CHECK(), or CHECK_{EQ,NE,LT,GT,LE,GE}() statements. The exceptions are src/node.h and src/node_object_wrap.h because they are public headers. PR-URL: https://github.com/node-forward/node/pull/16 Reviewed-By: Fedor Indutny <fedor@indutny.com>
2014-10-12src: fix up importsBen Noordhuis
Make tools/check-imports.sh stop complaining, remove or reorder 'using' statements. PR-URL: https://github.com/node-forward/node/pull/16 Reviewed-By: Fedor Indutny <fedor@indutny.com>
2014-10-12src: remove unnecessary HandleScopesBen Noordhuis
API callback functions don't need to create a v8::HandleScope instance because V8 already creates one in the JS->C++ adapter frame. PR-URL: https://github.com/node-forward/node/pull/16 Reviewed-By: Fedor Indutny <fedor@indutny.com>
2014-09-03stream_wrap: Add support to write binary stringsTrevor Norris
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-02src: reading/owner/onread/onconnection for tcpJackson Tian
Initialize fields to avoid Hidden Class creation in runtime. Reviewed-By: Fedor Indutny <fedor@indutny.com>
2014-06-10Merge remote-tracking branch 'upstream/v0.10'Timothy J Fontaine
Conflicts: AUTHORS ChangeLog deps/v8/src/api.cc deps/v8/src/unicode-inl.h deps/v8/src/unicode.h lib/_stream_readable.js lib/http.js src/cares_wrap.cc src/node.cc src/node_crypto.cc src/node_dtrace.cc src/node_file.cc src/node_stat_watcher.cc src/node_version.h src/process_wrap.cc src/string_bytes.cc src/string_bytes.h src/udp_wrap.cc src/util.h test/simple/test-buffer.js test/simple/test-stream2-compatibility.js
2014-04-29crypto: fix a couple of VC++ warningsRasmus Christian Pedersen
Signed-off-by: Fedor Indutny <fedor@indutny.com>
2014-04-02node: add signature to SET_PROTOTYPE_METHODC. Scott Ananian
This prevents segfaults when a native method is reassigned to a different object (which corrupts args.This()). When unwrapping, clients should use args.Holder() instead of args.This(). Closes #6690. Signed-off-by: Trevor Norris <trev.norris@gmail.com>
2014-03-13src: update to v8 3.24 APIsFedor Indutny
2014-02-22src: remove `node_isolate` from sourceFedor Indutny
fix #6899
2014-02-05async_wrap: add provider types/pass to constructorTrevor Norris
These will be used to allow users to filter for which types of calls they wish their callbacks to run. Signed-off-by: Timothy J Fontaine <tjfontaine@gmail.com>
2014-01-27node: register modules from DSO constructorsKeith M Wesolowski
Built-in modules should be automatically registered, replacing the static module list. Add-on modules should also be automatically registered via DSO constructors. This improves flexibility in adding built-in modules and is also a prerequisite to pure-C addon modules.
2014-01-27deps: update uv to 0.11.18Fedor Indutny
2014-01-21async_wrap/timers: remove Add/RemoveAsyncListenerTrevor Norris
The ability to add/remove an AsyncListener to an object after its creation was an artifact of trying to get AL working with the domain module. Now that is no longer necessary and other features are going to be implemented that would be affected by this functionality. So the code will be removed for now to simplify the implementation process. In the future this code will likely be reintroduced, but after some other more important matters have been addressed. None of this functionality was documented, as is was meant specifically for domain specific implementation work arounds. Signed-off-by: Timothy J Fontaine <tjfontaine@gmail.com>
2013-11-12src: fix Context::Scope usageBen Noordhuis
env->context() may or may not create a new Local. It currently does not but don't depend on that behavior, create a HandleScope first.
2013-11-11src: fix Environment::GetCurrent() usageBen Noordhuis
Create a HandleScope before calling the Environment::GetCurrent() that takes a v8::Isolate* as an argument because it creates a handle with the call to v8::Isolate::CurrentContext().
2013-10-31async-wrap: add methods to udp/tcp/pipe/timersTrevor Norris
Now it's possible to add/remove an async listener to an individual handle created by UDP, TCP, Pipe or Timer.
2013-10-31node: add AsyncListener supportTrevor Norris
AsyncListener is a JS API that works in tandem with the AsyncWrap class to allow the user to be alerted to key events in the life cycle of an asynchronous event. The AsyncWrap class has its own MakeCallback implementation that core will be migrated to use, and uses state sharing techniques to allow quicker communication between JS and C++ whether the async event callbacks need to be called.
2013-10-29src: shorten Object{Wrap,Unwrap}Trevor Norris
Going back to the original names of Wrap/Unwrap now that most all the class members that duplicate the name and functionality have been removed.
2013-10-29src: don't use class specific Unwrap methodsTrevor Norris
Instead use the template functions in util.h.
2013-10-29src: use function to get internal pointerTrevor Norris
Remove the NODE_{WRAP,UNWRAP} macros and instead use template functions.
2013-10-17cpplint: disallow if one-linersFedor Indutny
2013-09-06src: add multi-context supportBen Noordhuis
This commit makes it possible to use multiple V8 execution contexts within a single event loop. Put another way, handle and request wrap objects now "remember" the context they belong to and switch back to that context when the time comes to call into JS land. This could have been done in a quick and hacky way by calling v8::Object::GetCreationContext() on the wrap object right before making a callback but that leaves a fairly wide margin for bugs. Instead, we make the context explicit through a new Environment class that encapsulates everything (or almost everything) that belongs to the context. Variables that used to be a static or a global are now members of the aforementioned class. An additional benefit is that this approach should make it relatively straightforward to add full isolate support in due course. There is no JavaScript API yet but that will be added in the near future. This work was graciously sponsored by GitHub, Inc.
2013-09-04uv: upgrade to v0.11.13Ben Noordhuis
This commit changes src/tcp_wrap.cc and src/udp_wrap.cc just enough to get by (i.e. to compile and function correctly.) The new libuv API allows for more cleanup and deduplication but I'm saving that for another day.
2013-09-03uv: upgrade to v0.11.12Ben Noordhuis
* upgrade deps/uv/ to v0.11.12. * update files in src/ after a libuv API change.
2013-08-12src: fix build break from generic macro nameTrevor Norris
WRAP is too generic a macro name and causes the build to fail from conflicts. They have been prepended with NODE_.
2013-08-12src: centralize class wrap/unwrapTrevor Norris
While almost all cases were handled by simple WRAP/UNWRAP macros, this extends those to cover all known occurrences.