- Added functions for working with sockets in libck tcc

git-svn-id: svn://kolibrios.org@8315 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
superturbocat2001
2020-12-03 17:27:05 +00:00
parent bc2c4a193e
commit 818c477d6f
8 changed files with 262 additions and 16 deletions
+15 -13
View File
@@ -1,19 +1,21 @@
all:
kos32-tcc asm_ex.c -lck -o asm_ex.kex -I ../libc/include
kos32-tcc consoleio.c -lck -o consoleio.kex -I ../libc/include
kos32-tcc files.c -lck -o files.kex -I ../libc/include
kos32-tcc winbasics.c -lck -o winbasics.kex -I ../libc/include
kos32-tcc dynamic.c -lck -lhttp -linputbox -o dynamic.kex -I ../libc/include
kos32-tcc load_coff.c -o load_coff.kex -lck -I ../libc/include
kos32-tcc clayer/msgbox.c -lck -lmsgbox -o clayer/msgbox.kex -I ../libc/include
kos32-tcc graphics.c -lck -lgb -o graphics.kex -I ../libc/include
kos32-tcc clayer/rasterworks.c -lck -lrasterworks -o clayer/rasterworks.kex -I ../libc/include
kos32-tcc clayer/boxlib.c -lck -lbox -o clayer/boxlib.kex -I ../libc/include
kos32-tcc clayer/libimg.c -lck -limg -o clayer/libimg.kex -I ../libc/include
kos32-tcc console/console.c -lck -limg -o console/console.kex -I ../libc/include
kos32-tcc dir_example.c -lck -o dir_example.kex -I ../libc/include
../bin/kos32-tcc asm_ex.c -lck -o asm_ex.kex -I ../libc/include
../bin/kos32-tcc consoleio.c -lck -o consoleio.kex -I ../libc/include
../bin/kos32-tcc files.c -lck -o files.kex -I ../libc/include
../bin/kos32-tcc winbasics.c -lck -o winbasics.kex -I ../libc/include
../bin/kos32-tcc dynamic.c -lck -lhttp -linputbox -o dynamic.kex -I ../libc/include
../bin/kos32-tcc load_coff.c -o load_coff.kex -lck -I ../libc/include
../bin/kos32-tcc clayer/msgbox.c -lck -lmsgbox -o clayer/msgbox.kex -I ../libc/include
../bin/kos32-tcc graphics.c -lck -lgb -o graphics.kex -I ../libc/include
../bin/kos32-tcc clayer/rasterworks.c -lck -lrasterworks -o clayer/rasterworks.kex -I ../libc/include
../bin/kos32-tcc clayer/boxlib.c -lck -lbox -o clayer/boxlib.kex -I ../libc/include
../bin/kos32-tcc clayer/libimg.c -lck -limg -o clayer/libimg.kex -I ../libc/include
../bin/kos32-tcc console/console.c -lck -limg -o console/console.kex -I ../libc/include
../bin/kos32-tcc dir_example.c -lck -o dir_example.kex -I ../libc/include
../bin/kos32-tcc net/tcpsrv_demo.c -lck -o net/tcpsrv_demo.kex -I ../libc/include
clean:
rm *.kex
rm clayer/*.kex
rm console/*.kex
rm net/*.kex
@@ -12,4 +12,5 @@
../tcc clayer/libimg.c -lck -limg -o /tmp0/1/libimg_ex
../tcc console/console.c -lck -limg -o /tmp0/1/console
../tcc dir_example.c -lck -o /tmp0/1/dir_example
../tcc net/tcpsrv_demo.c -lck -o /tmp0/1/tcpsrv_demo
exit
@@ -0,0 +1,36 @@
#include <net/socket.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
const char msg1[]="Hello!";
char msg2='\0';
int main()
{
sockaddr addr={AF_INET4, PORT(23) , 0, 0};
int sk1=socket(AF_INET4, SOCK_STREAM, IPPROTO_TCP);
printf("Open socket: %d. Error: %d\n",sk1, err_code);
bind(sk1, &addr,sizeof(addr));
printf("Socket binding. Error: %d\n", err_code);
listen(sk1, 1);
printf("Listening to a socket. Error: %d\n", err_code);
int sk2 = accept(sk1, &addr, sizeof(addr));
printf("Accept done. Error: %d\n", err_code);
send(sk2, msg1, strlen(msg1),MSG_NOFLAG);
printf("Send message: '%s' Error: %d\n", msg1, err_code);
puts("Received data:");
while(msg2!='!')
{
recv(sk2, &msg2, 1, MSG_NOFLAG);
printf("%c",msg2);
}
close(sk1);
close(sk2);
puts("\nGood bye!");
exit(0);
}