浏览代码

close connection in clientDisconnected only.

Nicolas Cannasse 19 年之前
父节点
当前提交
b1faea5bdf
共有 1 个文件被更改,包括 8 次插入4 次删除
  1. 8 4
      std/neko/net/ThreadServer.hx

+ 8 - 4
std/neko/net/ThreadServer.hx

@@ -112,11 +112,10 @@ class ThreadServer<Client,Message> {
 				try {
 				try {
 					readClientData(infos);
 					readClientData(infos);
 				} catch( e : Dynamic ) {
 				} catch( e : Dynamic ) {
-					try s.close() catch( e : Dynamic ) { };
 					t.socks.remove(s);
 					t.socks.remove(s);
 					if( !Std.is(e,neko.io.Eof) && !Std.is(e,neko.io.Error) )
 					if( !Std.is(e,neko.io.Eof) && !Std.is(e,neko.io.Error) )
 						logError(e);
 						logError(e);
-					work(callback(clientDisconnected,infos.client));
+					work(callback(clientDisconnected,s,infos.client));
 				}
 				}
 			}
 			}
 		while( true ) {
 		while( true ) {
@@ -207,17 +206,22 @@ class ThreadServer<Client,Message> {
 		try {
 		try {
 			s.write(data);
 			s.write(data);
 		} catch( e : Dynamic ) {
 		} catch( e : Dynamic ) {
-			try s.close() catch( e : Dynamic ) { };
+			stopClient(s);
 		}
 		}
 	}
 	}
 
 
+	public function stopClient( s : neko.net.Socket ) {
+		try s.shutdown(true,true) catch( e : Dynamic ) { };
+	}
+
 	// --- CUSTOMIZABLE API ---
 	// --- CUSTOMIZABLE API ---
 
 
 	public function clientConnected( s : neko.net.Socket ) : Client {
 	public function clientConnected( s : neko.net.Socket ) : Client {
 		return null;
 		return null;
 	}
 	}
 
 
-	public function clientDisconnected( c : Client ) {
+	public function clientDisconnected( s : neko.net.Socket, c : Client ) {
+		try s.close() catch( e : Dynamic ) {};
 	}
 	}
 
 
 	public function readClientMessage( c : Client, buf : String, pos : Int, len : Int ) : { msg : Message, bytes : Int } {
 	public function readClientMessage( c : Client, buf : String, pos : Int, len : Int ) : { msg : Message, bytes : Int } {