0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-25 08:19:38 +01:00
nodejs/test/fixtures/net-fd-passing-receiver.js

33 lines
806 B
JavaScript
Raw Normal View History

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