daniel has submitted this change. ( 
https://gerrit.osmocom.org/c/libosmo-abis/+/30616 )

Change subject: ipa: Add ipa_client_conn_open2 with connect timeout argument
......................................................................

ipa: Add ipa_client_conn_open2 with connect timeout argument

Related: SYS#6237
Change-Id: Iaeb672a4c981e9769443fb0cd6c8e59cb76307bd
---
M TODO-RELEASE
M include/osmocom/abis/ipa.h
M src/input/ipa.c
3 files changed, 38 insertions(+), 4 deletions(-)

Approvals:
  Jenkins Builder: Verified
  osmith: Looks good to me, but someone else must approve
  daniel: Looks good to me, approved



diff --git a/TODO-RELEASE b/TODO-RELEASE
index d0852fc..5456ba8 100644
--- a/TODO-RELEASE
+++ b/TODO-RELEASE
@@ -7,3 +7,4 @@
 # If any interfaces have been added since the last public release: c:r:a + 1.
 # If any interfaces have been removed or changed since the last public 
release: c:r:0.
 #library       what            description / commit summary line
+libosmo-abis   ipa_client_conn_open2 New API added
diff --git a/include/osmocom/abis/ipa.h b/include/osmocom/abis/ipa.h
index 7e13a6d..0a36d78 100644
--- a/include/osmocom/abis/ipa.h
+++ b/include/osmocom/abis/ipa.h
@@ -105,6 +105,7 @@
 void ipa_client_conn_destroy(struct ipa_client_conn *link);

 int ipa_client_conn_open(struct ipa_client_conn *link);
+int ipa_client_conn_open2(struct ipa_client_conn *link, unsigned int 
connect_timeout);
 void ipa_client_conn_close(struct ipa_client_conn *link);

 void ipa_client_conn_send(struct ipa_client_conn *link, struct msgb *msg);
diff --git a/src/input/ipa.c b/src/input/ipa.c
index c121987..62b21e5 100644
--- a/src/input/ipa.c
+++ b/src/input/ipa.c
@@ -12,6 +12,7 @@
 #include <arpa/inet.h>

 #include <osmocom/core/select.h>
+#include <osmocom/core/timer.h>
 #include <osmocom/gsm/tlv.h>
 #include <osmocom/core/msgb.h>
 #include <osmocom/core/logging.h>
@@ -37,6 +38,8 @@

 void ipa_client_conn_close(struct ipa_client_conn *link)
 {
+       osmo_timer_del(&link->timer);
+
        /* be safe against multiple calls */
        if (link->ofd->fd != -1) {
                osmo_fd_unregister(link->ofd);
@@ -109,6 +112,13 @@
        return 0;
 }

+static void ipa_connect_failure(struct ipa_client_conn *link)
+{
+       ipa_client_conn_close(link);
+       if (link->updown_cb)
+               link->updown_cb(link, 0);
+}
+
 static int ipa_client_fd_cb(struct osmo_fd *ofd, unsigned int what)
 {
        struct ipa_client_conn *link = ofd->data;
@@ -119,11 +129,14 @@
        case IPA_CLIENT_LINK_STATE_CONNECTING:
                ret = getsockopt(ofd->fd, SOL_SOCKET, SO_ERROR, &error, &len);
                if (ret >= 0 && error > 0) {
-                       ipa_client_conn_close(link);
-                       if (link->updown_cb)
-                               link->updown_cb(link, 0);
+                       ipa_connect_failure(link);
                        return 0;
                }
+
+               /* Stop the timer when connection succeeds, on failure it's 
deleted in
+                  ipa_client_conn_close() called by ipa_connect_failure() 
above */
+               osmo_timer_del(&link->timer);
+
                osmo_fd_write_disable(ofd);
                LOGIPA(link, LOGL_NOTICE, "connection done\n");
                link->state = IPA_CLIENT_LINK_STATE_CONNECTED;
@@ -143,7 +156,16 @@
        default:
                break;
        }
-        return 0;
+       return 0;
+}
+
+/* Treat the connect timeout exactly like a connect failure */
+static void ipa_connect_timeout_cb(void *data)
+{
+       struct ipa_client_conn *link = (struct ipa_client_conn *)data;
+
+       LOGIPA(link, LOGL_NOTICE, "Connect timeout reached\n");
+       ipa_connect_failure(link);
 }

 struct ipa_client_conn *
@@ -197,6 +219,8 @@
        ipa_link->port = rem_port;
        ipa_link->updown_cb = updown_cb;
        ipa_link->read_cb = read_cb;
+       osmo_timer_setup(&ipa_link->timer, ipa_connect_timeout_cb, ipa_link);
+
        /* default to generic write callback if not set. */
        if (write_cb == NULL)
                ipa_link->write_cb = ipa_client_write_default_cb;
@@ -218,6 +242,11 @@

 int ipa_client_conn_open(struct ipa_client_conn *link)
 {
+       return ipa_client_conn_open2(link, 30);
+}
+
+int ipa_client_conn_open2(struct ipa_client_conn *link, unsigned int 
connect_timeout)
+{
        int ret;

        link->state = IPA_CLIENT_LINK_STATE_CONNECTING;
@@ -236,6 +265,9 @@
                return -EIO;
        }

+       if (connect_timeout > 0)
+               osmo_timer_schedule(&link->timer, connect_timeout, 0);
+
        return 0;
 }


--
To view, visit https://gerrit.osmocom.org/c/libosmo-abis/+/30616
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmo-abis
Gerrit-Branch: master
Gerrit-Change-Id: Iaeb672a4c981e9769443fb0cd6c8e59cb76307bd
Gerrit-Change-Number: 30616
Gerrit-PatchSet: 7
Gerrit-Owner: daniel <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <[email protected]>
Gerrit-Reviewer: dexter <[email protected]>
Gerrit-Reviewer: fixeria <[email protected]>
Gerrit-Reviewer: osmith <[email protected]>
Gerrit-Reviewer: pespin <[email protected]>
Gerrit-MessageType: merged

Reply via email to