]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
tvhpoll: cleanups, use only 'ptr' for identification
authorJaroslav Kysela <perex@perex.cz>
Sat, 30 Dec 2017 16:59:38 +0000 (17:59 +0100)
committerJaroslav Kysela <perex@perex.cz>
Thu, 4 Jan 2018 14:03:22 +0000 (15:03 +0100)
14 files changed:
src/dbus.c
src/descrambler/capmt.c
src/descrambler/cclient.c
src/httpc.c
src/input/mpegts/iptv/iptv.c
src/input/mpegts/linuxdvb/linuxdvb_ca.c
src/input/mpegts/linuxdvb/linuxdvb_frontend.c
src/input/mpegts/satip/satip_frontend.c
src/input/mpegts/tvhdhomerun/tvhdhomerun_frontend.c
src/spawn.c
src/tcp.c
src/tvhpoll.c
src/tvhpoll.h
src/upnp.c

index 30223e3a81f90460ad80008375239e7ad61fca93..d74c0b29a3f84b1c6f5016462486e9f670c6093e 100644 (file)
@@ -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);
index a77e15fc910c14c1e6a56b16ac8f72bb8ebb9c43..8f27477c22068fd71e98bb07ba89cdf3d45a1f56 100644 (file)
@@ -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);
index 3ce2c2bdd4b936fdde298f14de22a3e0dae84ab1..737a05502919cdf474a111519080a70dfe2901c9 100644 (file)
@@ -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;
index c6651040989825fee16f1db010bc1b85d43b1488..e0afaaba0c730284fcc2a3bc10cc8c48dd0056e8 100644 (file)
@@ -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;
         }
index 9fda8f466604bc0220c0221878562a07ab6d0383..e2bf280730946cce01e4b382d559e032846d9400 100644 (file)
@@ -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);
index cf7b3e9d56a0a99c1121f6aa80a1f00531acf6a6..e5ca45a3b1a8ed149bc2be879a9229ffb0f8476f 100644 (file)
@@ -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);
index 1ff5e6b6f7ea4701287acf5c38d3911603bcf64c..fcc7b8cb96f8911c56ca32661d98d8affd4b800e 100644 (file)
@@ -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;
index 99f45455c42d8b5bb03b761e9d0c24cc1463042f..8d3f24d5bd807b4bea2a64f4236a9a409b9278b9 100644 (file)
@@ -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);
index 4b39fad38b5c9fe753906cbac42e0bb1e6bbf411..eb2db76dcff0033341e8a5fc938afb77012e0afe 100644 (file)
@@ -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 */
index 3c6757690475821e8fd74942650ba70aa40f3d31..13afa12ad4b1a879eacff1a77715b4ec9f54d0cb 100644 (file)
@@ -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)) {
index 1e4e16f23ea5244f5546962782b2a8bb9570acae..7fd31363de7f8e9d050080e39f3d5cca53ed38b4 100644 (file)
--- 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);
index 4b8f119f3afb0d63c32e27f9308b9980896fd960..8803e0bd1d9d15b881c4a3b256b6333c90cfd331 100644 (file)
@@ -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
index 9035f0c6860a4bf8a7b8e1843f7883a67e3ba6a0..9e8ee26028970a1e730dcd20e8318757db024d4c 100644 (file)
 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
index 161094e7a5e27d20373550e6c536ce9a4f48538e..e1bbbaf3ccd0f2c76753f5e507ac5bec21ab9d6c 100644 (file)
@@ -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);