mirror of https://github.com/lukechilds/node.git
Oleg Efimov
14 years ago
committed by
Ryan Dahl
80 changed files with 975 additions and 878 deletions
@ -1,39 +1,39 @@ |
|||
var common = require('../common'); |
|||
var assert = require('assert'); |
|||
|
|||
var dns = require("dns"); |
|||
var dns = require('dns'); |
|||
|
|||
|
|||
// Try resolution without callback
|
|||
|
|||
dns.getHostByName('localhost', function (error, result) { |
|||
console.dir(result); |
|||
assert.deepEqual(['127.0.0.1'], result); |
|||
dns.getHostByName('localhost', function(error, result) { |
|||
console.dir(result); |
|||
assert.deepEqual(['127.0.0.1'], result); |
|||
}); |
|||
|
|||
dns.getHostByName('127.0.0.1', function (error, result) { |
|||
console.dir(result); |
|||
assert.deepEqual(['127.0.0.1'], result); |
|||
dns.getHostByName('127.0.0.1', function(error, result) { |
|||
console.dir(result); |
|||
assert.deepEqual(['127.0.0.1'], result); |
|||
}); |
|||
|
|||
dns.lookup(null, function (error, result, addressType) { |
|||
assert.equal(null, result); |
|||
assert.equal(4, addressType); |
|||
dns.lookup(null, function(error, result, addressType) { |
|||
assert.equal(null, result); |
|||
assert.equal(4, addressType); |
|||
}); |
|||
|
|||
dns.lookup('127.0.0.1', function (error, result, addressType) { |
|||
assert.equal('127.0.0.1', result); |
|||
assert.equal(4, addressType); |
|||
dns.lookup('127.0.0.1', function(error, result, addressType) { |
|||
assert.equal('127.0.0.1', result); |
|||
assert.equal(4, addressType); |
|||
}); |
|||
|
|||
dns.lookup('::1', function (error, result, addressType) { |
|||
assert.equal('::1', result); |
|||
assert.equal(6, addressType); |
|||
dns.lookup('::1', function(error, result, addressType) { |
|||
assert.equal('::1', result); |
|||
assert.equal(6, addressType); |
|||
}); |
|||
|
|||
dns.lookup('ipv6.google.com', function (error, result, addressType) { |
|||
if (error) throw error; |
|||
console.dir(arguments); |
|||
//assert.equal('string', typeof result);
|
|||
assert.equal(6, addressType); |
|||
dns.lookup('ipv6.google.com', function(error, result, addressType) { |
|||
if (error) throw error; |
|||
console.dir(arguments); |
|||
//assert.equal('string', typeof result);
|
|||
assert.equal(6, addressType); |
|||
}); |
|||
|
@ -1,18 +1,18 @@ |
|||
var common = require("../common"); |
|||
var common = require('../common'); |
|||
var assert = require('assert'); |
|||
|
|||
var spawn = require('child_process').spawn; |
|||
var child = spawn('/usr/bin/env', [], {env: {'HELLO' : 'WORLD'}}); |
|||
var child = spawn('/usr/bin/env', [], {env: {'HELLO': 'WORLD'}}); |
|||
|
|||
var response = ""; |
|||
var response = ''; |
|||
|
|||
child.stdout.setEncoding('utf8'); |
|||
|
|||
child.stdout.addListener("data", function (chunk) { |
|||
console.log("stdout: " + chunk); |
|||
child.stdout.addListener('data', function(chunk) { |
|||
console.log('stdout: ' + chunk); |
|||
response += chunk; |
|||
}); |
|||
|
|||
process.addListener('exit', function () { |
|||
assert.ok(response.indexOf('HELLO=WORLD') >= 0); |
|||
process.addListener('exit', function() { |
|||
assert.ok(response.indexOf('HELLO=WORLD') >= 0); |
|||
}); |
|||
|
@ -1,53 +1,57 @@ |
|||
var common = require('../common'); |
|||
var assert = require('assert'); |
|||
|
|||
var Buffer = require("buffer").Buffer, |
|||
fs = require("fs"), |
|||
dgram = require("dgram"), server, client, |
|||
var Buffer = require('buffer').Buffer, |
|||
fs = require('fs'), |
|||
dgram = require('dgram'), server, client, |
|||
server_port = 20989, |
|||
message_to_send = new Buffer("A message to send"), |
|||
message_to_send = new Buffer('A message to send'), |
|||
timer; |
|||
|
|||
server = dgram.createSocket("udp4"); |
|||
server.on("message", function (msg, rinfo) { |
|||
console.log("server got: " + msg + " from " + rinfo.address + ":" + rinfo.port); |
|||
assert.strictEqual(rinfo.address, "127.0.0.1"); |
|||
server = dgram.createSocket('udp4'); |
|||
server.on('message', function(msg, rinfo) { |
|||
console.log('server got: ' + msg + |
|||
' from ' + rinfo.address + ':' + rinfo.port); |
|||
assert.strictEqual(rinfo.address, '127.0.0.1'); |
|||
assert.strictEqual(msg.toString(), message_to_send.toString()); |
|||
server.send(msg, 0, msg.length, rinfo.port, rinfo.address); |
|||
}); |
|||
server.on("listening", function () { |
|||
server.on('listening', function() { |
|||
var address = server.address(); |
|||
console.log("server is listening on " + address.address + ":" + address.port); |
|||
client = dgram.createSocket("udp4"); |
|||
client.on("message", function (msg, rinfo) { |
|||
console.log("client got: " + msg + " from " + rinfo.address + ":" + address.port); |
|||
assert.strictEqual(rinfo.address, "127.0.0.1"); |
|||
console.log('server is listening on ' + address.address + ':' + address.port); |
|||
client = dgram.createSocket('udp4'); |
|||
client.on('message', function(msg, rinfo) { |
|||
console.log('client got: ' + msg + |
|||
' from ' + rinfo.address + ':' + address.port); |
|||
assert.strictEqual(rinfo.address, '127.0.0.1'); |
|||
assert.strictEqual(rinfo.port, server_port); |
|||
assert.strictEqual(msg.toString(), message_to_send.toString()); |
|||
client.close(); |
|||
server.close(); |
|||
}); |
|||
client.send(message_to_send, 0, message_to_send.length, server_port, "localhost", function (err, bytes) { |
|||
if (err) { |
|||
console.log("Caught error in client send."); |
|||
throw err; |
|||
} |
|||
console.log("client wrote " + bytes + " bytes."); |
|||
assert.strictEqual(bytes, message_to_send.length); |
|||
}); |
|||
client.on("close", function () { |
|||
if (server.fd === null) { |
|||
clearTimeout(timer); |
|||
} |
|||
}); |
|||
client.send(message_to_send, 0, message_to_send.length, |
|||
server_port, 'localhost', function(err, bytes) { |
|||
if (err) { |
|||
console.log('Caught error in client send.'); |
|||
throw err; |
|||
} |
|||
console.log('client wrote ' + bytes + ' bytes.'); |
|||
assert.strictEqual(bytes, message_to_send.length); |
|||
}); |
|||
client.on('close', |
|||
function() { |
|||
if (server.fd === null) { |
|||
clearTimeout(timer); |
|||
} |
|||
}); |
|||
}); |
|||
server.on("close", function () { |
|||
server.on('close', function() { |
|||
if (client.fd === null) { |
|||
clearTimeout(timer); |
|||
} |
|||
}); |
|||
server.bind(server_port); |
|||
|
|||
timer = setTimeout(function () { |
|||
throw new Error("Timeout"); |
|||
timer = setTimeout(function() { |
|||
throw new Error('Timeout'); |
|||
}, 200); |
|||
|
@ -1,57 +1,57 @@ |
|||
var common = require('../common'); |
|||
var assert = require('assert'); |
|||
|
|||
var Buffer = require("buffer").Buffer, |
|||
fs = require("fs"), |
|||
dgram = require("dgram"), server, client, |
|||
server_path = "/tmp/dgram_server_sock", |
|||
var Buffer = require('buffer').Buffer, |
|||
fs = require('fs'), |
|||
dgram = require('dgram'), server, client, |
|||
server_path = '/tmp/dgram_server_sock', |
|||
messages_to_send = [ |
|||
new Buffer("First message to send"), |
|||
new Buffer("Second message to send"), |
|||
new Buffer("Third message to send"), |
|||
new Buffer("Fourth message to send") |
|||
new Buffer('First message to send'), |
|||
new Buffer('Second message to send'), |
|||
new Buffer('Third message to send'), |
|||
new Buffer('Fourth message to send') |
|||
], |
|||
timer; |
|||
|
|||
server = dgram.createSocket("unix_dgram"); |
|||
server = dgram.createSocket('unix_dgram'); |
|||
server.bind(server_path); |
|||
server.messages = []; |
|||
server.on("message", function (msg, rinfo) { |
|||
console.log("server got: " + msg); |
|||
assert.strictEqual(rinfo.address, ""); // anon client sending
|
|||
server.on('message', function(msg, rinfo) { |
|||
console.log('server got: ' + msg); |
|||
assert.strictEqual(rinfo.address, ''); // anon client sending
|
|||
server.messages.push(msg.toString()); |
|||
if (server.messages.length === messages_to_send.length) { |
|||
server.messages.forEach(function (m, i) { |
|||
server.messages.forEach(function(m, i) { |
|||
assert.strictEqual(m, messages_to_send[i].toString()); |
|||
}); |
|||
server.close(); |
|||
client.close(); |
|||
} |
|||
}); |
|||
server.on("listening", function () { |
|||
console.log("server is listening"); |
|||
client = dgram.createSocket("unix_dgram"); |
|||
messages_to_send.forEach(function (m) { |
|||
client.send(m, 0, m.length, server_path, function (err, bytes) { |
|||
server.on('listening', function() { |
|||
console.log('server is listening'); |
|||
client = dgram.createSocket('unix_dgram'); |
|||
messages_to_send.forEach(function(m) { |
|||
client.send(m, 0, m.length, server_path, function(err, bytes) { |
|||
if (err) { |
|||
console.log("Caught error in client send."); |
|||
console.log('Caught error in client send.'); |
|||
throw err; |
|||
} |
|||
console.log("client wrote " + bytes + " bytes."); |
|||
console.log('client wrote ' + bytes + ' bytes.'); |
|||
}); |
|||
}); |
|||
client.on("close", function () { |
|||
client.on('close', function() { |
|||
if (server.fd === null) { |
|||
clearTimeout(timer); |
|||
} |
|||
}); |
|||
}); |
|||
server.on("close", function () { |
|||
server.on('close', function() { |
|||
if (client.fd === null) { |
|||
clearTimeout(timer); |
|||
} |
|||
}); |
|||
|
|||
timer = setTimeout(function () { |
|||
throw new Error("Timeout"); |
|||
timer = setTimeout(function() { |
|||
throw new Error('Timeout'); |
|||
}, 500); |
|||
|
Loading…
Reference in new issue