daniel has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/libosmocore/+/33497 )


Change subject: osmo_io: Add osmo_iofd_notify_connected()
......................................................................

osmo_io: Add osmo_iofd_notify_connected()

Don't call write_enable() in osmo_iofd_register(). This was used to
detect whether a socket is connected or not, but would always be
enabled, even on unconnected sockets. Instead make this behaviour
explicit by calling osmo_iofd_notify_connected().

Change-Id: Ieed10bc94c8aad821c0a8f7764db0e05c054c1e3
---
M include/osmocom/core/osmo_io.h
M src/core/libosmocore.map
M src/core/osmo_io.c
M tests/osmo_io/osmo_io_test.c
M tests/osmo_io/osmo_io_test.ok
5 files changed, 30 insertions(+), 6 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/97/33497/1

diff --git a/include/osmocom/core/osmo_io.h b/include/osmocom/core/osmo_io.h
index aac25a3..932b909 100644
--- a/include/osmocom/core/osmo_io.h
+++ b/include/osmocom/core/osmo_io.h
@@ -75,6 +75,8 @@
 int osmo_iofd_close(struct osmo_io_fd *iofd);
 void osmo_iofd_free(struct osmo_io_fd *iofd);

+void osmo_iofd_notify_connected(struct osmo_io_fd *iofd);
+
 int osmo_iofd_write_msgb(struct osmo_io_fd *iofd, struct msgb *msg);
 int osmo_iofd_sendto_msgb(struct osmo_io_fd *iofd, struct msgb *msg, int 
sendto_flags,
                          const struct osmo_sockaddr *dest);
diff --git a/src/core/libosmocore.map b/src/core/libosmocore.map
index 68f7270..50be67c 100644
--- a/src/core/libosmocore.map
+++ b/src/core/libosmocore.map
@@ -262,8 +262,6 @@
 osmo_iofd_get_priv_nr;
 osmo_iofd_init;
 osmo_iofd_ops;
-osmo_iofd_read_disable;
-osmo_iofd_read_enable;
 osmo_iofd_register;
 osmo_iofd_sendto_msgb;
 osmo_iofd_set_alloc_info;
@@ -275,8 +273,7 @@
 osmo_iofd_txqueue_len;
 osmo_iofd_unregister;
 osmo_iofd_uring_init;
-osmo_iofd_write_disable;
-osmo_iofd_write_enable;
+osmo_iofd_notify_connected;
 osmo_iofd_write_msgb;
 osmo_ip_str_type;
 osmo_isdnhdlc_decode;
diff --git a/src/core/osmo_io.c b/src/core/osmo_io.c
index d06e804..c7c4e48 100644
--- a/src/core/osmo_io.c
+++ b/src/core/osmo_io.c
@@ -430,7 +430,6 @@

        IOFD_FLAG_UNSET(iofd, IOFD_FLAG_CLOSED);
        osmo_iofd_ops.read_enable(iofd);
-       osmo_iofd_ops.write_enable(iofd);

        return rc;
 }
@@ -599,4 +598,14 @@
        iofd->io_ops = *ioops;
 }

+/*! Notify the user if/when the socket is connected
+ *  When the socket is connected the write_cb will be called.
+ *  \param[in] iofd the file descriptor */
+void osmo_iofd_notify_connected(struct osmo_io_fd *iofd)
+{
+       OSMO_ASSERT(iofd->mode == OSMO_IO_FD_MODE_READ_WRITE);
+       osmo_iofd_ops.write_enable(iofd);
+}
+
+
 #endif /* defined(__linux__) */
diff --git a/tests/osmo_io/osmo_io_test.c b/tests/osmo_io/osmo_io_test.c
index 74fe64d..bef1316 100644
--- a/tests/osmo_io/osmo_io_test.c
+++ b/tests/osmo_io/osmo_io_test.c
@@ -88,6 +88,8 @@
        osmo_iofd_register(iofd1, fds[0]);
        iofd2 = osmo_iofd_setup(ctx, fds[1], "ep2", OSMO_IO_FD_MODE_READ_WRITE, 
&ioops_conn_read_write, NULL);
        osmo_iofd_register(iofd2, fds[1]);
+       // Explicitly check if ep1 is connected through write_cb
+       osmo_iofd_notify_connected(iofd1);

        /* Allow enough cycles to handle the messages */
        for (int i = 0; i < 128; i++)
diff --git a/tests/osmo_io/osmo_io_test.ok b/tests/osmo_io/osmo_io_test.ok
index 43e5464..6527c19 100644
--- a/tests/osmo_io/osmo_io_test.ok
+++ b/tests/osmo_io/osmo_io_test.ok
@@ -1,6 +1,6 @@
 Running test_connected
+ep1: write() returned rc=0
 ep1: write() returned rc=16
-ep2: write() returned rc=0
 ep2: read() msg with len=16
 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10
 Running test_unconnected

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Ieed10bc94c8aad821c0a8f7764db0e05c054c1e3
Gerrit-Change-Number: 33497
Gerrit-PatchSet: 1
Gerrit-Owner: daniel <dwillm...@sysmocom.de>
Gerrit-MessageType: newchange

Reply via email to