| 4738 | */ |
| 4739 | |
| 4740 | static ssize_t /* O - Number of bytes written */ |
| 4741 | http_write(http_t *http, /* I - HTTP connection */ |
| 4742 | const char *buffer, /* I - Buffer for data */ |
| 4743 | size_t length) /* I - Number of bytes to write */ |
| 4744 | { |
| 4745 | ssize_t tbytes, /* Total bytes sent */ |
| 4746 | bytes; /* Bytes sent */ |
| 4747 | |
| 4748 | |
| 4749 | DEBUG_printf(("7http_write(http=%p, buffer=%p, length=" CUPS_LLFMT ")", (void *)http, (void *)buffer, CUPS_LLCAST length)); |
| 4750 | http->error = 0; |
| 4751 | tbytes = 0; |
| 4752 | |
| 4753 | while (length > 0) |
| 4754 | { |
| 4755 | DEBUG_printf(("8http_write: About to write %d bytes.", (int)length)); |
| 4756 | |
| 4757 | if (http->timeout_value > 0.0) |
| 4758 | { |
| 4759 | #ifdef HAVE_POLL |
| 4760 | struct pollfd pfd; /* Polled file descriptor */ |
| 4761 | #else |
| 4762 | fd_set output_set; /* Output ready for write? */ |
| 4763 | struct timeval timeout; /* Timeout value */ |
| 4764 | #endif /* HAVE_POLL */ |
| 4765 | int nfds; /* Result from select()/poll() */ |
| 4766 | |
| 4767 | do |
| 4768 | { |
| 4769 | #ifdef HAVE_POLL |
| 4770 | pfd.fd = http->fd; |
| 4771 | pfd.events = POLLOUT; |
| 4772 | |
| 4773 | while ((nfds = poll(&pfd, 1, http->wait_value)) < 0 && |
| 4774 | (errno == EINTR || errno == EAGAIN)) |
| 4775 | /* do nothing */; |
| 4776 | |
| 4777 | #else |
| 4778 | do |
| 4779 | { |
| 4780 | FD_ZERO(&output_set); |
| 4781 | FD_SET(http->fd, &output_set); |
| 4782 | |
| 4783 | timeout.tv_sec = http->wait_value / 1000; |
| 4784 | timeout.tv_usec = 1000 * (http->wait_value % 1000); |
| 4785 | |
| 4786 | nfds = select(http->fd + 1, NULL, &output_set, NULL, &timeout); |
| 4787 | } |
| 4788 | # ifdef _WIN32 |
| 4789 | while (nfds < 0 && (WSAGetLastError() == WSAEINTR || |
| 4790 | WSAGetLastError() == WSAEWOULDBLOCK)); |
| 4791 | # else |
| 4792 | while (nfds < 0 && (errno == EINTR || errno == EAGAIN)); |
| 4793 | # endif /* _WIN32 */ |
| 4794 | #endif /* HAVE_POLL */ |
| 4795 | |
| 4796 | if (nfds < 0) |
| 4797 | { |
no test coverage detected