| 93 | */ |
| 94 | |
| 95 | ssize_t /* O - Bytes written or -1 on error */ |
| 96 | cupsBackChannelWrite( |
| 97 | const char *buffer, /* I - Buffer to write */ |
| 98 | size_t bytes, /* I - Bytes to write */ |
| 99 | double timeout) /* I - Timeout in seconds, typically 1.0 */ |
| 100 | { |
| 101 | fd_set output; /* Output set */ |
| 102 | struct timeval tval; /* Timeout value */ |
| 103 | int status; /* Select status */ |
| 104 | ssize_t count; /* Current bytes */ |
| 105 | size_t total; /* Total bytes */ |
| 106 | |
| 107 | |
| 108 | /* |
| 109 | * Write all bytes... |
| 110 | */ |
| 111 | |
| 112 | total = 0; |
| 113 | |
| 114 | while (total < bytes) |
| 115 | { |
| 116 | /* |
| 117 | * Wait for write-ready... |
| 118 | */ |
| 119 | |
| 120 | do |
| 121 | { |
| 122 | cups_setup(&output, &tval, timeout); |
| 123 | |
| 124 | if (timeout < 0.0) |
| 125 | status = select(4, NULL, &output, NULL, NULL); |
| 126 | else |
| 127 | status = select(4, NULL, &output, NULL, &tval); |
| 128 | } |
| 129 | while (status < 0 && errno != EINTR && errno != EAGAIN); |
| 130 | |
| 131 | if (status <= 0) |
| 132 | return (-1); /* Timeout! */ |
| 133 | |
| 134 | /* |
| 135 | * Write bytes to the pipe... |
| 136 | */ |
| 137 | |
| 138 | #ifdef _WIN32 |
| 139 | count = (ssize_t)_write(3, buffer, (unsigned)(bytes - total)); |
| 140 | #else |
| 141 | count = write(3, buffer, bytes - total); |
| 142 | #endif /* _WIN32 */ |
| 143 | |
| 144 | if (count < 0) |
| 145 | { |
| 146 | /* |
| 147 | * Write error - abort on fatal errors... |
| 148 | */ |
| 149 | |
| 150 | if (errno != EINTR && errno != EAGAIN) |
| 151 | return (-1); |
| 152 | } |
no test coverage detected