| 3196 | */ |
| 3197 | |
| 3198 | ssize_t /* O - Number of bytes written */ |
| 3199 | httpWrite2(http_t *http, /* I - HTTP connection */ |
| 3200 | const char *buffer, /* I - Buffer for data */ |
| 3201 | size_t length) /* I - Number of bytes to write */ |
| 3202 | { |
| 3203 | ssize_t bytes; /* Bytes written */ |
| 3204 | |
| 3205 | |
| 3206 | DEBUG_printf(("httpWrite2(http=%p, buffer=%p, length=" CUPS_LLFMT ")", (void *)http, (void *)buffer, CUPS_LLCAST length)); |
| 3207 | |
| 3208 | /* |
| 3209 | * Range check input... |
| 3210 | */ |
| 3211 | |
| 3212 | if (!http || !buffer) |
| 3213 | { |
| 3214 | DEBUG_puts("1httpWrite2: Returning -1 due to bad input."); |
| 3215 | return (-1); |
| 3216 | } |
| 3217 | |
| 3218 | /* |
| 3219 | * Mark activity on the connection... |
| 3220 | */ |
| 3221 | |
| 3222 | http->activity = time(NULL); |
| 3223 | |
| 3224 | /* |
| 3225 | * Buffer small writes for better performance... |
| 3226 | */ |
| 3227 | |
| 3228 | #ifdef HAVE_LIBZ |
| 3229 | if (http->coding == _HTTP_CODING_GZIP || http->coding == _HTTP_CODING_DEFLATE) |
| 3230 | { |
| 3231 | DEBUG_printf(("1httpWrite2: http->coding=%d", http->coding)); |
| 3232 | |
| 3233 | if (length == 0) |
| 3234 | { |
| 3235 | http_content_coding_finish(http); |
| 3236 | bytes = 0; |
| 3237 | } |
| 3238 | else |
| 3239 | { |
| 3240 | size_t slen; /* Bytes to write */ |
| 3241 | ssize_t sret; /* Bytes written */ |
| 3242 | |
| 3243 | ((z_stream *)http->stream)->next_in = (Bytef *)buffer; |
| 3244 | ((z_stream *)http->stream)->avail_in = (uInt)length; |
| 3245 | |
| 3246 | while (deflate((z_stream *)http->stream, Z_NO_FLUSH) == Z_OK) |
| 3247 | { |
| 3248 | DEBUG_printf(("1httpWrite2: avail_out=%d", ((z_stream *)http->stream)->avail_out)); |
| 3249 | |
| 3250 | if (((z_stream *)http->stream)->avail_out > 0) |
| 3251 | continue; |
| 3252 | |
| 3253 | slen = _HTTP_MAX_SBUFFER - ((z_stream *)http->stream)->avail_out; |
| 3254 | |
| 3255 | DEBUG_printf(("1httpWrite2: Writing intermediate chunk, len=%d", (int)slen)); |
no test coverage detected