@ -1,53 +1,53 @@
'use strict' ;
'use strict' ;
require ( '../common' ) ;
const common = require ( '../common' ) ;
var assert = require ( 'assert' ) ;
const assert = require ( 'assert' ) ;
var TCP = process . binding ( 'tcp_wrap' ) . TCP ;
const TCP = process . binding ( 'tcp_wrap' ) . TCP ;
var WriteWrap = process . binding ( 'stream_wrap' ) . WriteWrap ;
const WriteWrap = process . binding ( 'stream_wrap' ) . WriteWrap ;
var server = new TCP ( ) ;
const server = new TCP ( ) ;
var r = server . bind ( '0.0.0.0' , 0 ) ;
const r = server . bind ( '0.0.0.0' , 0 ) ;
assert . e qual( 0 , r ) ;
assert . strictE qual( 0 , r ) ;
var port = { } ;
let port = { } ;
server . getsockname ( port ) ;
server . getsockname ( port ) ;
port = port . port ;
port = port . port ;
server . listen ( 128 ) ;
server . listen ( 128 ) ;
var sliceCount = 0 , eofCount = 0 ;
let sliceCount = 0 , eofCount = 0 ;
var writeCount = 0 ;
let writeCount = 0 ;
var recvCount = 0 ;
let recvCount = 0 ;
server . onconnection = function ( err , client ) {
server . onconnection = ( err , client ) => {
assert . e qual( 0 , client . writeQueueSize ) ;
assert . strictE qual( 0 , client . writeQueueSize ) ;
console . log ( 'got connection' ) ;
console . log ( 'got connection' ) ;
function maybeCloseClient ( ) {
const maybeCloseClient = ( ) => {
if ( client . pendingWrites . length == 0 && client . gotEOF ) {
if ( client . pendingWrites . length === 0 && client . gotEOF ) {
console . log ( 'close client' ) ;
console . log ( 'close client' ) ;
client . close ( ) ;
client . close ( ) ;
}
}
}
} ;
client . readStart ( ) ;
client . readStart ( ) ;
client . pendingWrites = [ ] ;
client . pendingWrites = [ ] ;
client . onread = function ( err , buffer ) {
client . onread = ( err , buffer ) => {
if ( buffer ) {
if ( buffer ) {
assert . ok ( buffer . length > 0 ) ;
assert . ok ( buffer . length > 0 ) ;
assert . e qual( 0 , client . writeQueueSize ) ;
assert . strictE qual( 0 , client . writeQueueSize ) ;
var req = new WriteWrap ( ) ;
const req = new WriteWrap ( ) ;
req . async = false ;
req . async = false ;
const returnCode = client . writeBuffer ( req , buffer ) ;
const returnCode = client . writeBuffer ( req , buffer ) ;
assert . e qual( returnCode , 0 ) ;
assert . strictE qual( returnCode , 0 ) ;
client . pendingWrites . push ( req ) ;
client . pendingWrites . push ( req ) ;
console . log ( 'client.writeQueueSize: ' + client . writeQueueSize ) ;
console . log ( 'client.writeQueueSize: ' + client . writeQueueSize ) ;
// 11 bytes should flush
// 11 bytes should flush
assert . e qual( 0 , client . writeQueueSize ) ;
assert . strictE qual( 0 , client . writeQueueSize ) ;
if ( req . async )
if ( req . async )
req . oncomplete = done ;
req . oncomplete = done ;
@ -55,15 +55,15 @@ server.onconnection = function(err, client) {
process . nextTick ( done . bind ( null , 0 , client , req ) ) ;
process . nextTick ( done . bind ( null , 0 , client , req ) ) ;
function done ( status , client_ , req_ ) {
function done ( status , client_ , req_ ) {
assert . e qual( req , client . pendingWrites . shift ( ) ) ;
assert . strictE qual( req , client . pendingWrites . shift ( ) ) ;
// Check parameters.
// Check parameters.
assert . e qual( 0 , status ) ;
assert . strictE qual( 0 , status ) ;
assert . e qual( client , client_ ) ;
assert . strictE qual( client , client_ ) ;
assert . e qual( req , req_ ) ;
assert . strictE qual( req , req_ ) ;
console . log ( 'client.writeQueueSize: ' + client . writeQueueSize ) ;
console . log ( 'client.writeQueueSize: ' + client . writeQueueSize ) ;
assert . e qual( 0 , client . writeQueueSize ) ;
assert . strictE qual( 0 , client . writeQueueSize ) ;
writeCount ++ ;
writeCount ++ ;
console . log ( 'write ' + writeCount ) ;
console . log ( 'write ' + writeCount ) ;
@ -81,26 +81,25 @@ server.onconnection = function(err, client) {
} ;
} ;
} ;
} ;
var net = require ( 'net' ) ;
const net = require ( 'net' ) ;
var c = net . createConnection ( port ) ;
const c = net . createConnection ( port ) ;
c . on ( 'connect' , function ( ) {
c . end ( 'hello world' ) ;
c . on ( 'connect' , common . mustCall ( ( ) => { c . end ( 'hello world' ) ; } ) ) ;
} ) ;
c . setEncoding ( 'utf8' ) ;
c . setEncoding ( 'utf8' ) ;
c . on ( 'data' , function ( d ) {
c . on ( 'data' , ( d ) => {
assert . e qual( 'hello world' , d ) ;
assert . strictE qual( 'hello world' , d ) ;
recvCount ++ ;
recvCount ++ ;
} ) ;
} ) ;
c . on ( 'close' , function ( ) {
c . on ( 'close' , ( ) => {
console . error ( 'client closed' ) ;
console . error ( 'client closed' ) ;
} ) ;
} ) ;
process . on ( 'exit' , function ( ) {
process . on ( 'exit' , ( ) => {
assert . e qual( 1 , sliceCount ) ;
assert . strictE qual( 1 , sliceCount ) ;
assert . e qual( 1 , eofCount ) ;
assert . strictE qual( 1 , eofCount ) ;
assert . e qual( 1 , writeCount ) ;
assert . strictE qual( 1 , writeCount ) ;
assert . e qual( 1 , recvCount ) ;
assert . strictE qual( 1 , recvCount ) ;
} ) ;
} ) ;