Browse Source

force socket removal on stopClient

Nicolas Cannasse 18 years ago
parent
commit
df9f20bf7f
1 changed files with 11 additions and 4 deletions
  1. 11 4
      std/neko/net/ThreadServer.hx

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

@@ -122,10 +122,15 @@ class ThreadServer<Client,Message> {
 				}
 				}
 			}
 			}
 		while( true ) {
 		while( true ) {
-			var s = neko.vm.Thread.readMessage(t.socks.length == 0);
-			if( s == null )
+			var m : { s : neko.net.Socket, cnx : Bool } = neko.vm.Thread.readMessage(t.socks.length == 0);
+			if( m == null )
 				break;
 				break;
-			t.socks.push(s);
+			if( m.cnx )
+				t.socks.push(m.s);
+			else if( t.socks.remove(m.s) ) {
+				var infos : ClientInfos<Client> = m.s.custom;
+				work(callback(doClientDisconnected,m.s,infos.client));
+			}
 		}
 		}
 	}
 	}
 
 
@@ -177,7 +182,7 @@ class ThreadServer<Client,Message> {
 			bufpos : 0,
 			bufpos : 0,
 		};
 		};
 		sock.custom = infos;
 		sock.custom = infos;
-		infos.thread.t.sendMessage(sock);
+		infos.thread.t.sendMessage({ s : sock, cnx : true });
 	}
 	}
 
 
 	function runTimer() {
 	function runTimer() {
@@ -231,7 +236,9 @@ class ThreadServer<Client,Message> {
 	}
 	}
 
 
 	public function stopClient( s : neko.net.Socket ) {
 	public function stopClient( s : neko.net.Socket ) {
+		var infos : ClientInfos<Client> = s.custom;
 		try s.shutdown(true,true) catch( e : Dynamic ) { };
 		try s.shutdown(true,true) catch( e : Dynamic ) { };
+		infos.thread.t.sendMessage({ s : s, cnx : false });
 	}
 	}
 
 
 	// --- CUSTOMIZABLE API ---
 	// --- CUSTOMIZABLE API ---