Skip to content

Commit

Permalink
Changes after code review
Browse files Browse the repository at this point in the history
Returning -1 instead of 0 from start_server function
  • Loading branch information
italo-sampaio committed Jan 17, 2025
1 parent f0cafca commit 355ff20
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions firmware/src/sgx/src/untrusted/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,27 @@ 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));

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
Expand All @@ -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");
Expand All @@ -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() {
Expand Down

0 comments on commit 355ff20

Please sign in to comment.