0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 23:43:09 +01:00
nodejs/test/fixtures/net-fd-passing-receiver.js
Herbert Vojčík cf2b206a8e More changes to tests so they really work under context module loader.
Plus, getting rid of test/common.js defining things in global.
2010-08-17 08:41:05 -07:00

33 lines
806 B
JavaScript

process.mixin(require("../common"));
net = require("net");
path = process.ARGV[2];
greeting = process.ARGV[3];
receiver = net.createServer(function(socket) {
socket.addListener("fd", function(fd) {
var peerInfo = process.getpeername(fd);
peerInfo.fd = fd;
var passedSocket = new net.Socket(peerInfo);
passedSocket.addListener("eof", function() {
passedSocket.close();
});
passedSocket.addListener("data", function(data) {
passedSocket.send("[echo] " + data);
});
passedSocket.addListener("close", function() {
receiver.close();
});
passedSocket.send("[greeting] " + greeting);
});
});
/* To signal the test runne we're up and listening */
receiver.addListener("listening", function() {
common.print("ready");
});
receiver.listen(path);