From 337205eb0857668ee5dfa8497fc683e0079145f9 Mon Sep 17 00:00:00 2001 From: Nanquitas Date: Thu, 18 Jan 2018 22:57:46 +0100 Subject: [PATCH] sock_util: remove unneeded check We loop while (server_sockfd == -1) so it's safe to assume that (server_sockfd != -1) once out of the loop. --- sysmodules/rosalina/source/sock_util.c | 43 ++++++++++++-------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/sysmodules/rosalina/source/sock_util.c b/sysmodules/rosalina/source/sock_util.c index ad88b0e..2eb62a9 100644 --- a/sysmodules/rosalina/source/sock_util.c +++ b/sysmodules/rosalina/source/sock_util.c @@ -135,33 +135,30 @@ void server_bind(struct sock_server *serv, u16 port) server_sockfd = socSocket(AF_INET, SOCK_STREAM, 0); } - if(server_sockfd != -1) + struct sockaddr_in saddr; + saddr.sin_family = AF_INET; + saddr.sin_port = htons(port); + saddr.sin_addr.s_addr = gethostid(); + + res = socBind(server_sockfd, (struct sockaddr*)&saddr, sizeof(struct sockaddr_in)); + + if(res == 0) { - struct sockaddr_in saddr; - saddr.sin_family = AF_INET; - saddr.sin_port = htons(port); - saddr.sin_addr.s_addr = gethostid(); - - res = socBind(server_sockfd, (struct sockaddr*)&saddr, sizeof(struct sockaddr_in)); - + res = socListen(server_sockfd, 2); if(res == 0) { - res = socListen(server_sockfd, 2); - if(res == 0) - { - int idx = serv->nfds; - serv->nfds++; - serv->poll_fds[idx].fd = server_sockfd; - serv->poll_fds[idx].events = POLLIN; + int idx = serv->nfds; + serv->nfds++; + serv->poll_fds[idx].fd = server_sockfd; + serv->poll_fds[idx].events = POLLIN; - struct sock_ctx *new_ctx = server_alloc_server_ctx(serv); - memcpy(&new_ctx->addr_in, &saddr, sizeof(struct sockaddr_in)); - new_ctx->type = SOCK_SERVER; - new_ctx->sockfd = server_sockfd; - new_ctx->n = 0; - new_ctx->i = idx; - serv->ctx_ptrs[idx] = new_ctx; - } + struct sock_ctx *new_ctx = server_alloc_server_ctx(serv); + memcpy(&new_ctx->addr_in, &saddr, sizeof(struct sockaddr_in)); + new_ctx->type = SOCK_SERVER; + new_ctx->sockfd = server_sockfd; + new_ctx->n = 0; + new_ctx->i = idx; + serv->ctx_ptrs[idx] = new_ctx; } } }