[PATCH 2/2] ipa: Add a callback to detect if the server_conn was closed

Daniel Willmann daniel at totalueberwachung.de
Thu Sep 15 12:56:58 CEST 2011


---
 include/osmocom/abis/ipa.h |    3 ++-
 src/input/ipa.c            |    5 ++++-
 src/ipa_proxy.c            |    2 +-
 3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/include/osmocom/abis/ipa.h b/include/osmocom/abis/ipa.h
index 43422dc..397cf9c 100644
--- a/include/osmocom/abis/ipa.h
+++ b/include/osmocom/abis/ipa.h
@@ -24,11 +24,12 @@ struct ipa_server_conn {
 	struct ipa_server_link		*server;
 	struct osmo_fd			ofd;
 	struct llist_head		tx_queue;
+	int (*closed_cb)(struct ipa_server_conn *peer);
 	int (*cb)(struct ipa_server_conn *peer, struct msgb *msg);
 	void				*data;
 };
 
-struct ipa_server_conn *ipa_server_conn_create(void *ctx, struct ipa_server_link *link, int fd, int (*cb)(struct ipa_server_conn *peer, struct msgb *msg), void *data);
+struct ipa_server_conn *ipa_server_conn_create(void *ctx, struct ipa_server_link *link, int fd, int (*cb)(struct ipa_server_conn *peer, struct msgb *msg), int (*closed_cb)(struct ipa_server_conn *peer), void *data);
 void ipa_server_conn_destroy(struct ipa_server_conn *peer);
 
 void ipa_server_conn_send(struct ipa_server_conn *peer, struct msgb *msg);
diff --git a/src/input/ipa.c b/src/input/ipa.c
index c881b22..a887959 100644
--- a/src/input/ipa.c
+++ b/src/input/ipa.c
@@ -443,7 +443,7 @@ static int ipa_server_conn_cb(struct osmo_fd *ofd, unsigned int what)
 struct ipa_server_conn *
 ipa_server_conn_create(void *ctx, struct ipa_server_link *link, int fd,
 		int (*cb)(struct ipa_server_conn *conn, struct msgb *msg),
-		void *data)
+		int (*closed_cb)(struct ipa_server_conn *conn), void *data)
 {
 	struct ipa_server_conn *conn;
 
@@ -459,6 +459,7 @@ ipa_server_conn_create(void *ctx, struct ipa_server_link *link, int fd,
 	conn->ofd.cb = ipa_server_conn_cb;
 	conn->ofd.when = BSC_FD_READ;
 	conn->cb = cb;
+	conn->closed_cb = closed_cb;
 	conn->data = data;
 	INIT_LLIST_HEAD(&conn->tx_queue);
 
@@ -474,6 +475,8 @@ void ipa_server_conn_destroy(struct ipa_server_conn *conn)
 {
 	close(conn->ofd.fd);
 	osmo_fd_unregister(&conn->ofd);
+	if (conn->closed_cb)
+		conn->closed_cb(conn);
 	talloc_free(conn);
 }
 
diff --git a/src/ipa_proxy.c b/src/ipa_proxy.c
index f4e1df8..9816d02 100644
--- a/src/ipa_proxy.c
+++ b/src/ipa_proxy.c
@@ -176,7 +176,7 @@ ipa_sock_src_accept_cb(struct ipa_server_link *link, int fd)
 	conn->route = route;
 
 	conn->src = ipa_server_conn_create(tall_ipa_proxy_ctx, link, fd,
-					   ipa_sock_src_cb, conn);
+					   ipa_sock_src_cb, NULL, conn);
 	if (conn->src == NULL) {
 		LOGP(DLINP, LOGL_ERROR, "could not create server peer: %s\n",
 			strerror(errno));
-- 
1.7.6.1





More information about the OpenBSC mailing list