@@ -42,9 +42,7 @@ var server = net.createServer(function(connection) {
42
42
} ) ;
43
43
44
44
server . listen ( common . PORT , function ( ) {
45
- for ( var i = 0 ; i < N ; i ++ ) {
46
- makeConnection ( i ) ;
47
- }
45
+ makeConnection ( 0 ) ;
48
46
} ) ;
49
47
50
48
server . maxConnections = N / 2 ;
@@ -53,50 +51,54 @@ console.error('server.maxConnections = %d', server.maxConnections);
53
51
54
52
55
53
function makeConnection ( index ) {
56
- setTimeout ( function ( ) {
57
- var c = net . createConnection ( common . PORT ) ;
58
- var gotData = false ;
59
-
60
- c . on ( 'end' , function ( ) { c . end ( ) ; } ) ;
61
-
62
- c . on ( 'data' , function ( b ) {
63
- gotData = true ;
64
- assert . ok ( 0 < b . length ) ;
65
- } ) ;
66
-
67
- c . on ( 'error' , function ( e ) {
68
- console . error ( 'error %d: %s' , index , e ) ;
69
- } ) ;
70
-
71
- c . on ( 'close' , function ( ) {
72
- console . error ( 'closed %d' , index ) ;
73
- closes ++ ;
74
-
75
- if ( closes < N / 2 ) {
76
- assert . ok ( server . maxConnections <= index ,
77
- index +
78
- ' was one of the first closed connections ' +
79
- 'but shouldnt have been' ) ;
54
+ var c = net . createConnection ( common . PORT ) ;
55
+ var gotData = false ;
56
+
57
+ c . on ( 'connect' , function ( ) {
58
+ if ( index + 1 < N ) {
59
+ makeConnection ( index + 1 ) ;
60
+ }
61
+ } ) ;
62
+
63
+ c . on ( 'end' , function ( ) { c . end ( ) ; } ) ;
64
+
65
+ c . on ( 'data' , function ( b ) {
66
+ gotData = true ;
67
+ assert . ok ( 0 < b . length ) ;
68
+ } ) ;
69
+
70
+ c . on ( 'error' , function ( e ) {
71
+ console . error ( 'error %d: %s' , index , e ) ;
72
+ } ) ;
73
+
74
+ c . on ( 'close' , function ( ) {
75
+ console . error ( 'closed %d' , index ) ;
76
+ closes ++ ;
77
+
78
+ if ( closes < N / 2 ) {
79
+ assert . ok ( server . maxConnections <= index ,
80
+ index +
81
+ ' was one of the first closed connections ' +
82
+ 'but shouldnt have been' ) ;
83
+ }
84
+
85
+ if ( closes === N / 2 ) {
86
+ var cb ;
87
+ console . error ( 'calling wait callback.' ) ;
88
+ while ( cb = waits . shift ( ) ) {
89
+ cb ( ) ;
80
90
}
81
-
82
- if ( closes === N / 2 ) {
83
- var cb ;
84
- console . error ( 'calling wait callback.' ) ;
85
- while ( cb = waits . shift ( ) ) {
86
- cb ( ) ;
87
- }
88
- server . close ( ) ;
89
- }
90
-
91
- if ( index < server . maxConnections ) {
92
- assert . equal ( true , gotData ,
93
- index + ' didn\'t get data, but should have' ) ;
94
- } else {
95
- assert . equal ( false , gotData ,
96
- index + ' got data, but shouldn\'t have' ) ;
97
- }
98
- } ) ;
99
- } , index ) ;
91
+ server . close ( ) ;
92
+ }
93
+
94
+ if ( index < server . maxConnections ) {
95
+ assert . equal ( true , gotData ,
96
+ index + ' didn\'t get data, but should have' ) ;
97
+ } else {
98
+ assert . equal ( false , gotData ,
99
+ index + ' got data, but shouldn\'t have' ) ;
100
+ }
101
+ } ) ;
100
102
}
101
103
102
104
0 commit comments