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

Function cupsSideChannelRead

cups/sidechannel.c:94–268  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

92 */
93
94int /* O - 0 on success, -1 on error */
95cupsSideChannelRead(
96 cups_sc_command_t *command, /* O - Command code */
97 cups_sc_status_t *status, /* O - Status code */
98 char *data, /* O - Data buffer pointer */
99 int *datalen, /* IO - Size of data buffer on entry, number of bytes in buffer on return */
100 double timeout) /* I - Timeout in seconds */
101{
102 char *buffer; /* Message buffer */
103 ssize_t bytes; /* Bytes read */
104 int templen; /* Data length from message */
105 int nfds; /* Number of file descriptors */
106#ifdef HAVE_POLL
107 struct pollfd pfd; /* Poll structure for poll() */
108#else /* select() */
109 fd_set input_set; /* Input set for select() */
110 struct timeval stimeout; /* Timeout value for select() */
111#endif /* HAVE_POLL */
112
113
114 DEBUG_printf(("cupsSideChannelRead(command=%p, status=%p, data=%p, "
115 "datalen=%p(%d), timeout=%.3f)", command, status, data,
116 datalen, datalen ? *datalen : -1, timeout));
117
118 /*
119 * Range check input...
120 */
121
122 if (!command || !status)
123 return (-1);
124
125 /*
126 * See if we have pending data on the side-channel socket...
127 */
128
129#ifdef HAVE_POLL
130 pfd.fd = CUPS_SC_FD;
131 pfd.events = POLLIN;
132
133 while ((nfds = poll(&pfd, 1,
134 timeout < 0.0 ? -1 : (int)(timeout * 1000))) < 0 &&
135 (errno == EINTR || errno == EAGAIN))
136 ;
137
138#else /* select() */
139 FD_ZERO(&input_set);
140 FD_SET(CUPS_SC_FD, &input_set);
141
142 stimeout.tv_sec = (int)timeout;
143 stimeout.tv_usec = (int)(timeout * 1000000) % 1000000;
144
145 while ((nfds = select(CUPS_SC_FD + 1, &input_set, NULL, NULL,
146 timeout < 0.0 ? NULL : &stimeout)) < 0 &&
147 (errno == EINTR || errno == EAGAIN))
148 ;
149
150#endif /* HAVE_POLL */
151

Callers 7

backendNetworkSideCBFunction · 0.85
sidechannel_threadFunction · 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