From: Jaroslav Kysela Date: Sat, 30 Dec 2017 16:59:38 +0000 (+0100) Subject: tvhpoll: cleanups, use only 'ptr' for identification X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8de20df92e3007992525a25c947042670e50b821;p=thirdparty%2Ftvheadend.git tvhpoll: cleanups, use only 'ptr' for identification --- diff --git a/src/dbus.c b/src/dbus.c index 30223e3a8..d74c0b29a 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -386,7 +386,7 @@ dbus_server_thread(void *aux) continue; } - if (ev.data.ptr == &dbus_pipe) { + if (ev.ptr == &dbus_pipe) { if (read(dbus_pipe.rd, &c, 1) == 1) { if (c == 's') dbus_flush_queue(notify); diff --git a/src/descrambler/capmt.c b/src/descrambler/capmt.c index a77e15fc9..8f27477c2 100644 --- a/src/descrambler/capmt.c +++ b/src/descrambler/capmt.c @@ -1537,7 +1537,7 @@ handle_ca0(capmt_t *capmt) for (i = 0; i < nfds; i++) { - if (ev[i].data.ptr == &capmt->capmt_pipe) { + if (ev[i].ptr == &capmt->capmt_pipe) { ret = read(capmt->capmt_pipe.rd, buf, 1); if (ret == 1 && buf[0] == 'c') { capmt_flush_queue(capmt, 0); @@ -1549,7 +1549,7 @@ handle_ca0(capmt_t *capmt) continue; } - adapter = ev[i].data.ptr; + adapter = ev[i].ptr; if (adapter == NULL) continue; @@ -1634,7 +1634,7 @@ handle_single(capmt_t *capmt) if (nfds <= 0) continue; - if (ev.data.ptr == &capmt->capmt_pipe) { + if (ev.ptr == &capmt->capmt_pipe) { ret = read(capmt->capmt_pipe.rd, buf, 1); if (ret == 1 && buf[0] == 'c') { capmt_flush_queue(capmt, 0); diff --git a/src/descrambler/cclient.c b/src/descrambler/cclient.c index 3ce2c2bdd..737a05502 100644 --- a/src/descrambler/cclient.c +++ b/src/descrambler/cclient.c @@ -410,9 +410,9 @@ cc_session(cclient_t *cc) pthread_mutex_lock(&cc->cc_mutex); if (r < 0 && ERRNO_AGAIN(errno)) continue; - if (ev.data.ptr == &cc->cc_pipe) + if (ev.ptr == &cc->cc_pipe) read(cc->cc_pipe.rd, buf, sizeof(buf)); - else if (ev.data.ptr == &cc->cc_fd) { + else if (ev.ptr == &cc->cc_fd) { len = sbuf_read(&rbuf, cc->cc_fd); if (len > 0 && cc->cc_read(cc, &rbuf)) break; diff --git a/src/httpc.c b/src/httpc.c index c66510409..e0afaaba0 100644 --- a/src/httpc.c +++ b/src/httpc.c @@ -1409,7 +1409,7 @@ http_client_thread ( void *p ) if (atomic_get(&http_running) && !ERRNO_AGAIN(errno)) tvherror(LS_HTTPC, "tvhpoll_wait() error"); } else if (n > 0) { - if (&http_pipe == ev.data.ptr) { + if (&http_pipe == ev.ptr) { if (read(http_pipe.rd, &c, 1) == 1) { /* end-of-task */ break; @@ -1418,7 +1418,7 @@ http_client_thread ( void *p ) } pthread_mutex_lock(&http_lock); TAILQ_FOREACH(hc, &http_clients, hc_link) - if (hc == ev.data.ptr) + if (hc == ev.ptr) break; if (hc == NULL) { pthread_mutex_unlock(&http_lock); @@ -2058,7 +2058,7 @@ rep: } if (r != 1) continue; - if (ev.data.ptr != hc) { + if (ev.ptr != hc) { fprintf(stderr, "HTTPCTS: Poll returned a wrong value\n"); goto fatal; } diff --git a/src/input/mpegts/iptv/iptv.c b/src/input/mpegts/iptv/iptv.c index 9fda8f466..e2bf28073 100644 --- a/src/input/mpegts/iptv/iptv.c +++ b/src/input/mpegts/iptv/iptv.c @@ -459,7 +459,7 @@ iptv_input_thread ( void *aux ) } else if ( nfds == 0 ) { continue; } - im = ev.data.ptr; + im = ev.ptr; r = 0; pthread_mutex_lock(&iptv_lock); diff --git a/src/input/mpegts/linuxdvb/linuxdvb_ca.c b/src/input/mpegts/linuxdvb/linuxdvb_ca.c index cf7b3e9d5..e5ca45a3b 100644 --- a/src/input/mpegts/linuxdvb/linuxdvb_ca.c +++ b/src/input/mpegts/linuxdvb/linuxdvb_ca.c @@ -298,7 +298,7 @@ linuxdvb_ca_thread ( void *aux ) evp = ev; evp->fd = linuxdvb_ca_pipe.rd; evp->events = TVHPOLL_IN; - evp->data.ptr = &linuxdvb_ca_pipe; + evp->ptr = &linuxdvb_ca_pipe; evp++; evcnt = 1; pthread_mutex_lock(&linuxdvb_ca_mutex); @@ -340,7 +340,7 @@ linuxdvb_ca_thread ( void *aux ) } evp->fd = lcat->lcat_ca_fd; evp->events = TVHPOLL_IN; - evp->data.ptr = lcat; + evp->ptr = lcat; evp++; evcnt++; } @@ -357,7 +357,7 @@ linuxdvb_ca_thread ( void *aux ) if (monitor) tm = tm2; for (evp = ev; evcnt > 0; evp++, evcnt--) { - if (evp->data.ptr == &linuxdvb_ca_pipe) { + if (evp->ptr == &linuxdvb_ca_pipe) { do { l = read(linuxdvb_ca_pipe.rd, buf, sizeof(buf)); } while (l < 0 && errno == EINTR); @@ -371,7 +371,7 @@ linuxdvb_ca_thread ( void *aux ) } LIST_FOREACH(lcat, &linuxdvb_all_transports, lcat_all_link) { if (lcat->lcat_ca_fd < 0) continue; - if (lcat != evp->data.ptr) continue; + if (lcat != evp->ptr) continue; do { l = read(lcat->lcat_ca_fd, buf, sizeof(buf)); } while (l < 0 && (r = errno) == EINTR); diff --git a/src/input/mpegts/linuxdvb/linuxdvb_frontend.c b/src/input/mpegts/linuxdvb/linuxdvb_frontend.c index 1ff5e6b6f..fcc7b8cb9 100644 --- a/src/input/mpegts/linuxdvb/linuxdvb_frontend.c +++ b/src/input/mpegts/linuxdvb/linuxdvb_frontend.c @@ -1389,10 +1389,12 @@ linuxdvb_frontend_input_thread ( void *aux ) /* Setup poll */ efd = tvhpoll_create(2); memset(ev, 0, sizeof(ev)); - ev[0].events = TVHPOLL_IN; - ev[0].fd = ev[0].data.fd = dvr; - ev[1].events = TVHPOLL_IN; - ev[1].fd = ev[1].data.fd = lfe->lfe_dvr_pipe.rd; + ev[0].events = TVHPOLL_IN; + ev[0].fd = dvr; + ev[0].ptr = lfe; + ev[1].events = TVHPOLL_IN; + ev[1].fd = lfe->lfe_dvr_pipe.rd; + ev[1].ptr = &lfe->lfe_dvr_pipe; tvhpoll_add(efd, ev, 2); /* Allocate memory */ @@ -1414,7 +1416,7 @@ linuxdvb_frontend_input_thread ( void *aux ) } } if (nfds < 1) continue; - if (ev[0].data.fd == lfe->lfe_dvr_pipe.rd) { + if (ev[0].ptr == &lfe->lfe_dvr_pipe) { if (read(lfe->lfe_dvr_pipe.rd, &b, 1) > 0) { if (b == 'c') linuxdvb_update_pids(lfe, name, &tuned, pids, ARRAY_SIZE(pids)); @@ -1423,7 +1425,7 @@ linuxdvb_frontend_input_thread ( void *aux ) } continue; } - if (ev[0].data.fd != dvr) break; + if (ev[0].ptr != lfe) break; nodata = 50; lfe->lfe_nodata = 0; diff --git a/src/input/mpegts/satip/satip_frontend.c b/src/input/mpegts/satip/satip_frontend.c index 99f45455c..8d3f24d5b 100644 --- a/src/input/mpegts/satip/satip_frontend.c +++ b/src/input/mpegts/satip/satip_frontend.c @@ -1602,7 +1602,7 @@ new_tune: } if (nfds <= 0) continue; - if (ev[0].data.ptr == NULL) { + if (ev[0].ptr == NULL) { c = read(lfe->sf_dvr_pipe.rd, b, 1); if (c == 1) { if (b[0] == 'e') { @@ -1616,7 +1616,7 @@ new_tune: } } - if (rtsp && ev[0].data.ptr == rtsp) { + if (rtsp && ev[0].ptr == rtsp) { r = http_client_run(rtsp); if (r < 0) { http_client_close(rtsp); @@ -1727,7 +1727,7 @@ new_tune: if (nfds < 0) continue; if (nfds == 0) break; - if (ev[0].data.ptr == NULL) { + if (ev[0].ptr == NULL) { c = read(lfe->sf_dvr_pipe.rd, b, 1); if (c == 1) { if (b[0] == 'c') { @@ -1750,7 +1750,7 @@ new_tune: goto done; } - if (ev[0].data.ptr == rtsp) { + if (ev[0].ptr == rtsp) { tc = 0; r = http_client_run(rtsp); if (r < 0) { @@ -1782,22 +1782,22 @@ new_tune: memset(ev, 0, sizeof(ev)); nfds = 0; if ((rtsp_flags & SATIP_SETUP_TCP) == 0) { - ev[nfds].events = TVHPOLL_IN; - ev[nfds].fd = rtp->fd; - ev[nfds].data.ptr = rtp; + ev[nfds].events = TVHPOLL_IN; + ev[nfds].fd = rtp->fd; + ev[nfds].ptr = rtp; nfds++; - ev[nfds].events = TVHPOLL_IN; - ev[nfds].fd = rtcp->fd; - ev[nfds].data.ptr = rtcp; + ev[nfds].events = TVHPOLL_IN; + ev[nfds].fd = rtcp->fd; + ev[nfds].ptr = rtcp; nfds++; } else { rtsp->hc_io_size = 128 * 1024; rtsp->hc_rtp_data_received = satip_frontend_rtp_data_received; } if (i) { - ev[nfds].events = TVHPOLL_IN; - ev[nfds].fd = rtsp->hc_fd; - ev[nfds].data.ptr = rtsp; + ev[nfds].events = TVHPOLL_IN; + ev[nfds].fd = rtsp->hc_fd; + ev[nfds].ptr = rtsp; nfds++; } tvhpoll_add(efd, ev, nfds); @@ -1845,7 +1845,7 @@ new_tune: break; } - if (nfds > 0 && ev[0].data.ptr == NULL) { + if (nfds > 0 && ev[0].ptr == NULL) { c = read(lfe->sf_dvr_pipe.rd, b, 1); if (c == 1) { if (b[0] == 'c') { @@ -1878,7 +1878,7 @@ new_tune: if (nfds < 1) continue; - if (ev[0].data.ptr == rtsp) { + if (ev[0].ptr == rtsp) { r = http_client_run(rtsp); if (r < 0) { if (rtsp->hc_code == 404 && session[0]) { @@ -1993,7 +1993,7 @@ new_tune: reply = 1; } - if (ev[0].data.ptr == rtcp) { + if (ev[0].ptr == rtcp) { c = recv(rtcp->fd, b, sizeof(b), MSG_DONTWAIT); if (c > 0) { pthread_mutex_lock(&lfe->sf_dvr_lock); @@ -2004,7 +2004,7 @@ new_tune: continue; } - if (ev[0].data.ptr != rtp) + if (ev[0].ptr != rtp) continue; tc = udp_multirecv_read(&um, rtp->fd, RTP_PKTS, &iovec); diff --git a/src/input/mpegts/tvhdhomerun/tvhdhomerun_frontend.c b/src/input/mpegts/tvhdhomerun/tvhdhomerun_frontend.c index 4b39fad38..eb2db76dc 100644 --- a/src/input/mpegts/tvhdhomerun/tvhdhomerun_frontend.c +++ b/src/input/mpegts/tvhdhomerun/tvhdhomerun_frontend.c @@ -161,10 +161,12 @@ tvhdhomerun_frontend_input_thread ( void *aux ) /* the poll set includes the sockfd and the pipe for IPC */ efd = tvhpoll_create(2); memset(ev, 0, sizeof(ev)); - ev[0].events = TVHPOLL_IN; - ev[0].fd = ev[0].data.fd = sockfd; - ev[1].events = TVHPOLL_IN; - ev[1].fd = ev[1].data.fd = hfe->hf_input_thread_pipe.rd; + ev[0].events = TVHPOLL_IN; + ev[0].fd = sockfd; + ev[0].ptr = hfe; + ev[1].events = TVHPOLL_IN; + ev[1].fd = hfe->hf_input_thread_pipe.rd; + ev[1].ptr = &hfe->hf_input_thread_pipe; r = tvhpoll_add(efd, ev, 2); if(r < 0) @@ -178,7 +180,7 @@ tvhdhomerun_frontend_input_thread ( void *aux ) nfds = tvhpoll_wait(efd, ev, 1, -1); if (nfds < 1) continue; - if (ev[0].data.fd != sockfd) break; + if (ev[0].ptr != hfe) break; if((r = sbuf_tsdebug_read(mmi->mmi_mux, &sb, sockfd)) < 0) { /* whoopsy */ diff --git a/src/spawn.c b/src/spawn.c index 3c6757690..13afa12ad 100644 --- a/src/spawn.c +++ b/src/spawn.c @@ -120,12 +120,12 @@ spawn_pipe_thread(void *aux) int nfds; memset(ev, 0, sizeof(ev)); - ev[0].events = TVHPOLL_IN; - ev[0].fd = spawn_pipe_info.rd; - ev[0].data.ptr = &spawn_pipe_info; - ev[1].events = TVHPOLL_IN; - ev[1].fd = spawn_pipe_error.rd; - ev[1].data.ptr = &spawn_pipe_error; + ev[0].events = TVHPOLL_IN; + ev[0].fd = spawn_pipe_info.rd; + ev[0].ptr = &spawn_pipe_info; + ev[1].events = TVHPOLL_IN; + ev[1].fd = spawn_pipe_error.rd; + ev[1].ptr = &spawn_pipe_error; tvhpoll_add(efd, ev, 2); while (atomic_get(&spawn_pipe_running)) { diff --git a/src/tcp.c b/src/tcp.c index 1e4e16f23..7fd31363d 100644 --- a/src/tcp.c +++ b/src/tcp.c @@ -743,7 +743,7 @@ tcp_server_loop(void *aux) if (r == 0) continue; - if (ev.data.ptr == &tcp_server_pipe) { + if (ev.ptr == &tcp_server_pipe) { r = read(tcp_server_pipe.rd, &c, 1); if (r > 0) { next: @@ -764,7 +764,7 @@ next: continue; } - ts = ev.data.ptr; + ts = ev.ptr; if(ev.events & TVHPOLL_HUP) { close(ts->serverfd); diff --git a/src/tvhpoll.c b/src/tvhpoll.c index 4b8f119f3..8803e0bd1 100644 --- a/src/tvhpoll.c +++ b/src/tvhpoll.c @@ -104,10 +104,9 @@ int tvhpoll_add { int i, rc; #if ENABLE_EPOLL - struct epoll_event ev; for (i = 0; i < num; i++) { - memset(&ev, 0, sizeof(ev)); - ev.data.u64 = evs[i].data.u64; + struct epoll_event ev = { 0 }; + ev.data.ptr = evs[i].ptr; if (evs[i].events & TVHPOLL_IN) ev.events |= EPOLLIN; if (evs[i].events & TVHPOLL_OUT) ev.events |= EPOLLOUT; if (evs[i].events & TVHPOLL_PRI) ev.events |= EPOLLPRI; @@ -124,7 +123,7 @@ int tvhpoll_add tvhpoll_alloc(tp, num); for (i = 0; i < num; i++) { if (evs[i].events & TVHPOLL_OUT){ - EV_SET(tp->ev+i, evs[i].fd, EVFILT_WRITE, EV_ADD, 0, 0, (intptr_t*)evs[i].data.u64); + EV_SET(tp->ev+i, evs[i].fd, EVFILT_WRITE, EV_ADD, 0, 0, evs[i].ptr); rc = kevent(tp->fd, tp->ev+i, 1, NULL, 0, NULL); if (rc == -1) { tvherror(LS_TVHPOLL, "failed to add kqueue WRITE filter [%d|%d]", @@ -136,7 +135,7 @@ int tvhpoll_add kevent(tp->fd, tp->ev+i, 1, NULL, 0, NULL); } if (evs[i].events & TVHPOLL_IN){ - EV_SET(tp->ev+i, evs[i].fd, EVFILT_READ, EV_ADD, 0, 0, (intptr_t*)evs[i].data.u64); + EV_SET(tp->ev+i, evs[i].fd, EVFILT_READ, EV_ADD, 0, 0, evs[i].ptr); rc = kevent(tp->fd, tp->ev+i, 1, NULL, 0, NULL); if (rc == -1) { tvherror(LS_TVHPOLL, "failed to add kqueue READ filter [%d|%d]", evs[i].fd, rc); @@ -159,7 +158,7 @@ int tvhpoll_add1 tvhpoll_event_t ev = { 0 }; ev.fd = fd; ev.events = events; - ev.data.ptr = ptr; + ev.ptr = ptr; return tvhpoll_add(tp, &ev, 1); } @@ -198,13 +197,16 @@ int tvhpoll_wait #if ENABLE_EPOLL nfds = epoll_wait(tp->fd, tp->ev, num, ms); for (i = 0; i < nfds; i++) { - evs[i].data.u64 = tp->ev[i].data.u64; - evs[i].events = 0; - if (tp->ev[i].events & EPOLLIN) evs[i].events |= TVHPOLL_IN; - if (tp->ev[i].events & EPOLLOUT) evs[i].events |= TVHPOLL_OUT; - if (tp->ev[i].events & EPOLLERR) evs[i].events |= TVHPOLL_ERR; - if (tp->ev[i].events & EPOLLPRI) evs[i].events |= TVHPOLL_PRI; - if (tp->ev[i].events & EPOLLHUP) evs[i].events |= TVHPOLL_HUP; + uint32_t events1 = tp->ev[i].events; + uint32_t events2 = 0; + if (events1 & EPOLLIN) events2 |= TVHPOLL_IN; + if (events1 & EPOLLOUT) events2 |= TVHPOLL_OUT; + if (events1 & EPOLLERR) events2 |= TVHPOLL_ERR; + if (events1 & EPOLLPRI) events2 |= TVHPOLL_PRI; + if (events1 & EPOLLHUP) events2 |= TVHPOLL_HUP; + evs[i].events = events2; + evs[i].fd = -1; + evs[i].ptr = tp->ev[i].data.ptr; } #elif ENABLE_KQUEUE struct timespec tm, *to = NULL; @@ -215,13 +217,14 @@ int tvhpoll_wait } nfds = kevent(tp->fd, NULL, 0, tp->ev, num, to); for (i = 0; i < nfds; i++) { - evs[i].fd = tp->ev[i].ident; - evs[i].events = 0; - evs[i].data.u64 = (intptr_t)tp->ev[i].udata; - if (tp->ev[i].filter == EVFILT_WRITE) evs[i].events |= TVHPOLL_OUT; - if (tp->ev[i].filter == EVFILT_READ) evs[i].events |= TVHPOLL_IN; - if (tp->ev[i].flags & EV_ERROR) evs[i].events |= TVHPOLL_ERR; - if (tp->ev[i].flags & EV_EOF) evs[i].events |= TVHPOLL_HUP; + uint32_t events2 = 0; + if (tp->ev[i].filter == EVFILT_WRITE) events2 |= TVHPOLL_OUT; + if (tp->ev[i].filter == EVFILT_READ) events2 |= TVHPOLL_IN; + if (tp->ev[i].flags & EV_ERROR) events2 |= TVHPOLL_ERR; + if (tp->ev[i].flags & EV_EOF) events2 |= TVHPOLL_HUP; + evs[i].events = events2; + evs[i].fd = -1; /* tp->ev[i].ident */; + evs[i].ptr = tp->ev[i].udata; } #else #endif diff --git a/src/tvhpoll.h b/src/tvhpoll.h index 9035f0c68..9e8ee2602 100644 --- a/src/tvhpoll.h +++ b/src/tvhpoll.h @@ -27,14 +27,9 @@ typedef struct tvhpoll tvhpoll_t; typedef struct tvhpoll_event { - int fd; // input - int events; - union { - void *ptr; - uint64_t u64; - uint32_t u32; - int fd; - } data; + int fd; // input + uint32_t events; + void *ptr; } tvhpoll_event_t; #define TVHPOLL_IN 0x01 diff --git a/src/upnp.c b/src/upnp.c index 161094e7a..e1bbbaf3c 100644 --- a/src/upnp.c +++ b/src/upnp.c @@ -148,12 +148,12 @@ upnp_thread( void *aux ) goto error; memset(&ev, 0, sizeof(ev)); - ev[0].fd = multicast->fd; - ev[0].events = TVHPOLL_IN; - ev[0].data.ptr = multicast; - ev[1].fd = unicast->fd; - ev[1].events = TVHPOLL_IN; - ev[1].data.ptr = unicast; + ev[0].fd = multicast->fd; + ev[0].events = TVHPOLL_IN; + ev[0].ptr = multicast; + ev[1].fd = unicast->fd; + ev[1].events = TVHPOLL_IN; + ev[1].ptr = unicast; tvhpoll_add(poll, ev, 2); delay_ms = 0; @@ -165,7 +165,7 @@ upnp_thread( void *aux ) while (r-- > 0) { if ((ev[r].events & TVHPOLL_IN) != 0) { - conn = ev[r].data.ptr; + conn = ev[r].ptr; iplen = sizeof(ip); size = recvfrom(conn->fd, buf, sizeof(buf), 0, (struct sockaddr *)&ip, &iplen);