diff --git a/src/iomux.c b/src/iomux.c index c648ae6..ffa9cfe 100644 --- a/src/iomux.c +++ b/src/iomux.c @@ -907,6 +907,33 @@ int iomux_num_fds(iomux_t *iomux) return num_fds; } +int +iomux_set_output_callback(iomux_t *iomux, int fd, iomux_output_callback_t cb) +{ + MUTEX_LOCK(iomux); + if (!iomux->connections[fd]) { + MUTEX_UNLOCK(iomux); + return 0; + } + iomux->connections[fd]->cbs.mux_output = cb; + MUTEX_UNLOCK(iomux); + return 1; +} + +int +iomux_unset_output_callback(iomux_t *iomux, int fd) +{ + MUTEX_LOCK(iomux); + if (!iomux->connections[fd]) { + MUTEX_UNLOCK(iomux); + return 0; + } + iomux_output_callback_t prev = iomux->connections[fd]->cbs.mux_output; + iomux->connections[fd]->cbs.mux_output = NULL; + MUTEX_UNLOCK(iomux); + return prev ? 1 : 0; +} + #if defined(HAVE_KQUEUE) void iomux_run(iomux_t *iomux, struct timeval *tv_default) diff --git a/src/iomux.h b/src/iomux.h index 5cd8bbb..e9aad4b 100644 --- a/src/iomux.h +++ b/src/iomux.h @@ -268,6 +268,9 @@ void iomux_run(iomux_t *iomux, struct timeval *timeout); */ int iomux_write(iomux_t *iomux, int fd, const void *buf, int len); +int iomux_set_output_callback(iomux_t *iomux, int fd, iomux_output_callback_t cb); +int iomux_unset_output_callback(iomux_t *iomux, int fd); + /** * @brief Close a file handled by the iomux * @param iomux A valid iomux handler