Skip to content

Commit

Permalink
allow to set/unset the output callback
Browse files Browse the repository at this point in the history
once a fildescriptor has already been added to the mux
  • Loading branch information
Andrea Guzzo committed Apr 27, 2014
1 parent dfd8d0c commit c39d73d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/iomux.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions src/iomux.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c39d73d

Please sign in to comment.