nitlanguage
/
nit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge: Binary over network
[nit.git]
/
lib
/
socket
/
socket_c.nit
diff --git
a/lib/socket/socket_c.nit
b/lib/socket/socket_c.nit
index
a574485
..
fbf2923
100644
(file)
--- a/
lib/socket/socket_c.nit
+++ b/
lib/socket/socket_c.nit
@@
-134,19
+134,18
@@
extern class NativeSocket `{ int* `}
# Write `value` as a single byte
fun write_byte(value: Int): Int `{
# Write `value` as a single byte
fun write_byte(value: Int): Int `{
- return write(*recv, &value, 1);
+ unsigned char byt = (unsigned char)value;
+ return write(*recv, &byt, 1);
`}
`}
- fun read: String import NativeString.to_s_with_length `{
+ fun read: String import NativeString.to_s_with_length, NativeString.to_s_with_copy `{
static char c[1024];
static char c[1024];
- int n = read(*recv, c, 1024);
+ int n = read(*recv, c, 1023);
if(n < 0) {
return NativeString_to_s_with_length("",0);
}
if(n < 0) {
return NativeString_to_s_with_length("",0);
}
- char* ret = malloc(n + 1);
- memcpy(ret, c, n);
- ret[n] = '\0';
- return NativeString_to_s_with_length(ret, n);
+ c[n] = 0;
+ return NativeString_to_s_with_copy(c);
`}
# Sets an option for the socket
`}
# Sets an option for the socket