Change in ...osmo-pcu[master]: osmobts_sock.cpp: pcu_sock_cb(): use libosmocore's socket API

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/.

fixeria gerrit-no-reply at lists.osmocom.org
Fri Aug 23 15:50:00 UTC 2019


fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-pcu/+/15278


Change subject: osmobts_sock.cpp: pcu_sock_cb(): use libosmocore's socket API
......................................................................

osmobts_sock.cpp: pcu_sock_cb(): use libosmocore's socket API

Change-Id: I7f5c7f5744ab14f36f46cf7941e91352eca8d2b9
---
M src/osmobts_sock.cpp
1 file changed, 9 insertions(+), 51 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-pcu refs/changes/78/15278/1

diff --git a/src/osmobts_sock.cpp b/src/osmobts_sock.cpp
index 6b49347..1072229 100644
--- a/src/osmobts_sock.cpp
+++ b/src/osmobts_sock.cpp
@@ -239,9 +239,6 @@
 int pcu_l1if_open(void)
 {
 	struct pcu_sock_state *state;
-	struct osmo_fd *bfd;
-	struct sockaddr_un local;
-	unsigned int namelen;
 	int rc;
 	struct gprs_rlcmac_bts *bts = bts_main_data();
 
@@ -255,60 +252,21 @@
 		INIT_LLIST_HEAD(&state->upqueue);
 	}
 
-	bfd = &state->conn_bfd;
-
-	bfd->fd = socket(AF_UNIX, SOCK_SEQPACKET, 0);
-	if (bfd->fd < 0) {
-		LOGP(DL1IF, LOGL_ERROR, "Failed to create PCU socket.\n");
-		talloc_free(state);
-		return -1;
-	}
-
-	local.sun_family = AF_UNIX;
-	if (osmo_strlcpy(local.sun_path, bts->pcu_sock_path, sizeof(local.sun_path)) >= sizeof(local.sun_path)) {
-		LOGP(DLGLOBAL, LOGL_ERROR, "Socket path exceeds maximum length of %zd bytes: %s\n",
-		     sizeof(local.sun_path), bts->pcu_sock_path);
-		return -ENOSPC;
-	}
-
-	/* we use the same magic that X11 uses in Xtranssock.c for
-	 * calculating the proper length of the sockaddr */
-#if defined(BSD44SOCKETS) || defined(__UNIXWARE__)
-	local.sun_len = strlen(local.sun_path);
-#endif
-#if defined(BSD44SOCKETS) || defined(SUN_LEN)
-	namelen = SUN_LEN(&local);
-#else
-	namelen = strlen(local.sun_path) +
-		  offsetof(struct sockaddr_un, sun_path);
-#endif
-	rc = connect(bfd->fd, (struct sockaddr *) &local, namelen);
-	if (rc != 0) {
-		LOGP(DL1IF, LOGL_ERROR, "Failed to connect to the osmo-bts"
-			" PCU socket (%s), delaying... '%s'\n",
-			strerror(errno), local.sun_path);
-		pcu_sock_state = state;
-		close(bfd->fd);
-		bfd->fd = -1;
+	rc = osmo_sock_unix_init_ofd(&state->conn_bfd, SOCK_SEQPACKET, 0,
+				     bts->pcu_sock_path, OSMO_SOCK_F_CONNECT);
+	if (rc < 0) {
+		LOGP(DL1IF, LOGL_ERROR, "Failed to connect to the BTS (%s). "
+					"Retrying...\n", bts->pcu_sock_path);
 		osmo_timer_setup(&state->timer, pcu_sock_timeout, NULL);
 		osmo_timer_schedule(&state->timer, 5, 0);
-		return 0;
+		return -EAGAIN;
 	}
 
-	bfd->when = BSC_FD_READ;
-	bfd->cb = pcu_sock_cb;
-	bfd->data = state;
-
-	rc = osmo_fd_register(bfd);
-	if (rc < 0) {
-		LOGP(DL1IF, LOGL_ERROR, "Could not register PCU fd: %d\n", rc);
-		close(bfd->fd);
-		talloc_free(state);
-		return rc;
-	}
+	state->conn_bfd.cb = pcu_sock_cb;
+	state->conn_bfd.data = state;
 
 	LOGP(DL1IF, LOGL_NOTICE, "osmo-bts PCU socket %s has been connected\n",
-	     local.sun_path);
+	     bts->pcu_sock_path);
 
 	pcu_sock_state = state;
 

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-pcu/+/15278
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-pcu
Gerrit-Branch: master
Gerrit-Change-Id: I7f5c7f5744ab14f36f46cf7941e91352eca8d2b9
Gerrit-Change-Number: 15278
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <axilirator at gmail.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190823/b5214292/attachment.htm>


More information about the gerrit-log mailing list