浏览代码

tested new/close client potential leak

ncannasse 6 年之前
父节点
当前提交
52f08dee30
共有 1 个文件被更改,包括 13 次插入4 次删除
  1. 13 4
      other/uvsample/UVSample.hx

+ 13 - 4
other/uvsample/UVSample.hx

@@ -48,6 +48,10 @@ class UVSample {
 			log("Client connected");
 			log("Client connected");
 			var s = tcp.accept();
 			var s = tcp.accept();
 			s.readStart(function(bytes) {
 			s.readStart(function(bytes) {
+				if( bytes == null ) {
+					s.close();
+					return;
+				}
 				totR += bytes.length;
 				totR += bytes.length;
 				// write back
 				// write back
 				s.write(bytes, function(b) if( !b ) throw "Write failure");
 				s.write(bytes, function(b) if( !b ) throw "Write failure");
@@ -60,9 +64,9 @@ class UVSample {
 
 
 			var numbers = [];
 			var numbers = [];
 			var client = new Tcp(loop);
 			var client = new Tcp(loop);
-			log("Connecting...");
+			//log("Connecting...");
 			client.connect(host, port, function(b) {
 			client.connect(host, port, function(b) {
-				log("Connected to server");
+				//log("Connected to server");
 
 
 
 
 				function send() {
 				function send() {
@@ -87,8 +91,13 @@ class UVSample {
 						if( !numbers.remove(k) )
 						if( !numbers.remove(k) )
 							throw "!";
 							throw "!";
 					}
 					}
-					if( numbers.length == 0 )
-						sendBatch();
+					if( numbers.length == 0 ) {					
+						if( Std.random(10000) == 0 ) {
+							startClient();
+							client.close();							
+						} else							
+							sendBatch();
+					}
 				});
 				});
 
 
 			});
 			});