Browse Source

Check some socket API values. Cpp changes for SocketProtocol

Hugh Sanderson 15 năm trước cách đây
mục cha
commit
446d4a9e31

+ 3 - 1
std/cpp/net/Socket.hx

@@ -119,8 +119,10 @@ class Socket {
 	}
 
 	// STATICS
-	public static function select(read : Array<Socket>, write : Array<Socket>, others : Array<Socket>, timeout : Float) : {read: Array<Socket>,write: Array<Socket>,others: Array<Socket>} {
+	public static function select(read : Array<Socket>, write : Array<Socket>, others : Array<Socket>, timeout : Null<Float>) : {read: Array<Socket>,write: Array<Socket>,others: Array<Socket>} {
 		var neko_array = socket_select(read,write,others, timeout);
+		if (neko_array==null)
+			throw "Select error";
 		return {
 			read: neko_array[0],
 			write: neko_array[1],

+ 2 - 0
std/cpp/net/SocketInput.hx

@@ -49,6 +49,8 @@ class SocketInput extends haxe.io.Input {
 
 	public override function readBytes( buf : haxe.io.Bytes, pos : Int, len : Int ) : Int {
 		var r;
+		if (__s==null)
+			throw "Invalid handle";
 		try {
 			r = socket_recv(__s,buf.getData(),pos,len);
 		} catch( e : Dynamic ) {

+ 2 - 0
std/cpp/net/SocketOutput.hx

@@ -35,6 +35,8 @@ class SocketOutput extends haxe.io.Output {
 	}
 
 	public override function writeByte( c : Int ) {
+		if (__s==null)
+			throw "Invalid handle";
 		try {
 			socket_send_char(__s, c);
 		} catch( e : Dynamic ) {

+ 4 - 2
std/haxe/remoting/SocketProtocol.hx

@@ -35,6 +35,8 @@ typedef Socket =
 		neko.net.Socket
 	#elseif php
 		php.net.Socket
+	#elseif cpp
+		cpp.net.Socket
 	#else
 		Dynamic
 	#end
@@ -139,7 +141,7 @@ class SocketProtocol {
 
 	public function sendMessage( msg : String ) {
 		var e = encodeMessageLength(msg.length + 3);
-		#if (neko || php)
+		#if (neko || php || cpp)
 		var o = socket.output;
 		o.writeByte(e.c1);
 		o.writeByte(e.c2);
@@ -191,7 +193,7 @@ class SocketProtocol {
 		return s.unserialize();
 	}
 
-	#if (neko || php)
+	#if (neko || php || cpp)
 
 	public function readMessage() {
 		var i = socket.input;