From 355ff2037517908cb649b6ece03052d72efc7522 Mon Sep 17 00:00:00 2001 From: Italo Sampaio Date: Fri, 17 Jan 2025 08:51:15 -0300 Subject: [PATCH] Changes after code review Returning -1 instead of 0 from start_server function --- firmware/src/sgx/src/untrusted/io.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/firmware/src/sgx/src/untrusted/io.c b/firmware/src/sgx/src/untrusted/io.c index 8517eafa..deb02a78 100644 --- a/firmware/src/sgx/src/untrusted/io.c +++ b/firmware/src/sgx/src/untrusted/io.c @@ -57,14 +57,14 @@ static int start_server(int port, const char *host) { if (hostinfo == NULL) { LOG("Host not found.\n"); - return 0; + return -1; } // socket create and verification sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd == -1) { LOG("Socket creation failed...\n"); - return 0; + return -1; } explicit_bzero(&servaddr, sizeof(servaddr)); @@ -72,12 +72,12 @@ static int start_server(int port, const char *host) { if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &(int){1}, sizeof(int)) < 0) { LOG("Socket option setting failed failed\n"); - return 0; + return -1; } if (setsockopt(sockfd, SOL_TCP, TCP_NODELAY, &(int){1}, sizeof(int)) < 0) { LOG("Socket option setting failed failed\n"); - return 0; + return -1; } // Set address and port @@ -88,13 +88,13 @@ static int start_server(int port, const char *host) { // Binding newly created socket to given IP and verification if ((bind(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr))) != 0) { LOG("Socket bind failed...\n"); - return 0; + return -1; } // Now server is ready to listen and verification if ((listen(sockfd, 5)) != 0) { LOG("Listen failed...\n"); - return 0; + return -1; } LOG("Server listening...\n"); @@ -116,7 +116,7 @@ static bool accept_connection() { bool io_init(int port, const char *host) { connfd = -1; serverfd = start_server(port, host); - return serverfd; + return (serverfd != -1); } void io_finalise() {