socket.h (615B)
1 /* 2 * socket.h -- low-level socket defs 3 */ 4 5 #ifndef SOCKET_H 6 #define SOCKET_H 7 8 #include <stddef.h> 9 10 typedef struct socket { 11 int fd; 12 } Socket; 13 14 /* serving */ 15 int sock_create(const char* ip, int port); /* make a socket */ 16 int sock_accept(int fd); /* accept a connection from a client */ 17 void sock_close(int fd); /* close a server socket */ 18 19 /* client */ 20 int sock_connet(const char* ip, int port); /* connet to the server */ 21 22 /* i/o */ 23 int sock_send(int fd, const char* data, size_t len); /* send data to client */ 24 int sock_recv(int fd, char* buf, size_t len); /* recieve data from client */ 25 26 #endif /* SOCKET_H */ 27