return -1;
}
- ret = fr_event_filter_insert(ef->linked_ctx, dst, ef->fd, ef->filter, &ef->active, ef->error, ef->uctx);
+ ret = fr_event_filter_insert(ef->linked_ctx, NULL,
+ dst, ef->fd, ef->filter, &ef->active, ef->error, ef->uctx);
if (ret < 0) return -1;
(void)fr_event_fd_delete(src, ef->fd, ef->filter);
/** Insert a filter for the specified fd
*
* @param[in] ctx to bind lifetime of the event to.
+ * @param[out] ef_out Previously allocated ef, or NULL.
* @param[in] el to insert fd callback into.
* @param[in] fd to install filters for.
* @param[in] filter one of the #fr_event_filter_t values.
* @param[in] error function to call when an error occurs on the fd.
* @param[in] uctx to pass to handler.
*/
-int fr_event_filter_insert(TALLOC_CTX *ctx, fr_event_list_t *el, int fd,
+int fr_event_filter_insert(TALLOC_CTX *ctx, fr_event_fd_t **ef_out,
+ fr_event_list_t *el, int fd,
fr_event_filter_t filter,
void *funcs, fr_event_error_cb_t error,
void *uctx)
return -1;
}
- ef = rbtree_finddata(el->fds, &(fr_event_fd_t){ .fd = fd, .filter = filter });
+ if (!ef_out || !*ef_out) {
+ ef = rbtree_finddata(el->fds, &(fr_event_fd_t){ .fd = fd, .filter = filter });
+ } else {
+ ef = *ef_out;
+ fr_assert((fd < 0) || (ef->fd == fd));
+ }
/*
* Need to free the event to change the talloc link.
ef->error = error;
ef->uctx = uctx;
+ if (ef_out) *ef_out = ef;
+
return 0;
}
return -1;
}
- return fr_event_filter_insert(ctx, el, fd, FR_EVENT_FILTER_IO, &funcs, error, uctx);
+ return fr_event_filter_insert(ctx, NULL, el, fd, FR_EVENT_FILTER_IO, &funcs, error, uctx);
}
#ifndef NDEBUG
int fr_event_fd_move(fr_event_list_t *dst, fr_event_list_t *src, int fd, fr_event_filter_t filter);
int fr_event_fd_delete(fr_event_list_t *el, int fd, fr_event_filter_t filter);
-int fr_event_filter_insert(TALLOC_CTX *ctx, fr_event_list_t *el, int fd,
+int fr_event_filter_insert(TALLOC_CTX *ctx, fr_event_fd_t **ef_out,
+ fr_event_list_t *el, int fd,
fr_event_filter_t filter,
void *funcs,
fr_event_error_cb_t error,
* @todo - ensure that proto_detail_work is done the file...
* maybe by creating a new instance?
*/
- if (fr_event_filter_insert(thread, thread->el, fd, FR_EVENT_FILTER_VNODE,
+ if (fr_event_filter_insert(thread, NULL, thread->el, fd, FR_EVENT_FILTER_VNODE,
&funcs, NULL, thread) < 0) {
PERROR("Failed adding work socket to event loop");
close(fd);
memset(&funcs, 0, sizeof(funcs));
funcs.revoke = mod_revoke;
- if (fr_event_filter_insert(thread, el, thread->fd, FR_EVENT_FILTER_VNODE, &funcs, NULL, thread) < 0) {
+ if (fr_event_filter_insert(thread, NULL, el, thread->fd, FR_EVENT_FILTER_VNODE, &funcs, NULL, thread) < 0) {
WARN("Failed to add event watching for unmounted file system");
}
#endif