]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/backchannel.c
Remove all of the Subversion keywords from various source files.
[thirdparty/cups.git] / cups / backchannel.c
index bdc18edba4ef16181271c86c25ef28766f8d6c8c..c4c96acbe3790743cbb2988d68445ee66b4392dd 100644 (file)
@@ -1,33 +1,16 @@
 /*
- * "$Id: backchannel.c 5099 2006-02-13 02:46:10Z mike $"
+ * Backchannel functions for CUPS.
  *
- *   Backchannel functions for the Common UNIX Printing System (CUPS).
+ * Copyright 2007-2014 by Apple Inc.
+ * Copyright 1997-2007 by Easy Software Products.
  *
- *   Copyright 1997-2005 by Easy Software Products.
+ * 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"
+ * 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/".
  *
- *   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
- *
- *   This file is subject to the Apple OS-Developed Software exception.
- *
- * Contents:
- *
- *   cupsBackChannelRead()  - Read data from the backchannel.
- *   cupsBackChannelWrite() - Write data to the backchannel.
- *   cups_setup()           - Setup select() 
+ * This file is subject to the Apple OS-Developed Software exception.
  */
 
 /*
@@ -55,18 +38,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@
  */
 
-int                                    /* O - Bytes read or -1 on error */
-cupsBackChannelRead(char   *buffer,    /* I - Buffer to read */
-                    int    bytes,      /* I - Bytes to read */
-                   double timeout)     /* I - Timeout in seconds */
+ssize_t                                        /* O - Bytes read or -1 on error */
+cupsBackChannelRead(char   *buffer,    /* I - Buffer to read into */
+                    size_t bytes,      /* I - Bytes to read */
+                   double timeout)     /* I - Timeout in seconds, typically 0.0 to poll */
 {
   fd_set       input;                  /* Input set */
   struct timeval tval;                 /* Timeout value */
@@ -86,7 +68,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! */
@@ -95,32 +77,36 @@ cupsBackChannelRead(char   *buffer, /* I - Buffer to read */
   * Read bytes from the pipe...
   */
 
+#ifdef WIN32
+  return ((ssize_t)_read(3, buffer, (unsigned)bytes));
+#else
   return (read(3, buffer, bytes));
+#endif /* WIN32 */
 }
 
 
 /*
  * '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@
  */
 
-int                                    /* O - Bytes written or -1 on error */
+ssize_t                                        /* O - Bytes written or -1 on error */
 cupsBackChannelWrite(
     const char *buffer,                        /* I - Buffer to write */
-    int        bytes,                  /* I - Bytes to write */
-    double     timeout)                        /* I - Timeout in seconds */
+    size_t     bytes,                  /* I - Bytes to write */
+    double     timeout)                        /* I - Timeout in seconds, typically 1.0 */
 {
   fd_set       output;                 /* Output set */
   struct timeval tval;                 /* Timeout value */
   int          status;                 /* Select status */
-  int          count,                  /* Current bytes */
-               total;                  /* Total bytes */
+  ssize_t      count;                  /* Current bytes */
+  size_t       total;                  /* Total bytes */
 
 
  /*
@@ -144,16 +130,20 @@ 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! */
 
    /*
     * Write bytes to the pipe...
     */
 
+#ifdef WIN32
+    count = (ssize_t)_write(3, buffer, (unsigned)(bytes - total));
+#else
     count = write(3, buffer, bytes - total);
+#endif /* WIN32 */
 
     if (count < 0)
     {
@@ -171,16 +161,16 @@ cupsBackChannelWrite(
       */
 
       buffer += count;
-      total  += count;
+      total  += (size_t)count;
     }
   }
 
-  return (bytes);
+  return ((ssize_t)bytes);
 }
 
 
 /*
- * 'cups_setup()' - Setup select() 
+ * 'cups_setup()' - Setup select()
  */
 
 static void
@@ -194,8 +184,3 @@ cups_setup(fd_set         *set,             /* I - Set for select() */
   FD_ZERO(set);
   FD_SET(3, set);
 }
-
-
-/*
- * End of "$Id: backchannel.c 5099 2006-02-13 02:46:10Z mike $".
- */