MCPcopy Create free account
hub / github.com/OpenPrinting/cups / cupsSideChannelWrite

Function cupsSideChannelWrite

cups/sidechannel.c:519–617  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

517 */
518
519int /* O - 0 on success, -1 on error */
520cupsSideChannelWrite(
521 cups_sc_command_t command, /* I - Command code */
522 cups_sc_status_t status, /* I - Status code */
523 const char *data, /* I - Data buffer pointer */
524 int datalen, /* I - Number of bytes of data */
525 double timeout) /* I - Timeout in seconds */
526{
527 char *buffer; /* Message buffer */
528 ssize_t bytes; /* Bytes written */
529#ifdef HAVE_POLL
530 struct pollfd pfd; /* Poll structure for poll() */
531#else /* select() */
532 fd_set output_set; /* Output set for select() */
533 struct timeval stimeout; /* Timeout value for select() */
534#endif /* HAVE_POLL */
535
536
537 /*
538 * Range check input...
539 */
540
541 if (command < CUPS_SC_CMD_SOFT_RESET || command >= CUPS_SC_CMD_MAX ||
542 datalen < 0 || datalen > _CUPS_SC_MAX_DATA || (datalen > 0 && !data))
543 return (-1);
544
545 /*
546 * See if we can safely write to the side-channel socket...
547 */
548
549#ifdef HAVE_POLL
550 pfd.fd = CUPS_SC_FD;
551 pfd.events = POLLOUT;
552
553 if (timeout < 0.0)
554 {
555 if (poll(&pfd, 1, -1) < 1)
556 return (-1);
557 }
558 else if (poll(&pfd, 1, (int)(timeout * 1000)) < 1)
559 return (-1);
560
561#else /* select() */
562 FD_ZERO(&output_set);
563 FD_SET(CUPS_SC_FD, &output_set);
564
565 if (timeout < 0.0)
566 {
567 if (select(CUPS_SC_FD + 1, NULL, &output_set, NULL, NULL) < 1)
568 return (-1);
569 }
570 else
571 {
572 stimeout.tv_sec = (int)timeout;
573 stimeout.tv_usec = (int)(timeout * 1000000) % 1000000;
574
575 if (select(CUPS_SC_FD + 1, NULL, &output_set, NULL, &stimeout) < 1)
576 return (-1);

Callers 9

backendNetworkSideCBFunction · 0.85
print_deviceFunction · 0.85
sidechannel_threadFunction · 0.85
print_deviceFunction · 0.85
sidechannel_threadFunction · 0.85
side_cbFunction · 0.85
cupsSideChannelDoRequestFunction · 0.85
cupsSideChannelSNMPGetFunction · 0.85
cupsSideChannelSNMPWalkFunction · 0.85

Calls 2

_cupsBufferGetFunction · 0.85
_cupsBufferReleaseFunction · 0.85

Tested by

no test coverage detected