src: reading/owner/onread/onconnection for tcp

Initialize fields to avoid Hidden Class creation in runtime.

Reviewed-By: Fedor Indutny <fedor@indutny.com>
crypto: avoid memory leak

Reviewed-By: Fedor Indutny <fedor@indutny.com>
crypto: unsigned value can't be negative

Reviewed-By: Fedor Indutny <fedor@indutny.com>
cluster: centralize removal from workers list.

Currently, cluster workers can be removed from the workers list in three
different places:
- In the exit event handler for the worker process.
- In the disconnect event handler of the worker process.
- In the disconnect event handler of the cluster master.

However, handles for a given worker are cleaned up only in one of these
places: in the cluster master's disconnect event handler.

Because these events happen asynchronously, it is possible that the
workers list is empty before we even clean up one handle. This makes
the assert that makes sure that no handle is left when the workers
list is empty fail.

This commit removes the worker from the cluster.workers list only when
the worker is dead _and_ disconnected, at which point we're sure that
its associated handles are cleaned up.

Fixes #8191 and #8192.

Reviewed-By: Fedor Indutny <fedor@indutny.com>
configure: generate a fully statically linked exec

Allow to create an executable with no external dynamic libraries, also the
ones from the system. This is somewhat dependent of the used C lib, for
example glibc has some internal dynamic libraries loaded by itself, but for
other ones like eglibc or dietlib, this would produce a true static linked
executable. This can be of interest for embebers or resource constraints
platforms, but the main reason for this is to allow to use a Javascript
file as Linux kernel 'init' on NodeOS.

Reviewed-By: Fedor Indutny <fedor@indutny.com>
node,async-wrap: verify domain enter/exit are set

The REPL global object lazy loads modules by placing getters for each.
This causes MakeDomainCallback() to be run if a native module is loaded
from the REPL, but if the domain module hasn't been loaded then there
are no enter/exit callbacks to be called. Causing an assert() to fail.

Fix the issue by conditionally running the callback instead of asserting
it is available. Also add "addon" test to verify the fix.

Fixes: #8231
Signed-off-by: Trevor Norris <trev.norris@gmail.com>
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>
net: Improve Socket.prototype.write()

Reviewed-by: Trevor Norris <trev.norris@gmail.com>
crypto: use less memory for storing keys

Use `BIO_new_mem_buf` where possible to reduce memory usage and
initialization costs.
tls_wrap: fix use after free

Do not free TLSCallbacks from StreamWrap. TLSCallbacks is bound to a V8
object and should be collected by V8's GC.
tls: support multiple keys/certs

Required to serve website with both ECDSA/RSA certificates.
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>
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>
test: listen on exclusive port in cluster workers

Test that listening on exclusive ports with the cluster module works
correctly.

Reviewed-by: Trevor Norris <trev.norris@gmail.com>
lib: improved forEach object performance

Reviewed-by: Trevor Norris <trev.norris@gmail.com>
src: fix handle leak in Parser::Execute()

Fix a resource leak where an intermediate Local<Context> handle in
Environment::GetCurrent() got leaked into whatever HandleScope was
further up the stack.

Reviewed-by: Trevor Norris <trev.norris@gmail.com>
src: add ClearWrap() to util.h

Counterpart to Wrap(), clears the previously assigned internal field.
Will be used in an upcoming commit.

Reviewed-by: Trevor Norris <trev.norris@gmail.com>
lib, src: don't make http parser handles weak

Weak handles put strain on the garbage collector and the parser handle
doesn't need to be weak in the first place.  This change should improve
GC times on busy servers a little.

Reviewed-by: Trevor Norris <trev.norris@gmail.com>
src: update and expand comments in base-object.h

It's safe to call BaseObject::object() from your destructor _unless_
the handle is weak; then it's the weak callback that is calling your
destructor and the object will have been released by the time the
destructor runs.

Reviewed-by: Trevor Norris <trev.norris@gmail.com>
lib: http: poison parser references after freeing

Make it a little harder to slip in use-after-free bugs by nulling out
references to the parser object after handing it off to freeParser().

Reviewed-by: Trevor Norris <trev.norris@gmail.com>