static int curl_glue_on_io(sd_event_source *s, int fd, uint32_t revents, void *userdata) { CurlGlue *g = userdata; int action, k = 0, translated_fd; assert(s); assert(g); translated_fd = PTR_TO_FD(hashmap_get(g->translate_fds, FD_TO_PTR(fd))); if ((revents & (EPOLLIN|EPOLLOUT)) == (EPOLLIN|EPOLLOUT)) action = CURL_POLL_INOUT; else if (revents & EPOLLIN) action = CURL_POLL_IN; else if (revents & EPOLLOUT) action = CURL_POLL_OUT; else action = 0; if (curl_multi_socket_action(g->curl, translated_fd, action, &k) < 0) { log_debug("Failed to propagate IO event."); return -EINVAL; } curl_glue_check_finished(g); return 0; }
int fdset_iterate(FDSet *s, Iterator *i) { void *p; if (!set_iterate(MAKE_SET(s), i, &p)) return -ENOENT; return PTR_TO_FD(p); }
int fdset_steal_first(FDSet *fds) { void *p; p = set_steal_first(MAKE_SET(fds)); if (!p) return -ENOENT; return PTR_TO_FD(p); }
void fdset_free(FDSet *s) { void *p; while ((p = set_steal_first(MAKE_SET(s)))) { /* Valgrind's fd might have ended up in this set here, * due to fdset_new_fill(). We'll ignore all failures * here, so that the EBADFD that valgrind will return * us on close() doesn't influence us */ /* When reloading duplicates of the private bus * connection fds and suchlike are closed here, which * has no effect at all, since they are only * duplicates. So don't be surprised about these log * messages. */ log_debug("Closing left-over fd %i", PTR_TO_FD(p)); close_nointr(PTR_TO_FD(p)); } set_free(MAKE_SET(s)); }
int fdset_cloexec(FDSet *fds, bool b) { Iterator i; void *p; int r; assert(fds); SET_FOREACH(p, MAKE_SET(fds), i) { r = fd_cloexec(PTR_TO_FD(p), b); if (r < 0) return r; }
int fdset_close_others(FDSet *fds) { void *e; Iterator i; int *a; unsigned j, m; j = 0, m = fdset_size(fds); a = alloca(sizeof(int) * m); SET_FOREACH(e, MAKE_SET(fds), i) a[j++] = PTR_TO_FD(e); assert(j == m); return close_all_fds(a, j); }
static void *close_thread(void *p) { assert_se(close_nointr(PTR_TO_FD(p)) != -EBADF); return NULL; }
static void *close_thread(void *p) { (void) pthread_setname_np(pthread_self(), "close"); assert_se(close_nointr(PTR_TO_FD(p)) != -EBADF); return NULL; }