]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/backchannel.c
Update svn:keyword properties.
[thirdparty/cups.git] / cups / backchannel.c
index 9b702172f34c1caebae45f61892d2352a9931848..7fa8c97f5c468ff68d9f8d38f9d63f0787e18cbd 100644 (file)
@@ -1,9 +1,9 @@
 /*
- * "$Id: backchannel.c 6649 2007-07-11 21:46:42Z mike $"
+ * "$Id$"
  *
- *   Backchannel functions for the Common UNIX Printing System (CUPS).
+ *   Backchannel functions for CUPS.
  *
- *   Copyright 2007 by Apple Inc.
+ *   Copyright 2007-2012 by Apple Inc.
  *   Copyright 1997-2007 by Easy Software Products.
  *
  *   These coded instructions, statements, and computer programs are the
@@ -18,7 +18,7 @@
  *
  *   cupsBackChannelRead()  - Read data from the backchannel.
  *   cupsBackChannelWrite() - Write data to the backchannel.
- *   cups_setup()           - Setup select() 
+ *   cups_setup()           - Setup select()
  */
 
 /*
@@ -46,18 +46,17 @@ static void cups_setup(fd_set *set, struct timeval *tval,
 /*
  * 'cupsBackChannelRead()' - Read data from the backchannel.
  *
- * Reads up to "bytes" bytes from the backchannel. The "timeout"
- * parameter controls how many seconds to wait for the data - use
- * 0.0 to return immediately if there is no data, -1.0 to wait
- * for data indefinitely.
+ * Reads up to "bytes" bytes from the backchannel/backend. The "timeout"
+ * parameter controls how many seconds to wait for the data - use 0.0 to
+ * return immediately if there is no data, -1.0 to wait for data indefinitely.
  *
- * @since CUPS 1.2@
+ * @since CUPS 1.2/OS X 10.5@
  */
 
 ssize_t                                        /* O - Bytes read or -1 on error */
-cupsBackChannelRead(char   *buffer,    /* I - Buffer to read */
+cupsBackChannelRead(char   *buffer,    /* I - Buffer to read into */
                     size_t bytes,      /* I - Bytes to read */
-                   double timeout)     /* I - Timeout in seconds */
+                   double timeout)     /* I - Timeout in seconds, typically 0.0 to poll */
 {
   fd_set       input;                  /* Input set */
   struct timeval tval;                 /* Timeout value */
@@ -77,7 +76,7 @@ cupsBackChannelRead(char   *buffer,   /* I - Buffer to read */
     else
       status = select(4, &input, NULL, NULL, &tval);
   }
-  while (status < 0 && errno != EINTR);
+  while (status < 0 && errno != EINTR && errno != EAGAIN);
 
   if (status < 0)
     return (-1);                       /* Timeout! */
@@ -87,7 +86,7 @@ cupsBackChannelRead(char   *buffer,   /* I - Buffer to read */
   */
 
 #ifdef WIN32
-  return ((ssize_t)read(3, buffer, (unsigned)bytes));
+  return ((ssize_t)_read(3, buffer, (unsigned)bytes));
 #else
   return (read(3, buffer, bytes));
 #endif /* WIN32 */
@@ -97,19 +96,19 @@ cupsBackChannelRead(char   *buffer, /* I - Buffer to read */
 /*
  * 'cupsBackChannelWrite()' - Write data to the backchannel.
  *
- * Writes "bytes" bytes to the backchannel. The "timeout" parameter
+ * Writes "bytes" bytes to the backchannel/filter. The "timeout" parameter
  * controls how many seconds to wait for the data to be written - use
  * 0.0 to return immediately if the data cannot be written, -1.0 to wait
  * indefinitely.
  *
- * @since CUPS 1.2@
+ * @since CUPS 1.2/OS X 10.5@
  */
 
 ssize_t                                        /* O - Bytes written or -1 on error */
 cupsBackChannelWrite(
     const char *buffer,                        /* I - Buffer to write */
     size_t     bytes,                  /* I - Bytes to write */
-    double     timeout)                        /* I - Timeout in seconds */
+    double     timeout)                        /* I - Timeout in seconds, typically 1.0 */
 {
   fd_set       output;                 /* Output set */
   struct timeval tval;                 /* Timeout value */
@@ -139,9 +138,9 @@ cupsBackChannelWrite(
       else
        status = select(4, NULL, &output, NULL, &tval);
     }
-    while (status < 0 && errno != EINTR);
+    while (status < 0 && errno != EINTR && errno != EAGAIN);
 
-    if (status < 0)
+    if (status <= 0)
       return (-1);                     /* Timeout! */
 
    /*
@@ -149,7 +148,7 @@ cupsBackChannelWrite(
     */
 
 #ifdef WIN32
-    count = (ssize_t)write(3, buffer, (unsigned)(bytes - total));
+    count = (ssize_t)_write(3, buffer, (unsigned)(bytes - total));
 #else
     count = write(3, buffer, bytes - total);
 #endif /* WIN32 */
@@ -160,7 +159,7 @@ cupsBackChannelWrite(
       * Write error - abort on fatal errors...
       */
 
-      if (errno != EINTR)
+      if (errno != EINTR && errno != EAGAIN)
         return (-1);
     }
     else
@@ -179,7 +178,7 @@ cupsBackChannelWrite(
 
 
 /*
- * 'cups_setup()' - Setup select() 
+ * 'cups_setup()' - Setup select()
  */
 
 static void
@@ -196,5 +195,5 @@ cups_setup(fd_set         *set,             /* I - Set for select() */
 
 
 /*
- * End of "$Id: backchannel.c 6649 2007-07-11 21:46:42Z mike $".
+ * End of "$Id$".
  */