File tree 1 file changed +13
-6
lines changed
1 file changed +13
-6
lines changed Original file line number Diff line number Diff line change 21
21
22
22
'use strict' ;
23
23
const common = require ( '../common' ) ;
24
+
24
25
const net = require ( 'net' ) ;
25
26
27
+ let serverSocket ;
28
+
26
29
const server = net . createServer ( common . mustCall ( function ( socket ) {
30
+ serverSocket = socket ;
31
+
27
32
socket . resume ( ) ;
28
33
29
34
socket . on ( 'error' , common . mustCall ( function ( error ) {
30
- console . error ( 'got error, closing server' , error ) ;
35
+ console . error ( 'received error as expected , closing server' , error ) ;
31
36
server . close ( ) ;
32
37
} ) ) ;
33
-
34
- setTimeout ( common . mustCall ( function ( ) {
35
- console . error ( 'about to try to write' ) ;
36
- socket . write ( 'test' , common . mustCall ( ) ) ;
37
- } ) , 250 ) ;
38
38
} ) ) ;
39
39
40
40
server . listen ( 0 , function ( ) {
41
41
const client = net . connect ( this . address ( ) . port , function ( ) {
42
+ // cliend.end() will close both the readable and writable side
43
+ // of the duplex because allowHalfOpen defaults to false.
44
+ // Then 'end' will be emitted when it receives a FIN packet from
45
+ // the other side.
46
+ client . on ( 'end' , common . mustCall ( ( ) => {
47
+ serverSocket . write ( 'test' , common . mustCall ( ) ) ;
48
+ } ) ) ;
42
49
client . end ( ) ;
43
50
} ) ;
44
51
} ) ;
You can’t perform that action at this time.
0 commit comments