[MERGED] libosmocore[master]: socket.c: osmo_sock_init: Several logic fixes and log improv...

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Thu Apr 5 19:57:36 UTC 2018


Harald Welte has submitted this change and it was merged.

Change subject: socket.c: osmo_sock_init: Several logic fixes and log improvements
......................................................................


socket.c: osmo_sock_init: Several logic fixes and log improvements

See explanations in previous commit.

Change-Id: I4889e777d8627fdfb52c97ab3ab353b6ed34aab2
---
M src/socket.c
1 file changed, 16 insertions(+), 8 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/socket.c b/src/socket.c
index 0e0aa24..d96f664 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -339,8 +339,10 @@
 
 		if (flags & OSMO_SOCK_F_CONNECT) {
 			rc = connect(sfd, rp->ai_addr, rp->ai_addrlen);
-			if (rc != -1 || (rc == -1 && errno == EINPROGRESS))
-				break;
+			if (rc != 0 && errno != EINPROGRESS) {
+				close(sfd);
+				continue;
+			}
 		} else {
 			rc = setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR,
 							&on, sizeof(on));
@@ -349,18 +351,24 @@
 					"cannot setsockopt socket:"
 					" %s:%u: %s\n",
 					host, port, strerror(errno));
-				break;
+				close(sfd);
+				continue;
 			}
-			if (bind(sfd, rp->ai_addr, rp->ai_addrlen) != -1)
-				break;
+			if (bind(sfd, rp->ai_addr, rp->ai_addrlen) == -1) {
+				LOGP(DLGLOBAL, LOGL_ERROR, "unable to bind socket:"
+					"%s:%u: %s\n",
+					host, port, strerror(errno));
+				close(sfd);
+				continue;
+			}
 		}
-		close(sfd);
+		break;
 	}
 	freeaddrinfo(result);
 
 	if (rp == NULL) {
-		LOGP(DLGLOBAL, LOGL_ERROR, "unable to connect/bind socket: %s:%u: %s\n",
-			host, port, strerror(errno));
+		LOGP(DLGLOBAL, LOGL_ERROR, "no suitable addr found for: %s:%u\n",
+			host, port);
 		return -ENODEV;
 	}
 

-- 
To view, visit https://gerrit.osmocom.org/7649
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I4889e777d8627fdfb52c97ab3ab353b6ed34aab2
Gerrit-PatchSet: 2
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol <pespin at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder



More information about the gerrit-log mailing list