Browse Source

added optional read nbytes.

Nicolas Cannasse 19 years ago
parent
commit
ff68980ad2
1 changed files with 11 additions and 2 deletions
  1. 11 2
      std/neko/Socket.hx

+ 11 - 2
std/neko/Socket.hx

@@ -61,8 +61,17 @@ class Socket {
 		socket_write(__s, untyped content.__s);
 	}
 
-	public function read() : String	{
-		return new String(socket_read(__s));
+	public function read( ?nbytes : Int ) : String	{
+		if( nbytes == null )
+			return new String(socket_read(__s));
+		var s = Lib.makeString(nbytes);
+		var p = 0;
+		while( nbytes > 0 ) {
+			var l = receive(s,p,nbytes);
+			p += l;
+			nbytes -= l;
+		}
+		return s;
 	}
 
 	public function connect(host : Host, port : Int) {