Commits

Vincent Chinedu Okonkwo  committed 8539df4

cleanup error handling system

  • Participants
  • Parent commits 76843cc

Comments (0)

Files changed (3)

File hxuv/net/remoting/AsyncRemotingServer.hx

       onError(e, haxe.Stack.exceptionStack());
 	}
 
-    function socket_error(sock:StreamInterface, e:Int, emsg:String) {
-      if( e == 59 ) {
-         doClientDisconnected(sock, sock.custom.client);
-         return;
-      }
-      logError({"error": e, "info": emsg});
-    }
-
     function onClientDataReady(sock : StreamInterface, data:String) {
 
       var c:RClientInfo = sock.custom;
       clients.add(infos);
 
       sock.onDataReady = callback(onClientDataReady, sock);
-      sock.onError = callback(socket_error, sock);
 
       sock.custom = infos;
       sock.read(); // Start Receving Remoting Data
 		cnx.setErrorHandler(function(e) {
 			if( !Std.is(e,haxe.io.Eof) && !Std.is(e,haxe.io.Error) )
 				me.logError(e);
+
 			me.stopClient(s);
 		});
 		initClientApi(cnx,ctx);

File hxuv/net/remoting/AsyncSocketConnection.hx

 	}
 
     function onProtocolError(e:Int, emsg:String) {
-      __data.error(cast({"no":e, "info":emsg}, haxe.io.Error));
+
+      var eo:Dynamic;
+      if( e == 1 ) eo = new haxe.io.Eof();
+      else eo = haxe.io.Error.Custom({"no":e, "info":emsg});
+
+      __data.error(eo);
     }
 
 	public function resolve(name) : AsyncConnection {

File hxuv/net/remoting/AsyncSocketProtocol.hx

 		this.context = ctx;
 
         this.socket.onWriteComplete = callback(this.onSendMessageDone);
-        this.socket.onError = callback(this.onError);
+        this.socket.onError = callback(onSocketError);
 	}
 
+    function onSocketError(e:Int, em:String) {
+      this.onError(e,em);
+    }
+
 	function decodeChar(c) : Null<Int> {
 		// A...Z
 		if( c >= 65 && c <= 90 )
 	}
 
 
-    function onSocketData(out:haxe.io.BytesOutput, fn: Dynamic -> Void, msg:String ) {
+    function onSocketData(oldfunc:Dynamic, out:haxe.io.BytesOutput, fn: Dynamic -> Void, msg:String ) {
 
       out.writeString(msg);
 
       do {
 
 		if( len == null ) {
-          data = cast("Invalid message", haxe.io.Error);
+          data = haxe.io.Error.Custom("Invalid message");
           break;
         }
 
 
         data = i.readString(len - 3);
 		if( i.readByte() != 0 ) {
-          data = cast("Invalid message", haxe.io.Error);
+          data = haxe.io.Error.Custom("Invalid message");
           break;
         }
 
 
       } while(false);
 
-      socket.onDataReady = null;
+      socket.onDataReady = oldfunc;
 
       out.close();
       b = null; // free all this data
         if( socket.onDataReady != null ) return;
 
         var out = new haxe.io.BytesOutput();
-        socket.onDataReady = callback(onSocketData, out, fn);
+        var oldfunc = socket.onDataReady;
+        socket.onDataReady = callback(onSocketData, oldfunc, out, fn);
+        socket.read();
 	}
 
 }