2010-12-05 00:20:34 +01:00
|
|
|
var common = require('../common');
|
|
|
|
var assert = require('assert');
|
|
|
|
var net = require('net');
|
|
|
|
var fs = require('fs');
|
|
|
|
var util = require('util');
|
|
|
|
var path = require('path');
|
2010-12-05 01:11:57 +01:00
|
|
|
var fn = path.join(common.fixturesDir, 'elipses.txt');
|
2010-05-29 02:52:59 +02:00
|
|
|
|
2010-12-05 01:11:57 +01:00
|
|
|
var expected = fs.readFileSync(fn, 'utf8');
|
2010-05-29 02:52:59 +02:00
|
|
|
|
2010-12-04 23:45:52 +01:00
|
|
|
var server = net.createServer(function(stream) {
|
2010-07-15 20:47:25 +02:00
|
|
|
common.error('pump!');
|
2010-12-04 23:45:52 +01:00
|
|
|
util.pump(fs.createReadStream(fn), stream, function() {
|
2010-07-15 20:47:25 +02:00
|
|
|
common.error('server stream close');
|
|
|
|
common.error('server close');
|
2010-05-29 02:52:59 +02:00
|
|
|
server.close();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2010-12-04 23:45:52 +01:00
|
|
|
server.listen(common.PORT, function() {
|
2010-12-05 01:11:57 +01:00
|
|
|
var conn = net.createConnection(common.PORT);
|
2010-05-29 02:52:59 +02:00
|
|
|
conn.setEncoding('utf8');
|
2010-12-04 23:45:52 +01:00
|
|
|
conn.addListener('data', function(chunk) {
|
2010-07-15 20:47:25 +02:00
|
|
|
common.error('recv data! nchars = ' + chunk.length);
|
2010-05-29 02:52:59 +02:00
|
|
|
buffer += chunk;
|
|
|
|
});
|
|
|
|
|
2010-12-04 23:45:52 +01:00
|
|
|
conn.addListener('end', function() {
|
2010-05-29 02:52:59 +02:00
|
|
|
conn.end();
|
|
|
|
});
|
2010-12-04 23:45:52 +01:00
|
|
|
conn.addListener('close', function() {
|
2010-07-15 20:47:25 +02:00
|
|
|
common.error('client connection close');
|
2010-05-29 02:52:59 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
var buffer = '';
|
2010-12-05 01:11:57 +01:00
|
|
|
var count = 0;
|
2010-05-29 02:52:59 +02:00
|
|
|
|
2010-12-04 23:45:52 +01:00
|
|
|
server.addListener('listening', function() {
|
2010-05-29 02:52:59 +02:00
|
|
|
});
|
|
|
|
|
2010-12-04 23:45:52 +01:00
|
|
|
process.addListener('exit', function() {
|
2010-05-29 02:52:59 +02:00
|
|
|
assert.equal(expected, buffer);
|
|
|
|
});
|