[PATCH] libosmocore[master]: Expand and expose ctrl connection allocation

Max gerrit-no-reply at lists.osmocom.org
Thu Jan 19 14:43:03 UTC 2017


Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

    https://gerrit.osmocom.org/1629

to look at the new patch set (#2).

Expand and expose ctrl connection allocation

Add function for allocating CTRL connection to public headers and
replace call to previous static function with it.

Change-Id: I522ed809cbebfd3d7dd08b4ed9137b39ff192e32
---
M include/osmocom/ctrl/control_if.h
M src/ctrl/control_if.c
2 files changed, 38 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/29/1629/2

diff --git a/include/osmocom/ctrl/control_if.h b/include/osmocom/ctrl/control_if.h
index 512ae10..f2af1db 100644
--- a/include/osmocom/ctrl/control_if.h
+++ b/include/osmocom/ctrl/control_if.h
@@ -27,5 +27,5 @@
 					       const char *bind_addr,
 					       uint16_t port,
 					       ctrl_cmd_lookup lookup);
-
+struct ctrl_connection *osmo_ctrl_conn_alloc(void *ctx, void *data);
 int ctrl_cmd_handle(struct ctrl_handle *ctrl, struct ctrl_cmd *cmd, void *data);
diff --git a/src/ctrl/control_if.c b/src/ctrl/control_if.c
index df39486..376b7d3 100644
--- a/src/ctrl/control_if.c
+++ b/src/ctrl/control_if.c
@@ -357,7 +357,7 @@
 	return ret;
 }
 
-static int control_write_cb(struct osmo_fd *bfd, struct msgb *msg)
+int control_write_cb(struct osmo_fd *bfd, struct msgb *msg)
 {
 	int rc;
 
@@ -368,7 +368,7 @@
 	return rc;
 }
 
-static struct ctrl_connection *ctrl_connection_alloc(void *ctx)
+struct ctrl_connection *osmo_ctrl_conn_alloc(void *ctx, void *data)
 {
 	struct ctrl_connection *ccon = talloc_zero(ctx, struct ctrl_connection);
 	if (!ccon)
@@ -379,6 +379,9 @@
 
 	INIT_LLIST_HEAD(&ccon->cmds);
 	INIT_LLIST_HEAD(&ccon->def_cmds);
+
+	ccon->write_queue.bfd.data = data ? data : ccon;
+	ccon->write_queue.write_cb = control_write_cb;
 
 	return ccon;
 }
@@ -412,19 +415,17 @@
 		return ret;
 	}
 #endif
-	ccon = ctrl_connection_alloc(listen_bfd->data);
+	ctrl = listen_bfd->data;
+	ccon = osmo_ctrl_conn_alloc(listen_bfd->data, ctrl);
 	if (!ccon) {
 		LOGP(DLCTRL, LOGL_ERROR, "Failed to allocate.\n");
 		close(fd);
 		return -1;
 	}
 
-	ctrl = listen_bfd->data;
-	ccon->write_queue.bfd.data = ctrl;
 	ccon->write_queue.bfd.fd = fd;
 	ccon->write_queue.bfd.when = BSC_FD_READ;
 	ccon->write_queue.read_cb = handle_control_read;
-	ccon->write_queue.write_cb = control_write_cb;
 
 	ret = osmo_fd_register(&ccon->write_queue.bfd);
 	if (ret < 0) {
@@ -654,6 +655,36 @@
 	return ctrl_interface_setup_dynip(data, "127.0.0.1", port, lookup);
 }
 
+struct ctrl_handle *ctrl_interface_connect(void *data, const char *addr,
+					   uint16_t port,
+					   ctrl_cmd_lookup lookup)
+{
+	int ret;
+	struct ctrl_handle *ctrl;
+
+	ctrl = talloc_zero(data, struct ctrl_handle);
+	if (!ctrl)
+		return NULL;
+
+	INIT_LLIST_HEAD(&ctrl->ccon_list);
+
+	ctrl->data = data;
+	ctrl->lookup = lookup;
+
+	ctrl->listen_fd.cb = NULL;
+	ctrl->listen_fd.data = ctrl;
+	ret = osmo_sock_init_ifd(&ctrl->listen_fd, AF_INET, SOCK_STREAM,
+				 IPPROTO_TCP, addr, port, OSMO_SOCK_F_CONNECT);
+	if (ret < 0) {
+		LOGP(DLCTRL, LOGL_ERROR, "Cannot connect to CTRL at %s:%u\n",
+		     addr, port);
+		talloc_free(ctrl);
+		return NULL;
+	}
+	LOGP(DLCTRL, LOGL_NOTICE, "CTRL connected to %s:%u\n", addr, port);
+	return ctrl;
+}
+
 struct ctrl_handle *ctrl_interface_setup_dynip(void *data,
 					       const char *bind_addr,
 					       uint16_t port,

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

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I522ed809cbebfd3d7dd08b4ed9137b39ff192e32
Gerrit-PatchSet: 2
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max <msuraev at sysmocom.de>


More information about the gerrit-log mailing list