client-server communication test

This commit is contained in:
2025-07-22 15:32:32 +05:00
parent 1e41ab49e5
commit 94091d7797
4 changed files with 102 additions and 9 deletions

View File

@@ -44,3 +44,10 @@ Result(Socket) socket_accept(Socket main_socket) {
Socket user_connection = accept(main_socket, (struct sockaddr*)&remote_addr, (void*)&sockaddr_size);
return RESULT_VALUE(i64, user_connection);
}
Result(void) socket_connect(Socket s, EndpointIPv4 remote_end){
struct sockaddr_in sockaddr = EndpointIPv4_toSockaddr(remote_end);
if(connect(s, (void*)&sockaddr, sizeof(sockaddr)) != 0)
return RESULT_ERROR("connect() failed", false);
return RESULT_VOID;
}

View File

@@ -15,4 +15,5 @@ void socket_close(Socket s);
Result(void) socket_shutdown(Socket s, SocketShutdownType direction);
Result(void) socket_bind(Socket s, EndpointIPv4 local_end);
Result(void) socket_listen(Socket s, i32 backlog);
Result(Socket) socket_accept(Socket main_socket);
Result(Socket) socket_accept(Socket s);
Result(void) socket_connect(Socket s, EndpointIPv4 remote_end);