From 769431de05772a4c2cf316d0f8ac8e9d8c25411b Mon Sep 17 00:00:00 2001 From: xant Date: Wed, 26 Mar 2014 12:33:51 +0100 Subject: [PATCH] consistency + inform the caller if a iomux_remove() call failed --- src/iomux.c | 9 +++++---- src/iomux.h | 4 +++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/iomux.c b/src/iomux.c index 204c265..12fe49a 100644 --- a/src/iomux.c +++ b/src/iomux.c @@ -245,14 +245,14 @@ iomux_add(iomux_t *iomux, int fd, iomux_callbacks_t *cbs) return 0; } -void +int iomux_remove(iomux_t *iomux, int fd) { MUTEX_LOCK(iomux); if (!iomux->connections[fd]) { MUTEX_UNLOCK(iomux); - return; + return 0; } iomux_unschedule(iomux, iomux->connections[fd]->timeout_id); @@ -289,6 +289,7 @@ iomux_remove(iomux_t *iomux, int fd) iomux->minfd = iomux->maxfd; } MUTEX_UNLOCK(iomux); + return 1; } iomux_timeout_id_t @@ -1063,7 +1064,7 @@ iomux_close(iomux_t *iomux, int fd) iomux_connection_t *conn = iomux->connections[fd]; if (!conn) { // fd is not registered within iomux MUTEX_UNLOCK(iomux); - return -1; + return 0; } if (fcntl(fd, F_GETFD, 0) != -1 && conn->outlen) { // there is pending data @@ -1094,7 +1095,7 @@ iomux_close(iomux_t *iomux, int fd) MUTEX_UNLOCK(iomux); - return 0; + return 1; } int diff --git a/src/iomux.h b/src/iomux.h index 465c8e8..2369e77 100644 --- a/src/iomux.h +++ b/src/iomux.h @@ -128,8 +128,9 @@ int iomux_add(iomux_t *iomux, int fd, iomux_callbacks_t *cbs); * @brief Remove a filedescriptor from the mux * @param iomux A valid iomux handler * @param fd The fd to remove + * @return TRUE on success; FALSE otherwise */ -void iomux_remove(iomux_t *iomux, int fd); +int iomux_remove(iomux_t *iomux, int fd); /** * @brief Register a timeout on a connection. @@ -278,6 +279,7 @@ int iomux_write(iomux_t *iomux, int fd, const void *buf, int len); * @brief Close a file handled by the iomux * @param iomux A valid iomux handler * @param fd The fd to close + * @return TRUE on success; FALSE otherwise */ int iomux_close(iomux_t *iomux, int fd);