]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - backend/runloop.c
Remove support for AIX, HP-UX, and OSF/1.
[thirdparty/cups.git] / backend / runloop.c
index 43b83999639d1760fdca3276ddaaa398f96661fe..6e717e8ccf0f0fa17558ab15e80f5bad8d0a081c 100644 (file)
@@ -1,25 +1,18 @@
 /*
- * "$Id: runloop.c 9565 2011-02-23 00:08:08Z mike $"
+ * "$Id$"
  *
- *   Common run loop APIs for CUPS backends.
+ * Common run loop APIs for CUPS backends.
  *
- *   Copyright 2007-2011 by Apple Inc.
- *   Copyright 2006-2007 by Easy Software Products, all rights reserved.
+ * Copyright 2007-2013 by Apple Inc.
+ * Copyright 2006-2007 by Easy Software Products, all rights reserved.
  *
- *   These coded instructions, statements, and computer programs are the
- *   property of Apple Inc. and are protected by Federal copyright
- *   law.  Distribution and use rights are outlined in the file "LICENSE.txt"
- *   "LICENSE" which should have been included with this file.  If this
- *   file is missing or damaged, see the license at "http://www.cups.org/".
+ * These coded instructions, statements, and computer programs are the
+ * property of Apple Inc. and are protected by Federal copyright
+ * law.  Distribution and use rights are outlined in the file "LICENSE.txt"
+ * "LICENSE" which should have been included with this file.  If this
+ * file is missing or damaged, see the license at "http://www.cups.org/".
  *
- *   This file is subject to the Apple OS-Developed Software exception.
- *
- * Contents:
- *
- *   backendDrainOutput() - Drain pending print data to the device.
- *   backendRunLoop()     - Read and write print and back-channel data.
- *   backendWaitLoop()    - Wait for input from stdin while handling
- *                          side-channel queries.
+ * This file is subject to the Apple OS-Developed Software exception.
  */
 
 /*
 
 #include "backend-private.h"
 #include <limits.h>
-#ifdef __hpux
-#  include <sys/time.h>
-#else
-#  include <sys/select.h>
-#endif /* __hpux */
+#include <sys/select.h>
 
 
 /*
@@ -92,7 +81,8 @@ backendDrainOutput(int print_fd,      /* I - Print file descriptor */
 
       if (errno != EAGAIN || errno != EINTR)
       {
-        _cupsLangPrintError("ERROR", _("Unable to read print data"));
+       fprintf(stderr, "DEBUG: Read failed: %s\n", strerror(errno));
+       _cupsLangPrintFilter(stderr, "ERROR", _("Unable to read print data."));
        return (-1);
       }
 
@@ -250,7 +240,7 @@ backendRunLoop(
        {
          fputs("STATE: +offline-report\n", stderr);
          _cupsLangPrintFilter(stderr, "INFO",
-                              _("Printer is not currently connected."));
+                              _("The printer is not connected."));
          offline = 1;
        }
        else if (errno == EINTR && total_bytes == 0)
@@ -319,7 +309,9 @@ backendRunLoop(
 
        if (errno != EAGAIN || errno != EINTR)
        {
-         _cupsLangPrintError("ERROR", _("Unable to read print data"));
+         fprintf(stderr, "DEBUG: Read failed: %s\n", strerror(errno));
+         _cupsLangPrintFilter(stderr, "ERROR",
+                              _("Unable to read print data."));
          return (-1);
        }
 
@@ -368,7 +360,7 @@ backendRunLoop(
          {
            fputs("STATE: +offline-report\n", stderr);
            _cupsLangPrintFilter(stderr, "INFO",
-                                _("Printer is not currently connected."));
+                                _("The printer is not connected."));
            offline = 1;
          }
        }
@@ -389,7 +381,8 @@ backendRunLoop(
        if (offline && update_state)
        {
          fputs("STATE: -offline-report\n", stderr);
-         _cupsLangPrintFilter(stderr, "INFO", _("Printer is now connected."));
+         _cupsLangPrintFilter(stderr, "INFO",
+                              _("The printer is now connected."));
          offline = 0;
        }
 
@@ -434,12 +427,11 @@ backendWaitLoop(
     int          use_bc,               /* I - Use back-channel? */
     _cups_sccb_t side_cb)              /* I - Side-channel callback */
 {
-  fd_set       input;                  /* Input set for reading */
-  time_t       curtime,                /* Current time */
-               snmp_update = 0;
-#if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
-  struct sigaction action;             /* Actions for POSIX signals */
-#endif /* HAVE_SIGACTION && !HAVE_SIGSET */
+  int                  nfds;           /* Number of file descriptors */
+  fd_set               input;          /* Input set for reading */
+  time_t               curtime = 0,    /* Current time */
+                       snmp_update = 0;/* Last SNMP status update */
+  struct timeval       timeout;        /* Timeout for select() */
 
 
   fprintf(stderr, "DEBUG: backendWaitLoop(snmp_fd=%d, addr=%p, side_cb=%p)\n",
@@ -449,6 +441,9 @@ backendWaitLoop(
   * Now loop until we receive data from stdin...
   */
 
+  if (snmp_fd >= 0)
+    snmp_update = time(NULL) + 5;
+
   for (;;)
   {
    /*
@@ -460,7 +455,18 @@ backendWaitLoop(
     if (side_cb)
       FD_SET(CUPS_SC_FD, &input);
 
-    if (select(CUPS_SC_FD + 1, &input, NULL, NULL, NULL) < 0)
+    if (snmp_fd >= 0)
+    {
+      curtime         = time(NULL);
+      timeout.tv_sec  = curtime >= snmp_update ? 0 : snmp_update - curtime;
+      timeout.tv_usec = 0;
+
+      nfds = select(CUPS_SC_FD + 1, &input, NULL, NULL, &timeout);
+    }
+    else
+      nfds = select(CUPS_SC_FD + 1, &input, NULL, NULL, NULL);
+
+    if (nfds < 0)
     {
      /*
       * Pause printing to clear any pending errors...
@@ -504,10 +510,10 @@ backendWaitLoop(
     * Do SNMP updates periodically...
     */
 
-    if (snmp_fd >= 0 && time(&curtime) >= snmp_update)
+    if (snmp_fd >= 0 && curtime >= snmp_update)
     {
       if (backendSNMPSupplies(snmp_fd, addr, NULL, NULL))
-        snmp_update = INT_MAX;
+        snmp_fd = -1;
       else
         snmp_update = curtime + 5;
     }
@@ -522,5 +528,5 @@ backendWaitLoop(
 
 
 /*
- * End of "$Id: runloop.c 9565 2011-02-23 00:08:08Z mike $".
+ * End of "$Id$".
  */