msuraev has submitted this change. ( 
https://gerrit.osmocom.org/c/libosmo-netif/+/30686 )

Change subject: Add osmo_stream_srv_link_is_opened()
......................................................................

Add osmo_stream_srv_link_is_opened()

We use file descriptor of -1 as an indicator for unopened link internally.
However, since all the structs of libosmo-netif are opaque, using it from 
external
applications looks like a leaky abstraction.

Let's remedy this by adding function which properly check this for the library 
user.

Related: OS#5568
Change-Id: I91aa7da5f09ec4e8e2d21c827b45ed92e6b0e3d9
---
M include/osmocom/netif/stream.h
M src/stream.c
2 files changed, 15 insertions(+), 4 deletions(-)

Approvals:
  Jenkins Builder: Verified
  fixeria: Looks good to me, but someone else must approve
  laforge: Looks good to me, approved



diff --git a/include/osmocom/netif/stream.h b/include/osmocom/netif/stream.h
index ce8f1d2..a52e7c4 100644
--- a/include/osmocom/netif/stream.h
+++ b/include/osmocom/netif/stream.h
@@ -36,7 +36,7 @@
 void *osmo_stream_srv_link_get_data(struct osmo_stream_srv_link *link);
 char *osmo_stream_srv_link_get_sockname(const struct osmo_stream_srv_link 
*link);
 struct osmo_fd *osmo_stream_srv_link_get_ofd(struct osmo_stream_srv_link 
*link);
-
+bool osmo_stream_srv_link_is_opened(const struct osmo_stream_srv_link *link);
 int osmo_stream_srv_link_open(struct osmo_stream_srv_link *link);
 void osmo_stream_srv_link_close(struct osmo_stream_srv_link *link);

diff --git a/src/stream.c b/src/stream.c
index 85779db..172a299 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -1267,16 +1267,27 @@
        return 0;
 }

+/*! \brief Check whether the stream server link is opened
+ *  \param[in] link Stream Server Link to check */
+bool osmo_stream_srv_link_is_opened(const struct osmo_stream_srv_link *link)
+{
+       if (!link)
+               return false;
+
+       if (link->ofd.fd == -1)
+               return false;
+
+       return true;
+}
+
 /*! \brief Close the stream server link and unregister from select loop
  *  Does not destroy the server link, merely closes it!
  *  \param[in] link Stream Server Link to close */
 void osmo_stream_srv_link_close(struct osmo_stream_srv_link *link)
 {
-       if (!link)
+       if (!osmo_stream_srv_link_is_opened(link))
                return;

-       if (link->ofd.fd == -1)
-               return;
        osmo_fd_unregister(&link->ofd);
        close(link->ofd.fd);
        link->ofd.fd = -1;



1 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted 
one.
--
To view, visit https://gerrit.osmocom.org/c/libosmo-netif/+/30686
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Change-Id: I91aa7da5f09ec4e8e2d21c827b45ed92e6b0e3d9
Gerrit-Change-Number: 30686
Gerrit-PatchSet: 2
Gerrit-Owner: msuraev <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <[email protected]>
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-Reviewer: msuraev <[email protected]>
Gerrit-Reviewer: pespin <[email protected]>
Gerrit-MessageType: merged

Reply via email to