Commits

Markus Tzoe committed 75fa644

nshandle: eliminate poll

  • Participants
  • Parent commits ec07991

Comments (0)

Files changed (1)

File src/reporter.c

     socklen_t len = sizeof(faddr);
     struct report report;
     memset(&report, 0, sizeof(struct report));
-    struct pollfd fds;
-    fds.fd = fd;
-    fds.events = POLLIN | POLLPRI;
-    int ret = poll(&fds, 1, 5);
-    if (ret == -1 || ret == 0) {
+    int ret;
+    while ((ret = recvfrom(fd, &report, sizeof(struct report), 0, (struct sockaddr *)&faddr, &len)) == -1 && errno == EAGAIN);
+    if (ret == -1)
+    {
+        my_syslog(LOG_ERR, _("%d: accept_report: unkonw error: %d"), now, errno);
         return;
     }
-    if(fds.revents & (POLLIN | POLLPRI)){
-        if (recvfrom(fd, &report, sizeof(struct report), 0, (struct sockaddr *)&faddr, &len) == -1)
-        {
-            my_syslog(LOG_ERR, _("%d: accept_report: unkonw error: %d"), now, errno);
-            return;
-        }
 
-        if(inet_ntop(faddr.sin_family, &faddr.sin_addr, daemon->addrbuff, ADDRSTRLEN) == NULL) {
-            my_syslog(LOG_ERR, ("%d: inet_ntop() error. abort cache insertion."), now);
-            return;
-        }
+    if(inet_ntop(faddr.sin_family, &faddr.sin_addr, daemon->addrbuff, ADDRSTRLEN) == NULL) {
+        my_syslog(LOG_ERR, ("%d: inet_ntop() error. abort cache insertion."), now);
+        return;
+    }
 
-        if(report.proto != RPRT_PRNO){
-            report.flags |= RPRT_ABRT;
-        }
-        else {
-            report.flags &= 0x0F;
-            report.flags |= RPRT_OKAY;
-        
-            /*if (report.flags & RPRT_PULL)
-            {
-                //my_syslog(LOG_INFO, _("flag: PULL"));
-            }*/
+    if(report.proto != RPRT_PRNO){
+        report.flags |= RPRT_ABRT;
+    }
+    else {
+        report.flags &= 0x0F;
+        report.flags |= RPRT_OKAY;
+    
+        /*if (report.flags & RPRT_PULL)
+        {
+            //my_syslog(LOG_INFO, _("flag: PULL"));
+        }*/
 
-            if (RPRT_PUSH & report.flags)
-            {
-                write_record(&report, &faddr);
-            }
-        }
-        
-        if (RPRT_ACKN & report.flags)
+        if (RPRT_PUSH & report.flags)
         {
-            reply_ack(fd, &report, (struct sockaddr *)&faddr);
+            write_record(&report, &faddr);
         }
     }
+    
+    if (RPRT_ACKN & report.flags)
+    {
+        reply_ack(fd, &report, (struct sockaddr *)&faddr);
+    }
+
 }