lib/socket: support reading string with null bytes
authorAlexis Laferrière <alexis.laf@xymus.net>
Fri, 29 May 2015 14:48:42 +0000 (10:48 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Fri, 29 May 2015 17:08:16 +0000 (13:08 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/socket/socket_c.nit

index ee6173e..d9056d6 100644 (file)
@@ -138,14 +138,14 @@ extern class NativeSocket `{ int* `}
                return write(*self, &byt, 1);
        `}
 
-       fun read: String import NativeString.to_s_with_length, NativeString.to_s_with_copy `{
-               static char c[1024];
+       fun read: String import NativeString.to_s_with_length, NativeString `{
+               char *c = new_NativeString(1024);
                int n = read(*self, c, 1023);
                if(n < 0) {
                        return NativeString_to_s_with_length("",0);
                }
                c[n] = 0;
-               return NativeString_to_s_with_copy(c);
+               return NativeString_to_s_with_length(c, n);
        `}
 
        # Sets an option for the socket