]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/backchannel.c
Update svn:keyword properties.
[thirdparty/cups.git] / cups / backchannel.c
index cfb22aa5cbb1c8126bfca4137ad34c39d75a9ca1..7fa8c97f5c468ff68d9f8d38f9d63f0787e18cbd 100644 (file)
@@ -1,25 +1,16 @@
 /*
- * "$Id: backchannel.c 6190 2007-01-10 16:48:27Z mike $"
+ * "$Id$"
  *
- *   Backchannel functions for the Common UNIX Printing System (CUPS).
+ *   Backchannel functions for CUPS.
  *
+ *   Copyright 2007-2012 by Apple Inc.
  *   Copyright 1997-2007 by Easy Software Products.
  *
  *   These coded instructions, statements, and computer programs are the
- *   property of Easy Software Products and are protected by Federal
- *   copyright law.  Distribution and use rights are outlined in the file
- *   "LICENSE.txt" which should have been included with this file.  If this
- *   file is missing or damaged please contact Easy Software Products
- *   at:
- *
- *       Attn: CUPS Licensing Information
- *       Easy Software Products
- *       44141 Airport View Drive, Suite 204
- *       Hollywood, Maryland 20636 USA
- *
- *       Voice: (301) 373-9600
- *       EMail: cups-info@cups.org
- *         WWW: http://www.cups.org
+ *   property of Apple Inc. and are protected by Federal copyright
+ *   law.  Distribution and use rights are outlined in the file "LICENSE.txt"
+ *   which should have been included with this file.  If this file is
+ *   file is missing or damaged, see the license at "http://www.cups.org/".
  *
  *   This file is subject to the Apple OS-Developed Software exception.
  *
@@ -27,7 +18,7 @@
  *
  *   cupsBackChannelRead()  - Read data from the backchannel.
  *   cupsBackChannelWrite() - Write data to the backchannel.
- *   cups_setup()           - Setup select() 
+ *   cups_setup()           - Setup select()
  */
 
 /*
@@ -55,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 */
@@ -86,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! */
@@ -96,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 */
@@ -106,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 */
@@ -148,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! */
 
    /*
@@ -158,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 */
@@ -169,7 +159,7 @@ cupsBackChannelWrite(
       * Write error - abort on fatal errors...
       */
 
-      if (errno != EINTR)
+      if (errno != EINTR && errno != EAGAIN)
         return (-1);
     }
     else
@@ -188,7 +178,7 @@ cupsBackChannelWrite(
 
 
 /*
- * 'cups_setup()' - Setup select() 
+ * 'cups_setup()' - Setup select()
  */
 
 static void
@@ -205,5 +195,5 @@ cups_setup(fd_set         *set,             /* I - Set for select() */
 
 
 /*
- * End of "$Id: backchannel.c 6190 2007-01-10 16:48:27Z mike $".
+ * End of "$Id$".
  */