pespin has submitted this change. (
https://gerrit.osmocom.org/c/osmo-pcap/+/39166?usp=email )
Change subject: pcap-client: Split client-conn allocation to its own constructor function
......................................................................
pcap-client: Split client-conn allocation to its own constructor function
Preparation patch towards follow-up changes. Also makes it easier to
spot whre this struct is allocated.
Change-Id: I0cea59f9a94cf1233c2df6ea844a1c5599123d64
---
M src/osmo_client_core.c
1 file changed, 21 insertions(+), 18 deletions(-)
Approvals:
Jenkins Builder: Verified
fixeria: Looks good to me, approved
laforge: Looks good to me, but someone else must approve
diff --git a/src/osmo_client_core.c b/src/osmo_client_core.c
index 11ba7c9..f858e17 100644
--- a/src/osmo_client_core.c
+++ b/src/osmo_client_core.c
@@ -379,28 +379,31 @@
return NULL;
}
+struct osmo_pcap_client_conn *osmo_client_conn_alloc(
+ struct osmo_pcap_client *client,
+ const char *name)
+{
+ struct osmo_pcap_client_conn *conn;
+
+ conn = talloc_zero(client, struct osmo_pcap_client_conn);
+ OSMO_ASSERT(conn);
+
+ conn->name = talloc_strdup(conn, name);
+ OSMO_ASSERT(conn->name);
+
+ osmo_client_conn_init(conn, client);
+ llist_add_tail(&conn->entry, &client->conns);
+ return conn;
+}
+
struct osmo_pcap_client_conn *osmo_client_find_or_create_conn(
struct osmo_pcap_client *client,
const char *name)
{
- struct osmo_pcap_client_conn *conn = osmo_client_find_conn(client, name);;
+ struct osmo_pcap_client_conn *conn;
- if (conn)
- return conn;
-
- conn = talloc_zero(client, struct osmo_pcap_client_conn);
- if (!conn) {
- LOGP(DCLIENT, LOGL_ERROR, "Failed to allocate conn for %s\n", name);
- return NULL;
- }
- conn->name = talloc_strdup(conn, name);
- if (!conn->name) {
- LOGP(DCLIENT, LOGL_ERROR, "Failed to allocate name for %s\n", name);
- talloc_free(conn);
- return NULL;
- }
-
- osmo_client_conn_init(conn, client);
- llist_add_tail(&conn->entry, &client->conns);
+ conn = osmo_client_find_conn(client, name);
+ if (!conn)
+ conn = osmo_client_conn_alloc(client, name);
return conn;
}
--
To view, visit
https://gerrit.osmocom.org/c/osmo-pcap/+/39166?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: osmo-pcap
Gerrit-Branch: master
Gerrit-Change-Id: I0cea59f9a94cf1233c2df6ea844a1c5599123d64
Gerrit-Change-Number: 39166
Gerrit-PatchSet: 2
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>