浏览代码

neko.net package.

Nicolas Cannasse 19 年之前
父节点
当前提交
7e6c13b401

+ 4 - 6
std/haxe/Http.hx

@@ -25,11 +25,9 @@
 package haxe;
 package haxe;
 
 
 #if neko
 #if neko
-import neko.io.Socket.Host;
-
 private typedef AbstractSocket = {
 private typedef AbstractSocket = {
 	var input(default,null) : neko.io.Input;
 	var input(default,null) : neko.io.Input;
-	function connect( host : Host, port : Int ) : Void;	
+	function connect( host : neko.net.Host, port : Int ) : Void;
 	function setTimeout( t : Float ) : Void;
 	function setTimeout( t : Float ) : Void;
 	function write( str : String ) : Void;
 	function write( str : String ) : Void;
 	function close() : Void;
 	function close() : Void;
@@ -226,7 +224,7 @@ class Http {
 			return;
 			return;
 		}
 		}
 		if( sock == null )
 		if( sock == null )
-			sock = new neko.io.Socket();
+			sock = new neko.net.Socket();
 		var host = url_regexp.matched(2);
 		var host = url_regexp.matched(2);
 		var portString = url_regexp.matched(3);
 		var portString = url_regexp.matched(3);
 		var request = url_regexp.matched(4);
 		var request = url_regexp.matched(4);
@@ -277,7 +275,7 @@ class Http {
 				b.add(uri);
 				b.add(uri);
 		}
 		}
 		try {
 		try {
-			sock.connect(neko.io.Socket.resolve(host),port);
+			sock.connect(new neko.net.Host(host),port);
 			sock.write(b.toString());
 			sock.write(b.toString());
 			readHttpResponse(api,sock);
 			readHttpResponse(api,sock);
 			sock.close();
 			sock.close();
@@ -374,7 +372,7 @@ class Http {
 			responseHeaders.set(hname,hval);
 			responseHeaders.set(hname,hval);
 			if( hname.toLowerCase() == "content-length" )
 			if( hname.toLowerCase() == "content-length" )
 				size = Std.parseInt(hval);
 				size = Std.parseInt(hval);
-		}		
+		}
 		var chunked = responseHeaders.get("Transfer-Encoding") == "chunked";
 		var chunked = responseHeaders.get("Transfer-Encoding") == "chunked";
 		var chunk_re = ~/^([0-9A-Fa-f]+)[ ]*\r\n/m;
 		var chunk_re = ~/^([0-9A-Fa-f]+)[ ]*\r\n/m;
 		chunk_size = null;
 		chunk_size = null;

+ 8 - 9
std/haxe/ImportAll.hx

@@ -63,12 +63,7 @@ import haxe.remoting.DelayedConnection;
 import haxe.remoting.LocalConnection;
 import haxe.remoting.LocalConnection;
 #end
 #end
 import haxe.remoting.Proxy;
 import haxe.remoting.Proxy;
-#if neko
-import haxe.remoting.Server;
-import haxe.remoting.SocketBuffer;
-#end
-#if js
-#else true
+#if !js
 import haxe.remoting.SocketConnection;
 import haxe.remoting.SocketConnection;
 #end
 #end
 
 
@@ -513,9 +508,6 @@ import neko.io.Input;
 import neko.io.Logger;
 import neko.io.Logger;
 import neko.io.Multiple;
 import neko.io.Multiple;
 import neko.io.Output;
 import neko.io.Output;
-import neko.io.Socket;
-import neko.io.SocketInput;
-import neko.io.SocketOutput;
 import neko.io.StringInput;
 import neko.io.StringInput;
 import neko.io.StringOutput;
 import neko.io.StringOutput;
 
 
@@ -532,6 +524,13 @@ import neko.db.ResultSet;
 import neko.db.Sqlite;
 import neko.db.Sqlite;
 import neko.db.Transaction;
 import neko.db.Transaction;
 
 
+import neko.net.Host;
+import neko.net.RemotingServer;
+import neko.net.RemotingBuffer;
+import neko.net.Socket;
+import neko.net.SocketInput;
+import neko.net.SocketOutput;
+
 #end
 #end
 
 
 #if js
 #if js

+ 2 - 2
std/haxe/remoting/SocketConnection.hx

@@ -125,7 +125,7 @@ class SocketConnection extends AsyncConnection {
 			throw "Message is too big";
 			throw "Message is too big";
 		var c2 = encodeChar(len&63);
 		var c2 = encodeChar(len&63);
 		#if neko
 		#if neko
-		var s : neko.io.Socket = __data;
+		var s : neko.net.Socket = __data;
 		s.output.writeChar(c1);
 		s.output.writeChar(c1);
 		s.output.writeChar(c2);
 		s.output.writeChar(c2);
 		s.output.write(msg);
 		s.output.write(msg);
@@ -202,7 +202,7 @@ class SocketConnection extends AsyncConnection {
 
 
 	#if neko
 	#if neko
 
 
-	public static function socketConnect( s : neko.io.Socket, r : Server ) {
+	public static function socketConnect( s : neko.net.Socket, r : Server ) {
 		var sc = new SocketConnection(s,[]);
 		var sc = new SocketConnection(s,[]);
 		sc.__funs = new List();
 		sc.__funs = new List();
 		sc.__r = r;
 		sc.__r = r;

+ 56 - 0
std/neko/net/Host.hx

@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2005, The haXe Project Contributors
+ * All rights reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   - Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   - Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ *
+ */
+package neko.net;
+
+enum HostHandle {
+}
+
+class Host {
+
+	public var __h : HostHandle;
+
+	public function new( name : String ) {
+		__h = host_resolve(untyped name.__s);
+	}
+
+	public function toString() : String {
+		return new String(host_to_string(__h));
+	}
+
+	public function reverse() {
+		return new String(host_reverse(__h));
+	}
+
+	public static function localhost() : String {
+		return new String(host_local());
+	}
+
+	private static var host_resolve = neko.Lib.load("std","host_resolve",1);
+	private static var host_reverse = neko.Lib.load("std","host_reverse",1);
+	private static var host_to_string = neko.Lib.load("std","host_to_string",1);
+	private static var host_local = neko.Lib.load("std","host_local",0);
+
+}

+ 161 - 0
std/neko/net/RemotingBuffer.hx

@@ -0,0 +1,161 @@
+/*
+ * Copyright (c) 2005, The haXe Project Contributors
+ * All rights reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   - Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   - Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ */
+package neko.net;
+
+enum RemotingError {
+	ReadError;
+	InvalidMessage;
+}
+
+class RemotingBuffer {
+
+	public static var START_SIZE = 256;
+	public static var MAX_SIZE = 4096;
+
+	var buffer : String;
+	var bufpos : Int;
+	var lastpos : Int;
+	var msglen : Int;
+	var sock : neko.net.Socket;
+	var lastread : Float;
+
+	public function new(s) {
+		sock = s;
+		bufpos = 0;
+		lastpos = 0;
+		lastread = neko.Sys.time();
+		buffer = neko.Lib.makeString(START_SIZE);
+	}
+
+	public function lastRead() {
+		return lastread;
+	}
+
+	public function bufferData() {
+	    return buffer.substr(lastpos,bufpos - lastpos);
+	}
+
+	public function onData( data : String ) {
+	}
+
+	public function onXmlData( data : String ) {
+	}
+
+	public function read() {
+		var buflen = buffer.length;
+		var len = try sock.input.readBytes(buffer,bufpos,buflen-bufpos) catch( e : Dynamic ) { if( e == neko.io.Error.Blocked ) return; 0; };
+		if( len == 0 )
+			throw ReadError;
+		lastread = neko.Sys.time();
+		bufpos += len;
+		while( process(len) ) {
+		}
+		if( bufpos == buflen ) {
+			// copy/expand buffer
+			if( lastpos != 0 ) {
+				var bytes = bufpos-lastpos;
+				neko.Lib.copyBytes(buffer,0,buffer,lastpos,bytes);
+				lastpos = 0;
+				bufpos = bytes;
+			} else {
+				if( buflen * 2 > MAX_SIZE )
+					throw InvalidMessage; // can only happens for Xml messages
+				var b2 = neko.Lib.makeString(buflen * 2);
+				neko.Lib.copyBytes(b2,0,buffer,0,bufpos);
+				buffer = b2;
+			}
+		}
+	}
+
+	function decodeMessageLength() {
+		// message starting with < : XML
+		if( buffer.charCodeAt(lastpos) == 60 )
+			return -1;
+		var c1 = decodeChar(buffer.charCodeAt(lastpos));
+		var c2 = decodeChar(buffer.charCodeAt(lastpos+1));
+		if( c1 == null || c2 == null )
+			throw InvalidMessage;
+		return (c1 << 6) | c2;
+	}
+
+	function decodeChar(c) {
+		// A...Z
+		if( c >= 65 && c <= 90 )
+			return c - 65;
+		// a...z
+		if( c >= 97 && c <= 122 )
+			return c - 97 + 26;
+		// 0...9
+		if( c >= 48 && c <= 57 )
+			return c - 48 + 52;
+		// +
+		if( c == 43 )
+			return 62;
+		// /
+		if( c == 47 )
+			return 63;
+		return null;
+	}
+
+	function process( nbytes ) {
+		var av_bytes = bufpos - lastpos;
+		if( av_bytes < 2 )
+			return false;
+		if( msglen == null )
+			msglen = decodeMessageLength();
+		var isxml = false;
+		if( msglen == -1 ) {
+			// wait for \0
+			var i = nbytes;
+			while( i > 0 ) {
+				if( buffer.charCodeAt(bufpos - i) == 0 )
+					break;
+				i -= 1;
+			}
+			if( i == 0 )
+				return false;
+			msglen = av_bytes - i;
+			isxml = true;
+		} else {
+			if( av_bytes < msglen )
+				return false;
+			lastpos += 2;
+			msglen -= 3;
+		}
+		var msg = buffer.substr(lastpos,msglen);
+		lastpos += msglen + 1;
+		msglen = null;
+		if( lastpos == bufpos ) {
+			lastpos = 0;
+			bufpos = 0;
+		}
+		if( isxml )
+			onXmlData(msg);
+		else
+			onData(msg);
+		return true;
+	}
+
+}

+ 100 - 0
std/neko/net/RemotingServer.hx

@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2005, The haXe Project Contributors
+ * All rights reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   - Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   - Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ */
+package neko.net;
+
+class RemotingServer {
+
+	var objects : Hash<Dynamic>;
+	var prefix : String;
+	var log : String -> Void;
+
+	public function new() {
+		objects = new Hash();
+		log = null;
+	}
+
+	public function addObject( name : String, obj : Dynamic ) {
+		objects.set(name,obj);
+	}
+
+	public function setLogger( l ) {
+		log = l;
+	}
+
+	public function setPrivatePrefix( p : String ) {
+		prefix = p;
+	}
+
+	public function resolvePath( path : Array<String> ) : Dynamic {
+		var objname = path.shift();
+		if( objname == null )
+			throw "Empty path";
+		var obj = objects.get(objname);
+		if( obj == null )
+			throw "Object '"+objname+"' is not accessible";
+		for( x in path ) {
+			if( obj == null || (prefix != null && x.indexOf(prefix,0) == 0) )
+				return null;
+			obj = Reflect.field(obj,x);
+		}
+		return obj;
+	}
+
+	public function handleRequest() {
+		if( neko.Web.getClientHeader("X-Haxe-Remoting") == null && neko.Web.getClientHeader("x-haxe-remoting") == null )
+			return false;
+		var v = neko.Web.getParams().get("__x");
+		try {
+			if( v == null )
+				throw "Missing remoting data";
+			var u = new haxe.Unserializer(v);
+			var path : Array<String> = u.unserialize();
+			var args : Array<Dynamic> = u.unserialize();
+			var f = path.pop();
+			var obj = resolvePath(path);
+			var funptr = Reflect.field(obj,f);
+			if( !Reflect.isFunction(funptr) )
+				throw "Calling not-a-function '"+f+"'";
+			var v = Reflect.callMethod(obj,funptr,args);
+			var s = new haxe.Serializer();
+			s.serialize(v);
+			neko.Lib.print("hxr");
+			neko.Lib.print(s.toString());
+		} catch( e : Dynamic ) {
+			if( log != null ) {
+				log(haxe.Stack.toString(haxe.Stack.exceptionStack()));
+				log(Std.string(e));
+				log("\n\n");
+			}
+			var s = new haxe.Serializer();
+			s.serializeException(e);
+			neko.Lib.print("hxr");
+			neko.Lib.print(s.toString());
+		}
+		return true;
+	}
+
+}
+

+ 4 - 28
std/neko/io/Socket.hx → std/neko/net/Socket.hx

@@ -1,4 +1,3 @@
-
 /*
 /*
  * Copyright (c) 2005, The haXe Project Contributors
  * Copyright (c) 2005, The haXe Project Contributors
  * All rights reserved.
  * All rights reserved.
@@ -25,14 +24,11 @@
  *
  *
  * Contributor: Lee McColl Sylvester
  * Contributor: Lee McColl Sylvester
  */
  */
-package neko.io;
+package neko.net;
 
 
 enum SocketHandle {
 enum SocketHandle {
 }
 }
 
 
-enum Host {
-}
-
 class Socket {
 class Socket {
 
 
 	private var __s : SocketHandle;
 	private var __s : SocketHandle;
@@ -65,10 +61,10 @@ class Socket {
 
 
 	public function connect(host : Host, port : Int) {
 	public function connect(host : Host, port : Int) {
 		try {
 		try {
-			socket_connect(__s, host, port);
+			socket_connect(__s, host.__h, port);
 		} catch( s : String ) {
 		} catch( s : String ) {
 			if( s == "std@socket_connect" )
 			if( s == "std@socket_connect" )
-				throw "Failed to connect on "+(try reverse(host) catch( e : Dynamic ) hostToString(host))+":"+port;
+				throw "Failed to connect on "+(try host.reverse() catch( e : Dynamic ) host.toString())+":"+port;
 			else
 			else
 				neko.Lib.rethrow(s);
 				neko.Lib.rethrow(s);
 		}
 		}
@@ -83,7 +79,7 @@ class Socket {
 	}
 	}
 
 
 	public function bind(host : Host, port : Int) {
 	public function bind(host : Host, port : Int) {
-		socket_bind(__s, host, port);
+		socket_bind(__s, host.__h, port);
 	}
 	}
 
 
 	public function accept() : Socket {
 	public function accept() : Socket {
@@ -151,22 +147,6 @@ class Socket {
 		};
 		};
 	}
 	}
 
 
-	public static function resolve(host : String) : Host {
-		return host_resolve(untyped host.__s);
-	}
-
-	public static function hostToString(host : Host) : String {
-		return new String(host_to_string(host));
-	}
-
-	public static function reverse( host : Host ) : String {
-		return new String(host_reverse(host));
-	}
-
-	public static function localhost() : String {
-		return new String(host_local());
-	}
-
 	static function __init__() {
 	static function __init__() {
 		neko.Lib.load("std","socket_init",0)();
 		neko.Lib.load("std","socket_init",0)();
 	}
 	}
@@ -175,10 +155,6 @@ class Socket {
 	private static var socket_close = neko.Lib.load("std","socket_close",1);
 	private static var socket_close = neko.Lib.load("std","socket_close",1);
 	private static var socket_write = neko.Lib.load("std","socket_write",2);
 	private static var socket_write = neko.Lib.load("std","socket_write",2);
 	private static var socket_read = neko.Lib.load("std","socket_read",1);
 	private static var socket_read = neko.Lib.load("std","socket_read",1);
-	private static var host_resolve = neko.Lib.load("std","host_resolve",1);
-	private static var host_reverse = neko.Lib.load("std","host_reverse",1);
-	private static var host_to_string = neko.Lib.load("std","host_to_string",1);
-	private static var host_local = neko.Lib.load("std","host_local",0);
 	private static var socket_connect = neko.Lib.load("std","socket_connect",3);
 	private static var socket_connect = neko.Lib.load("std","socket_connect",3);
 	private static var socket_listen = neko.Lib.load("std","socket_listen",2);
 	private static var socket_listen = neko.Lib.load("std","socket_listen",2);
 	private static var socket_select = neko.Lib.load("std","socket_select",4);
 	private static var socket_select = neko.Lib.load("std","socket_select",4);

+ 10 - 9
std/neko/io/SocketInput.hx → std/neko/net/SocketInput.hx

@@ -22,10 +22,11 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  * DAMAGE.
  * DAMAGE.
  */
  */
-package neko.io;
-import neko.io.Socket;
+package neko.net;
+import neko.net.Socket;
+import neko.io.Error;
 
 
-class SocketInput extends Input {
+class SocketInput extends neko.io.Input {
 
 
 	var __s : SocketHandle;
 	var __s : SocketHandle;
 
 
@@ -38,11 +39,11 @@ class SocketInput extends Input {
 			socket_recv_char(__s);
 			socket_recv_char(__s);
 		} catch( e : Dynamic ) {
 		} catch( e : Dynamic ) {
 			if( e == "Blocking" )
 			if( e == "Blocking" )
-				throw Error.Blocked;
+				throw Blocked;
 			else if( __s == null )
 			else if( __s == null )
-				throw Error.Custom(e);
+				throw Custom(e);
 			else
 			else
-				throw new Eof();
+				throw new neko.io.Eof();
 		}
 		}
 	}
 	}
 
 
@@ -52,12 +53,12 @@ class SocketInput extends Input {
 			r = socket_recv(__s,untyped buf.__s,pos,len);
 			r = socket_recv(__s,untyped buf.__s,pos,len);
 		} catch( e : Dynamic ) {
 		} catch( e : Dynamic ) {
 			if( e == "Blocking" )
 			if( e == "Blocking" )
-				throw Error.Blocked;
+				throw Blocked;
 			else
 			else
-				throw Error.Custom(e);
+				throw Custom(e);
 		}
 		}
 		if( r == 0 )
 		if( r == 0 )
-			throw new Eof();
+			throw new neko.io.Eof();
 		return r;
 		return r;
 	}
 	}
 
 

+ 8 - 7
std/neko/io/SocketOutput.hx → std/neko/net/SocketOutput.hx

@@ -22,10 +22,11 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  * DAMAGE.
  * DAMAGE.
  */
  */
-package neko.io;
-import neko.io.Socket;
+package neko.net;
+import neko.net.Socket;
+import neko.io.Error;
 
 
-class SocketOutput extends Output {
+class SocketOutput extends neko.io.Output {
 
 
 	var __s : SocketHandle;
 	var __s : SocketHandle;
 
 
@@ -38,9 +39,9 @@ class SocketOutput extends Output {
 			socket_send_char(__s, c);
 			socket_send_char(__s, c);
 		} catch( e : Dynamic ) {
 		} catch( e : Dynamic ) {
 			if( e == "Blocking" )
 			if( e == "Blocking" )
-				throw Error.Blocked;
+				throw Blocked;
 			else
 			else
-				throw Error.Custom(e);
+				throw Custom(e);
 		}
 		}
 	}
 	}
 
 
@@ -49,9 +50,9 @@ class SocketOutput extends Output {
 			socket_send(__s, untyped buf.__s, pos, len);
 			socket_send(__s, untyped buf.__s, pos, len);
 		} catch( e : Dynamic ) {
 		} catch( e : Dynamic ) {
 			if( e == "Blocking" )
 			if( e == "Blocking" )
-				throw Error.Blocked;
+				throw Blocked;
 			else
 			else
-				throw Error.Custom(e);
+				throw Custom(e);
 		}
 		}
 	}
 	}
 
 

+ 6 - 6
std/tools/haxelib/Main.hx

@@ -109,10 +109,10 @@ class Main {
 		}
 		}
 		return neko.io.File.stdin().readLine();
 		return neko.io.File.stdin().readLine();
 	}
 	}
