/*
- * "$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>
/*
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);
}
{
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)
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);
}
{
fputs("STATE: +offline-report\n", stderr);
_cupsLangPrintFilter(stderr, "INFO",
- _("Printer is not currently connected."));
+ _("The printer is not connected."));
offline = 1;
}
}
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;
}
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",
* Now loop until we receive data from stdin...
*/
+ if (snmp_fd >= 0)
+ snmp_update = time(NULL) + 5;
+
for (;;)
{
/*
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...
* 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;
}
/*
- * End of "$Id: runloop.c 9565 2011-02-23 00:08:08Z mike $".
+ * End of "$Id$".
*/