1
1
'use strict' ;
2
- require ( '../common' ) ;
3
- var assert = require ( 'assert' ) ;
2
+ const common = require ( '../common' ) ;
3
+ const assert = require ( 'assert' ) ;
4
4
5
- var TCP = process . binding ( 'tcp_wrap' ) . TCP ;
6
- var WriteWrap = process . binding ( 'stream_wrap' ) . WriteWrap ;
5
+ const TCP = process . binding ( 'tcp_wrap' ) . TCP ;
6
+ const WriteWrap = process . binding ( 'stream_wrap' ) . WriteWrap ;
7
7
8
- var server = new TCP ( ) ;
8
+ const server = new TCP ( ) ;
9
9
10
- var r = server . bind ( '0.0.0.0' , 0 ) ;
11
- assert . equal ( 0 , r ) ;
12
- var port = { } ;
10
+ const r = server . bind ( '0.0.0.0' , 0 ) ;
11
+ assert . strictEqual ( 0 , r ) ;
12
+ let port = { } ;
13
13
server . getsockname ( port ) ;
14
14
port = port . port ;
15
15
16
16
server . listen ( 128 ) ;
17
17
18
- var sliceCount = 0 , eofCount = 0 ;
18
+ let sliceCount = 0 , eofCount = 0 ;
19
19
20
- var writeCount = 0 ;
21
- var recvCount = 0 ;
20
+ let writeCount = 0 ;
21
+ let recvCount = 0 ;
22
22
23
- server . onconnection = function ( err , client ) {
24
- assert . equal ( 0 , client . writeQueueSize ) ;
23
+ server . onconnection = ( err , client ) => {
24
+ assert . strictEqual ( 0 , client . writeQueueSize ) ;
25
25
console . log ( 'got connection' ) ;
26
26
27
- function maybeCloseClient ( ) {
28
- if ( client . pendingWrites . length == 0 && client . gotEOF ) {
27
+ const maybeCloseClient = ( ) => {
28
+ if ( client . pendingWrites . length === 0 && client . gotEOF ) {
29
29
console . log ( 'close client' ) ;
30
30
client . close ( ) ;
31
31
}
32
- }
32
+ } ;
33
33
34
34
client . readStart ( ) ;
35
35
client . pendingWrites = [ ] ;
36
- client . onread = function ( err , buffer ) {
36
+ client . onread = ( err , buffer ) => {
37
37
if ( buffer ) {
38
38
assert . ok ( buffer . length > 0 ) ;
39
39
40
- assert . equal ( 0 , client . writeQueueSize ) ;
40
+ assert . strictEqual ( 0 , client . writeQueueSize ) ;
41
41
42
- var req = new WriteWrap ( ) ;
42
+ const req = new WriteWrap ( ) ;
43
43
req . async = false ;
44
44
const returnCode = client . writeBuffer ( req , buffer ) ;
45
- assert . equal ( returnCode , 0 ) ;
45
+ assert . strictEqual ( returnCode , 0 ) ;
46
46
client . pendingWrites . push ( req ) ;
47
47
48
48
console . log ( 'client.writeQueueSize: ' + client . writeQueueSize ) ;
49
49
// 11 bytes should flush
50
- assert . equal ( 0 , client . writeQueueSize ) ;
50
+ assert . strictEqual ( 0 , client . writeQueueSize ) ;
51
51
52
52
if ( req . async )
53
53
req . oncomplete = done ;
54
54
else
55
55
process . nextTick ( done . bind ( null , 0 , client , req ) ) ;
56
56
57
57
function done ( status , client_ , req_ ) {
58
- assert . equal ( req , client . pendingWrites . shift ( ) ) ;
58
+ assert . strictEqual ( req , client . pendingWrites . shift ( ) ) ;
59
59
60
60
// Check parameters.
61
- assert . equal ( 0 , status ) ;
62
- assert . equal ( client , client_ ) ;
63
- assert . equal ( req , req_ ) ;
61
+ assert . strictEqual ( 0 , status ) ;
62
+ assert . strictEqual ( client , client_ ) ;
63
+ assert . strictEqual ( req , req_ ) ;
64
64
65
65
console . log ( 'client.writeQueueSize: ' + client . writeQueueSize ) ;
66
- assert . equal ( 0 , client . writeQueueSize ) ;
66
+ assert . strictEqual ( 0 , client . writeQueueSize ) ;
67
67
68
68
writeCount ++ ;
69
69
console . log ( 'write ' + writeCount ) ;
@@ -81,26 +81,25 @@ server.onconnection = function(err, client) {
81
81
} ;
82
82
} ;
83
83
84
- var net = require ( 'net' ) ;
84
+ const net = require ( 'net' ) ;
85
85
86
- var c = net . createConnection ( port ) ;
87
- c . on ( 'connect' , function ( ) {
88
- c . end ( 'hello world' ) ;
89
- } ) ;
86
+ const c = net . createConnection ( port ) ;
87
+
88
+ c . on ( 'connect' , common . mustCall ( ( ) => { c . end ( 'hello world' ) ; } ) ) ;
90
89
91
90
c . setEncoding ( 'utf8' ) ;
92
- c . on ( 'data' , function ( d ) {
93
- assert . equal ( 'hello world' , d ) ;
91
+ c . on ( 'data' , ( d ) => {
92
+ assert . strictEqual ( 'hello world' , d ) ;
94
93
recvCount ++ ;
95
94
} ) ;
96
95
97
- c . on ( 'close' , function ( ) {
96
+ c . on ( 'close' , ( ) => {
98
97
console . error ( 'client closed' ) ;
99
98
} ) ;
100
99
101
- process . on ( 'exit' , function ( ) {
102
- assert . equal ( 1 , sliceCount ) ;
103
- assert . equal ( 1 , eofCount ) ;
104
- assert . equal ( 1 , writeCount ) ;
105
- assert . equal ( 1 , recvCount ) ;
100
+ process . on ( 'exit' , ( ) => {
101
+ assert . strictEqual ( 1 , sliceCount ) ;
102
+ assert . strictEqual ( 1 , eofCount ) ;
103
+ assert . strictEqual ( 1 , writeCount ) ;
104
+ assert . strictEqual ( 1 , recvCount ) ;
106
105
} ) ;
0 commit comments