/*
- * "$Id: backchannel.c 6190 2007-01-10 16:48:27Z 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-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
- *
- * 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()
+ * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
*/
/*
*/
#include "cups.h"
+#include "sidechannel.h"
#include <errno.h>
-#ifdef WIN32
+#ifdef _WIN32
# include <io.h>
# include <fcntl.h>
#else
# include <sys/time.h>
-#endif /* WIN32 */
+#endif /* _WIN32 */
/*
/*
* '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/macOS 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 */
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! */
* Read bytes from the pipe...
*/
-#ifdef WIN32
- return ((ssize_t)read(3, buffer, (unsigned)bytes));
+#ifdef _WIN32
+ return ((ssize_t)_read(3, buffer, (unsigned)bytes));
#else
return (read(3, buffer, bytes));
-#endif /* WIN32 */
+#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/macOS 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 */
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));
+#ifdef _WIN32
+ count = (ssize_t)_write(3, buffer, (unsigned)(bytes - total));
#else
count = write(3, buffer, bytes - total);
-#endif /* WIN32 */
+#endif /* _WIN32 */
if (count < 0)
{
* Write error - abort on fatal errors...
*/
- if (errno != EINTR)
+ if (errno != EINTR && errno != EAGAIN)
return (-1);
}
else
*/
buffer += count;
- total += count;
+ total += (size_t)count;
}
}
/*
- * 'cups_setup()' - Setup select()
+ * 'cups_setup()' - Setup select()
*/
static void
FD_ZERO(set);
FD_SET(3, set);
}
-
-
-/*
- * End of "$Id: backchannel.c 6190 2007-01-10 16:48:27Z mike $".
- */