Skip to content

Commit

Permalink
consistency + inform the caller if a iomux_remove() call failed
Browse files Browse the repository at this point in the history
  • Loading branch information
xant committed Mar 26, 2014
1 parent 85051f4 commit 769431d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/iomux.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -289,6 +289,7 @@ iomux_remove(iomux_t *iomux, int fd)
iomux->minfd = iomux->maxfd;
}
MUTEX_UNLOCK(iomux);
return 1;
}

iomux_timeout_id_t
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1094,7 +1095,7 @@ iomux_close(iomux_t *iomux, int fd)

MUTEX_UNLOCK(iomux);

return 0;
return 1;
}

int
Expand Down
4 changes: 3 additions & 1 deletion src/iomux.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 769431d

Please sign in to comment.