Harald Welte has submitted this change and it was merged.

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


socket.c: osmo_sock_init2: connect: Several logic fixes and log improvements

See explanations in previous commits.

Change-Id: Ib2f7577b9f498ae9d388ed1f79f6ca0ec6f09664
---
M src/socket.c
1 file changed, 17 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 2310d75..0e0aa24 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -242,7 +242,8 @@
        if (flags & OSMO_SOCK_F_CONNECT) {
                result = addrinfo_helper(family, type, proto, remote_host, 
remote_port, false);
                if (!result) {
-                       close(sfd);
+                       if (sfd >= 0)
+                               close(sfd);
                        return -EINVAL;
                }
 
@@ -260,16 +261,24 @@
                        }
 
                        rc = connect(sfd, rp->ai_addr, rp->ai_addrlen);
-                       if (rc != -1 || (rc == -1 && errno == EINPROGRESS))
-                               break;
-
-                       close(sfd);
-                       sfd = -1;
+                       if (rc != 0 && errno != EINPROGRESS) {
+                               LOGP(DLGLOBAL, LOGL_ERROR, "unable to connect 
socket: %s:%u: %s\n",
+                                       remote_host, remote_port, 
strerror(errno));
+                               /* We want to maintain the bind socket if bind 
was enabled */
+                               if (!(flags & OSMO_SOCK_F_BIND)) {
+                                       close(sfd);
+                                       sfd = -1;
+                               }
+                               continue;
+                       }
+                       break;
                }
                freeaddrinfo(result);
                if (rp == NULL) {
-                       LOGP(DLGLOBAL, LOGL_ERROR, "unable to connect socket: 
%s:%u: %s\n",
-                               remote_host, remote_port, strerror(errno));
+                       LOGP(DLGLOBAL, LOGL_ERROR, "no suitable remote addr 
found for: %s:%u\n",
+                               remote_host, remote_port);
+                       if (sfd >= 0)
+                               close(sfd);
                        return -ENODEV;
                }
        }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ib2f7577b9f498ae9d388ed1f79f6ca0ec6f09664
Gerrit-PatchSet: 2
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol <pes...@sysmocom.de>
Gerrit-Reviewer: Harald Welte <lafo...@gnumonks.org>
Gerrit-Reviewer: Jenkins Builder

Reply via email to