Browse Source

hl_ abstract prefixes

Nicolas Cannasse 9 years ago
parent
commit
ad4a896df1

+ 1 - 1
std/hl/_std/sys/io/File.hx

@@ -21,7 +21,7 @@
  */
 package sys.io;
 
-typedef FileHandle = hl.types.NativeAbstract<"fd">;
+typedef FileHandle = hl.types.NativeAbstract<"hl_fdesc">;
 
 @:access(String)
 @:coreApi class File {

+ 1 - 1
std/hl/_std/sys/io/Process.hx

@@ -21,7 +21,7 @@
  */
 package sys.io;
 
-private typedef ProcessHandle = hl.types.NativeAbstract<"process">;
+private typedef ProcessHandle = hl.types.NativeAbstract<"hl_process">;
 
 private class Stdin extends haxe.io.Output {
 

+ 3 - 1
std/hl/_std/sys/net/Host.hx

@@ -29,8 +29,10 @@ class Host {
 	public var ip(default,null) : Int;
 
 	public function new( name : String ) : Void {
+		var size = 0;
 		host = name;
-		ip = host_resolve(@:privateAccess name.bytes);
+		ip = host_resolve(@:privateAccess name.bytes.utf16ToUtf8(0,size));
+		if( ip == -1 ) throw new Sys.SysError("Unresolved host " + name);
 	}
 
 	public function toString() : String {

+ 10 - 2
std/hl/_std/sys/net/Socket.hx

@@ -22,7 +22,7 @@
 package sys.net;
 import haxe.io.Error;
 
-private typedef SocketHandle = hl.types.NativeAbstract<"socket">;
+private typedef SocketHandle = hl.types.NativeAbstract<"hl_socket">;
 
 private class SocketOutput extends haxe.io.Output {
 
@@ -41,6 +41,7 @@ private class SocketOutput extends haxe.io.Output {
 	}
 
 	public override function writeBytes( buf : haxe.io.Bytes, pos : Int, len : Int) : Int {
+		if( pos < 0 || len < 0 || pos + len > buf.length ) throw haxe.io.Error.OutsideBounds;
 		var n = socket_send(@:privateAccess sock.__s, buf.getData().b, pos, len);
 		if( n < 0 ) {
 			if( n == -1 ) throw Blocked;
@@ -77,6 +78,7 @@ private class SocketInput extends haxe.io.Input {
 	}
 
 	public override function readBytes( buf : haxe.io.Bytes, pos : Int, len : Int ) : Int {
+		if( pos < 0 || len < 0 || pos + len > buf.length ) throw haxe.io.Error.OutsideBounds;
 		var r = socket_recv(@:privateAccess sock.__s,buf.getData().b,pos,len);
 		if( r < 0 ) {
 			if( r == -1 ) throw Blocked;
@@ -95,6 +97,7 @@ private class SocketInput extends haxe.io.Input {
 }
 
 @:coreApi
+@:keepInit
 class Socket {
 
 	private var __s : SocketHandle;
@@ -102,6 +105,10 @@ class Socket {
 	public var output(default,null) : haxe.io.Output;
 	public var custom : Dynamic;
 
+	static function __init__() : Void {
+		socket_init();
+	}
+
 	public function new() : Void {
 		if( __s == null ) __s = socket_new(false);
 		input = new SocketInput(this);
@@ -192,7 +199,8 @@ class Socket {
 		throw new Sys.SysError("Not implemented");
 	}
 
-	@:hlNative("std","socket_new") static function socket_new( udp : Bool ) : SocketHandle { return null; }
+	@:hlNative("std", "socket_init") static function socket_init() : Void {}
+	@:hlNative("std", "socket_new") static function socket_new( udp : Bool ) : SocketHandle { return null; }
 	@:hlNative("std", "socket_close") static function socket_close( s : SocketHandle ) : Void { }
 	@:hlNative("std", "socket_connect") static function socket_connect( s : SocketHandle, host : Int, port : Int ) : Bool { return true; }
 	@:hlNative("std", "socket_listen") static function socket_listen( s : SocketHandle, count : Int ) : Bool { return true; }