summaryrefslogtreecommitdiff
path: root/backend/runloop.c
diff options
context:
space:
mode:
authormsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>2012-03-30 05:59:14 +0000
committermsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>2012-03-30 05:59:14 +0000
commit82cc1f9ac32564e92bfbbe7a1de416f4ebcc8584 (patch)
treeaf43377451e06dac91d6639e35b1b5bf41d14d4e /backend/runloop.c
parent3e7fe0ca760ad0054cf5c9ec7c90ca415cf6eb06 (diff)
downloadcups-82cc1f9ac32564e92bfbbe7a1de416f4ebcc8584.tar.gz
Merge changes from CUPS 1.6svn-r10390.
git-svn-id: svn+ssh://src.apple.com/svn/cups/easysw/current@3755 a1ca3aef-8c08-0410-bb20-df032aa958be
Diffstat (limited to 'backend/runloop.c')
-rw-r--r--backend/runloop.c30
1 files changed, 23 insertions, 7 deletions
diff --git a/backend/runloop.c b/backend/runloop.c
index 227883bfa..777b04801 100644
--- a/backend/runloop.c
+++ b/backend/runloop.c
@@ -3,7 +3,7 @@
*
* Common run loop APIs for CUPS backends.
*
- * Copyright 2007-2011 by Apple Inc.
+ * Copyright 2007-2012 by Apple Inc.
* Copyright 2006-2007 by Easy Software Products, all rights reserved.
*
* These coded instructions, statements, and computer programs are the
@@ -434,9 +434,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; /* Last SNMP status update */
+ 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",
@@ -446,6 +448,9 @@ backendWaitLoop(
* Now loop until we receive data from stdin...
*/
+ if (snmp_fd >= 0)
+ snmp_update = time(NULL) + 5;
+
for (;;)
{
/*
@@ -457,7 +462,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...
@@ -501,10 +517,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;
}