Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/v0.10'
Browse files Browse the repository at this point in the history
Conflicts:
	src/node_os.cc
  • Loading branch information
bnoordhuis committed Apr 18, 2013
2 parents 39dfe94 + 659fb23 commit 8e190bf
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 24 deletions.
6 changes: 4 additions & 2 deletions doc/api/http.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ per connection (in the case of keep-alive connections).
`function (socket) { }`

When a new TCP stream is established. `socket` is an object of type
`net.Socket`. Usually users will not want to access this event. The
`socket` can also be accessed at `request.connection`.
`net.Socket`. Usually users will not want to access this event. In
particular, the socket will not emit `readable` events because of how
the protocol parser attaches to the socket. The `socket` can also be
accessed at `request.connection`.

### Event: 'close'

Expand Down
4 changes: 2 additions & 2 deletions doc/api/path.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ Example:
'/foo/bar/baz/asdf'

path.join('foo', {}, 'bar')
// returns
'foo/bar'
// throws exception
TypeError: Arguments to path.join must be strings

## path.resolve([from ...], to)

Expand Down
1 change: 1 addition & 0 deletions lib/dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ Socket.prototype.bind = function(/*port, address, callback*/) {

var port = arguments[0];
var address = arguments[1];
if (typeof address === 'function') address = ''; // a.k.a. "any address"

// resolve address first
self._handle.lookup(address, function(err, ip) {
Expand Down
4 changes: 2 additions & 2 deletions src/handle_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Handle<Value> HandleWrap::Ref(const Arguments& args) {

UNWRAP_NO_ABORT(HandleWrap)

if (wrap) {
if (wrap != NULL && wrap->handle__ != NULL) {
uv_ref(wrap->handle__);
wrap->flags_ &= ~kUnref;
}
Expand All @@ -71,7 +71,7 @@ Handle<Value> HandleWrap::Unref(const Arguments& args) {

UNWRAP_NO_ABORT(HandleWrap)

if (wrap) {
if (wrap != NULL && wrap->handle__ != NULL) {
uv_unref(wrap->handle__);
wrap->flags_ |= kUnref;
}
Expand Down
3 changes: 2 additions & 1 deletion src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1986,7 +1986,8 @@ Handle<Value> Connection::GetNegotiatedProto(const Arguments& args) {
return False(node_isolate);
}

return String::New((const char*) npn_proto, npn_proto_len);
return scope.Close(String::New(reinterpret_cast<const char*>(npn_proto),
npn_proto_len));
} else {
return ss->selectedNPNProto_;
}
Expand Down
28 changes: 16 additions & 12 deletions src/node_os.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,17 @@
#endif

#ifdef __POSIX__
# include <unistd.h> // gethostname, sysconf
# include <netdb.h> // MAXHOSTNAMELEN on Solaris.
# include <unistd.h> // gethostname, sysconf
# include <sys/param.h> // MAXHOSTNAMELEN on Linux and the BSDs.
# include <sys/utsname.h>
#endif

// Add Windows fallback.
#ifndef MAXHOSTNAMELEN
# define MAXHOSTNAMELEN 256
#endif

namespace node {

using namespace v8;
Expand All @@ -51,32 +58,29 @@ static Handle<Value> GetEndianness(const Arguments& args) {

static Handle<Value> GetHostname(const Arguments& args) {
HandleScope scope(node_isolate);
char s[255];
int r = gethostname(s, 255);
char buf[MAXHOSTNAMELEN + 1];

if (r < 0) {
if (gethostname(buf, sizeof(buf))) {
#ifdef __POSIX__
return ThrowException(ErrnoException(errno, "gethostname"));
#else // __MINGW32__
return ThrowException(ErrnoException(WSAGetLastError(), "gethostname"));
#endif // __MINGW32__
}
buf[sizeof(buf) - 1] = '\0';

return scope.Close(String::New(s));
return scope.Close(String::New(buf));
}

static Handle<Value> GetOSType(const Arguments& args) {
HandleScope scope(node_isolate);

#ifdef __POSIX__
char type[256];
struct utsname info;

uname(&info);
strncpy(type, info.sysname, strlen(info.sysname));
type[strlen(info.sysname)] = 0;

return scope.Close(String::New(type));
if (uname(&info)) {
return ThrowException(ErrnoException(errno, "uname"));
}
return scope.Close(String::New(info.sysname));
#else // __MINGW32__
return scope.Close(String::New("Windows_NT"));
#endif
Expand Down
5 changes: 4 additions & 1 deletion test/simple/test-child-process-fork-exec-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ else {
fs.writeFileSync(copyPath, fs.readFileSync(nodePath));
fs.chmodSync(copyPath, '0755');

// slow but simple
var envCopy = JSON.parse(JSON.stringify(process.env));
envCopy.FORK = 'true';
var child = require('child_process').fork(__filename, {
execPath: copyPath,
env: { FORK: 'true' }
env: envCopy
});
child.on('message', common.mustCall(function(recv) {
assert.deepEqual(msg, recv);
Expand Down
36 changes: 36 additions & 0 deletions test/simple/test-dgram-bind-default-address.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

var common = require('../common');
var assert = require('assert');
var dgram = require('dgram');

dgram.createSocket('udp4').bind(common.PORT + 0, common.mustCall(function() {
assert.equal(this.address().port, common.PORT + 0);
assert.equal(this.address().address, '0.0.0.0');
this.close();
}));

dgram.createSocket('udp6').bind(common.PORT + 1, common.mustCall(function() {
assert.equal(this.address().port, common.PORT + 1);
assert.equal(this.address().address, '::');
this.close();
}));
12 changes: 8 additions & 4 deletions test/simple/test-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@
// being in the test folder
process.chdir(__dirname);

child.exec(process.execPath + ' test-init', {env: {'TEST_INIT': 1}},
// slow but simple
var envCopy = JSON.parse(JSON.stringify(process.env));
envCopy.TEST_INIT = 1;

child.exec(process.execPath + ' test-init', {env: envCopy},
function(err, stdout, stderr) {
assert.equal(stdout, 'Loaded successfully!',
'`node test-init` failed!');
});
child.exec(process.execPath + ' test-init.js', {env: {'TEST_INIT': 1}},
child.exec(process.execPath + ' test-init.js', {env: envCopy},
function(err, stdout, stderr) {
assert.equal(stdout, 'Loaded successfully!',
'`node test-init.js` failed!');
Expand All @@ -48,7 +52,7 @@
// test-init-index is in fixtures dir as requested by ry, so go there
process.chdir(common.fixturesDir);

child.exec(process.execPath + ' test-init-index', {env: {'TEST_INIT': 1}},
child.exec(process.execPath + ' test-init-index', {env: envCopy},
function(err, stdout, stderr) {
assert.equal(stdout, 'Loaded successfully!',
'`node test-init-index failed!');
Expand All @@ -59,7 +63,7 @@
// expected in node
process.chdir(common.fixturesDir + '/test-init-native/');

child.exec(process.execPath + ' fs', {env: {'TEST_INIT': 1}},
child.exec(process.execPath + ' fs', {env: envCopy},
function(err, stdout, stderr) {
assert.equal(stdout, 'fs loaded successfully',
'`node fs` failed!');
Expand Down
24 changes: 24 additions & 0 deletions test/simple/test-stdout-close-unref.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

process.stdin.resume();
process.stdin._handle.close();
process.stdin._handle.unref(); // Should not segfault.

0 comments on commit 8e190bf

Please sign in to comment.