node/test/simple/test-net-can-reset-timeout.js

42 lines
834 B
JavaScript
Raw Normal View History

var net = require('net');
var common = require('../common');
var assert = require('assert');
var timeoutCount = 0;
2010-12-05 06:45:52 +08:00
var server = net.createServer(function(stream) {
stream.setTimeout(100);
2010-12-05 06:45:52 +08:00
stream.on('timeout', function() {
console.log('timeout');
// try to reset the timeout.
2010-12-05 06:45:52 +08:00
stream.write('WHAT.');
// don't worry, the socket didn't *really* time out, we're just thinking
// it did.
timeoutCount += 1;
});
2010-12-05 06:45:52 +08:00
stream.on('end', function() {
console.log('server side end');
stream.end();
});
});
server.listen(common.PORT, function() {
var c = net.createConnection(common.PORT);
2010-12-05 06:45:52 +08:00
c.on('data', function() {
c.end();
});
2010-12-05 06:45:52 +08:00
c.on('end', function() {
console.log('client side end');
server.close();
});
});
2010-12-05 06:45:52 +08:00
process.on('exit', function() {
assert.equal(1, timeoutCount);
});