Change in libosmo-abis[master]: ipa: add optional connect timeout to ipa_client_conn_open

dexter gerrit-no-reply at lists.osmocom.org
Wed Jun 2 15:57:45 UTC 2021


dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmo-abis/+/24514 )


Change subject: ipa: add optional connect timeout to ipa_client_conn_open
......................................................................

ipa: add optional connect timeout to ipa_client_conn_open

The function ipa_client_conn_open opens an osmo-socket using
osmo_sock_init2 and sets the OSMO_SOCK_F_NONBLOCK. This means that it
returns while the TCP connection is still in progress and it is not
clear yet if the connection will succeed or not. In cases where an
established connection is critical the API user may specify a timeout in
the IPA line options. ipa_client_conn_open() will then wait until the
the connection is established (or failed).

Change-Id: I7bc4345876e3c20266985270d0ddfa770437a053
Related: SYS#4971
---
M TODO-RELEASE
M include/osmocom/abis/e1_input.h
M src/input/ipa.c
3 files changed, 15 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmo-abis refs/changes/14/24514/1

diff --git a/TODO-RELEASE b/TODO-RELEASE
index 8c417cd..e7a2891 100644
--- a/TODO-RELEASE
+++ b/TODO-RELEASE
@@ -10,3 +10,4 @@
 update libosmocore dependency to > 1.5.1 for OSMO_SOCK_F_{DSCP,PRIO}()
 libosmo-abis	new member	ipa_client_conn new struct members dscp, priority
 libosmo-abis	new member	ipa_server_link new struct members dscp, priority
+libosmo-abis	new member	e1inp_line_ops new struct member cfg.ipa.timeout_msec
diff --git a/include/osmocom/abis/e1_input.h b/include/osmocom/abis/e1_input.h
index 9c3fe56..ba5033f 100644
--- a/include/osmocom/abis/e1_input.h
+++ b/include/osmocom/abis/e1_input.h
@@ -181,6 +181,7 @@
 		struct {
 			enum e1inp_line_role role;	/* BSC or BTS mode. */
 			const char *addr;		/* IP address .*/
+			int timeout_msec;		/* connect timeout (optional, only valid in BTS mode) */
 			void *dev;			/* device parameters. */
 		} ipa;
 		struct {
diff --git a/src/input/ipa.c b/src/input/ipa.c
index c121987..298369a 100644
--- a/src/input/ipa.c
+++ b/src/input/ipa.c
@@ -10,6 +10,7 @@
 #include <sys/socket.h>
 #include <sys/ioctl.h>
 #include <arpa/inet.h>
+#include <netinet/tcp.h>
 
 #include <osmocom/core/select.h>
 #include <osmocom/gsm/tlv.h>
@@ -219,6 +220,7 @@
 int ipa_client_conn_open(struct ipa_client_conn *link)
 {
 	int ret;
+	int timeout_msec;
 
 	link->state = IPA_CLIENT_LINK_STATE_CONNECTING;
 	ret = osmo_sock_init2(AF_INET, SOCK_STREAM, IPPROTO_TCP,
@@ -228,6 +230,7 @@
 			     OSMO_SOCK_F_DSCP(link->dscp) | OSMO_SOCK_F_PRIO(link->priority));
 	if (ret < 0)
 		return ret;
+
 	link->ofd->fd = ret;
 	osmo_fd_write_enable(link->ofd);
 	if (osmo_fd_register(link->ofd) < 0) {
@@ -236,6 +239,16 @@
 		return -EIO;
 	}
 
+	/* If a connect timeout is specified we will wait until the file
+	 * descriptor becomes writeable (connection successful) or enters
+	 * an errornous state. */
+	timeout_msec = link->line->ops->cfg.ipa.timeout_msec;
+	if (timeout_msec) {
+		ret = osmo_sock_wait(link->ofd->fd, timeout_msec);
+		if (ret < 0)
+			return -EIO;
+	}
+
 	return 0;
 }
 

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

Gerrit-Project: libosmo-abis
Gerrit-Branch: master
Gerrit-Change-Id: I7bc4345876e3c20266985270d0ddfa770437a053
Gerrit-Change-Number: 24514
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210602/d7130f2a/attachment.htm>


More information about the gerrit-log mailing list