mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.4 KiB
61 lines
1.4 KiB
10 years ago
|
'use strict';
|
||
14 years ago
|
var common = require('../common');
|
||
|
var assert = require('assert');
|
||
|
var TCP = process.binding('tcp_wrap').TCP;
|
||
10 years ago
|
var TCPConnectWrap = process.binding('tcp_wrap').TCPConnectWrap;
|
||
|
var ShutdownWrap = process.binding('stream_wrap').ShutdownWrap;
|
||
14 years ago
|
|
||
|
function makeConnection() {
|
||
|
var client = new TCP();
|
||
|
|
||
10 years ago
|
var req = new TCPConnectWrap();
|
||
12 years ago
|
var err = client.connect(req, '127.0.0.1', common.PORT);
|
||
|
assert.equal(err, 0);
|
||
|
|
||
14 years ago
|
req.oncomplete = function(status, client_, req_) {
|
||
|
assert.equal(0, status);
|
||
|
assert.equal(client, client_);
|
||
|
assert.equal(req, req_);
|
||
|
|
||
13 years ago
|
console.log('connected');
|
||
10 years ago
|
var shutdownReq = new ShutdownWrap();
|
||
12 years ago
|
var err = client.shutdown(shutdownReq);
|
||
|
assert.equal(err, 0);
|
||
|
|
||
14 years ago
|
shutdownReq.oncomplete = function(status, client_, req_) {
|
||
13 years ago
|
console.log('shutdown complete');
|
||
14 years ago
|
assert.equal(0, status);
|
||
|
assert.equal(client, client_);
|
||
|
assert.equal(shutdownReq, req_);
|
||
|
shutdownCount++;
|
||
|
client.close();
|
||
|
};
|
||
14 years ago
|
};
|
||
|
}
|
||
|
|
||
|
/////
|
||
|
|
||
|
var connectCount = 0;
|
||
|
var endCount = 0;
|
||
14 years ago
|
var shutdownCount = 0;
|
||
14 years ago
|
|
||
|
var server = require('net').Server(function(s) {
|
||
13 years ago
|
console.log('got connection');
|
||
14 years ago
|
connectCount++;
|
||
12 years ago
|
s.resume();
|
||
14 years ago
|
s.on('end', function() {
|
||
13 years ago
|
console.log('got eof');
|
||
14 years ago
|
endCount++;
|
||
|
s.destroy();
|
||
|
server.close();
|
||
|
});
|
||
|
});
|
||
|
|
||
|
server.listen(common.PORT, makeConnection);
|
||
|
|
||
|
process.on('exit', function() {
|
||
14 years ago
|
assert.equal(1, shutdownCount);
|
||
14 years ago
|
assert.equal(1, connectCount);
|
||
|
assert.equal(1, endCount);
|
||
|
});
|