-	
+
 	function ask( question ) {
 	function ask( question ) {
 		while( true ) {
 		while( true ) {
-			neko.Lib.print(question+" [y/n/a] ? ");			
+			neko.Lib.print(question+" [y/n/a] ? ");
 			switch( neko.io.File.stdin().readLine() ) {
 			switch( neko.io.File.stdin().readLine() ) {
 			case "n": return No;
 			case "n": return No;
 			case "y": return Yes;
 			case "y": return Yes;
@@ -266,8 +266,8 @@ class Main {
 
 
 		// directly send the file data over Http
 		// directly send the file data over Http
 		// we can't use haxe.Http because we want *sent* data progress
 		// we can't use haxe.Http because we want *sent* data progress
-		var s = new neko.io.Socket();
-		s.connect(neko.io.Socket.resolve(SERVER.host),SERVER.port);
+		var s = new neko.net.Socket();
+		s.connect(new neko.net.Host(SERVER.host),SERVER.port);
 		s.write("POST /"+SERVER.url+"?submit="+id);
 		s.write("POST /"+SERVER.url+"?submit="+id);
 		s.write(" HTTP/1.1\r\nHost: "+SERVER.host+"\r\n");
 		s.write(" HTTP/1.1\r\nHost: "+SERVER.host+"\r\n");
 		s.write("Content-Type: application/octet-stream\r\n");
 		s.write("Content-Type: application/octet-stream\r\n");
@@ -508,7 +508,7 @@ class Main {
 					case Yes:
 					case Yes:
 					case Always: prompt = false;
 					case Always: prompt = false;
 					case No: continue;
 					case No: continue;
-					}				
+					}
 				doInstall(p,inf.curversion,true);
 				doInstall(p,inf.curversion,true);
 				update = true;
 				update = true;
 			} else
 			} else
@@ -561,7 +561,7 @@ class Main {
 		var version = param("Version");
 		var version = param("Version");
 		setCurrent(prj,version,false);
 		setCurrent(prj,version,false);
 	}
 	}
-	
+
 	function setCurrent( prj : String, version : String, doAsk : Bool ) {
 	function setCurrent( prj : String, version : String, doAsk : Bool ) {
 		var pdir = getRepository() + Datas.safe(prj);
 		var pdir = getRepository() + Datas.safe(prj);
 		var vdir = pdir + "/" + Datas.safe(version);
 		var vdir = pdir + "/" + Datas.safe(version);