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
diff --git a/src/core/libosmocore.map b/src/core/libosmocore.map
index d31392b..50be67c 100644
--- a/src/core/libosmocore.map
+++ b/src/core/libosmocore.map
@@ -273,6 +273,7 @@
osmo_iofd_txqueue_len;
osmo_iofd_unregister;
osmo_iofd_uring_init;
+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 4cef142..fdb9e32 100644
--- a/src/core/osmo_io.c
+++ b/src/core/osmo_io.c
@@ -433,7 +433,9 @@
IOFD_FLAG_UNSET(iofd, IOFD_FLAG_CLOSED);
osmo_iofd_ops.read_enable(iofd);
- osmo_iofd_ops.write_enable(iofd);
+
+ if (iofd->tx_queue.current_length > 0)
+ osmo_iofd_ops.write_enable(iofd);
return rc;
}
@@ -603,4 +605,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__) */