summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/select.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/select.c b/src/select.c
index f7ee424c..0ba8bc60 100644
--- a/src/select.c
+++ b/src/select.c
@@ -24,6 +24,7 @@
#include <fcntl.h>
#include <stdio.h>
+#include <unistd.h>
#include <string.h>
#include <stdbool.h>
@@ -117,6 +118,22 @@ void osmo_fd_unregister(struct osmo_fd *fd)
llist_del(&fd->list);
}
+/*! Close a file descriptor, mark it as closed + unregister from select loop abstraction
+ * \param[in] fd osmocom file descriptor to be unregistered + closed
+ *
+ * If \a fd is registered, we unregister it from the select() loop
+ * abstraction. We then close the fd and set it to -1, as well as
+ * unsetting any 'when' flags */
+void osmo_fd_close(struct osmo_fd *fd)
+{
+ if (osmo_fd_is_registered(fd))
+ osmo_fd_unregister(fd);
+ if (fd->fd != -1)
+ close(fd->fd);
+ fd->fd = -1;
+ fd->when = 0;
+}
+
/*! Populate the fd_sets and return the highest fd number
* \param[in] _rset The readfds to populate
* \param[in] _wset The wrtiefds to populate