added send and recv builtins

This commit is contained in:
cozis
2021-12-04 21:02:50 +01:00
parent 57c0d7c910
commit 014287509a
5 changed files with 106 additions and 3 deletions
+18 -1
View File
@@ -22,6 +22,8 @@ if net.listen(fd, backlog) != 0:
return none;
}
buffer = newBuffer(16);
while true:
{
client_addr = {};
@@ -34,5 +36,20 @@ while true:
print('client_fd = ', client_fd, '\n');
print('client_addr = {', client_addr, '}\n');
# ..continue..
do
{
n = net.recv(client_fd, buffer, 0);
if n < 0:
print('Warning! Failed to read from socket!\n');
else if n == 0:
{
# Client disconnected.
}
else
{
print('Received ', n, ' bytes: ', buffer, '\n');
}
}
while n > 0;
}