Преглед на файлове

Add nonblocking connect support neko and cpp socket implementations.

Bryan Ischo преди 10 години
родител
ревизия
9a17cb67d8
променени са 2 файла, в които са добавени 24 реда и са изтрити 0 реда
  1. 12 0
      std/cpp/_std/sys/net/Socket.hx
  2. 12 0
      std/neko/_std/sys/net/Socket.hx

+ 12 - 0
std/cpp/_std/sys/net/Socket.hx

@@ -99,6 +99,8 @@ private class SocketOutput extends haxe.io.Output {
 		} catch( e : Dynamic ) {
 			if( e == "Blocking" )
 				throw Blocked;
+			else if (e == "EOF")
+				throw new haxe.io.Eof();
 			else
 				throw Custom(e);
 		}
@@ -158,6 +160,10 @@ class Socket {
 		} catch( s : String ) {
 			if( s == "std@socket_connect" )
 				throw "Failed to connect on "+host.toString()+":"+port;
+			else if (s == "Blocking") {
+				// Do nothing, this is not a real error, it simply indicates
+				// that a non-blocking connect is in progress
+			}
 			else
 				cpp.Lib.rethrow(s);
 		}
@@ -186,6 +192,9 @@ class Socket {
 
 	public function peer() : { host : Host, port : Int } {
 		var a : Dynamic = socket_peer(__s);
+		if (a == null) {
+			return null;
+		}
 		var h = new Host("127.0.0.1");
 		untyped h.ip = a[0];
 		return { host : h, port : a[1] };
@@ -193,6 +202,9 @@ class Socket {
 
 	public function host() : { host : Host, port : Int } {
 		var a : Dynamic = socket_host(__s);
+		if (a == null) {
+			return null;
+		}
 		var h = new Host("127.0.0.1");
 		untyped h.ip = a[0];
 		return { host : h, port : a[1] };

+ 12 - 0
std/neko/_std/sys/net/Socket.hx

@@ -39,6 +39,8 @@ private class SocketOutput extends haxe.io.Output {
 		} catch( e : Dynamic ) {
 			if( e == "Blocking" )
 				throw Blocked;
+			else if ( e == "EOF" )
+				throw new haxe.io.Eof();
 			else
 				throw Custom(e);
 		}
@@ -151,6 +153,10 @@ class Socket {
 		} catch( s : String ) {
 			if( s == "std@socket_connect" )
 				throw "Failed to connect on "+host.toString()+":"+port;
+			else if ( s == "Blocking" ) {
+				// Do nothing, this is not a real error, it simply indicates
+				// that a non-blocking connect is in progress
+			}
 			else
 				neko.Lib.rethrow(s);
 		}
@@ -179,6 +185,9 @@ class Socket {
 
 	public function peer() : { host : Host, port : Int } {
 		var a : Dynamic = socket_peer(__s);
+		if (a == null) {
+			return null;
+		}
 		var h = new Host("127.0.0.1");
 		untyped h.ip = a[0];
 		return { host : h, port : a[1] };
@@ -186,6 +195,9 @@ class Socket {
 
 	public function host() : { host : Host, port : Int } {
 		var a : Dynamic = socket_host(__s);
+		if (a == null) {
+			return null;
+		}
 		var h = new Host("127.0.0.1");
 		untyped h.ip = a[0];
 		return { host : h, port : a[1] };