| 5860 | */ |
| 5861 | |
| 5862 | static ssize_t /* O - Number of bytes read */ |
| 5863 | ipp_read_http(http_t *http, /* I - Client connection */ |
| 5864 | ipp_uchar_t *buffer, /* O - Buffer for data */ |
| 5865 | size_t length) /* I - Total length */ |
| 5866 | { |
| 5867 | ssize_t tbytes, /* Total bytes read */ |
| 5868 | bytes; /* Bytes read this pass */ |
| 5869 | |
| 5870 | |
| 5871 | DEBUG_printf(("7ipp_read_http(http=%p, buffer=%p, length=%d)", (void *)http, (void *)buffer, (int)length)); |
| 5872 | |
| 5873 | /* |
| 5874 | * Loop until all bytes are read... |
| 5875 | */ |
| 5876 | |
| 5877 | for (tbytes = 0, bytes = 0; |
| 5878 | tbytes < (int)length; |
| 5879 | tbytes += bytes, buffer += bytes) |
| 5880 | { |
| 5881 | DEBUG_printf(("9ipp_read_http: tbytes=" CUPS_LLFMT ", http->state=%d", CUPS_LLCAST tbytes, http->state)); |
| 5882 | |
| 5883 | if (http->state == HTTP_STATE_WAITING) |
| 5884 | break; |
| 5885 | |
| 5886 | if (http->used == 0 && !http->blocking) |
| 5887 | { |
| 5888 | /* |
| 5889 | * Wait up to 10 seconds for more data on non-blocking sockets... |
| 5890 | */ |
| 5891 | |
| 5892 | if (!httpWait(http, 10000)) |
| 5893 | { |
| 5894 | /* |
| 5895 | * Signal no data... |
| 5896 | */ |
| 5897 | |
| 5898 | bytes = -1; |
| 5899 | break; |
| 5900 | } |
| 5901 | } |
| 5902 | else if (http->used == 0 && http->timeout_value > 0) |
| 5903 | { |
| 5904 | /* |
| 5905 | * Wait up to timeout seconds for more data on blocking sockets... |
| 5906 | */ |
| 5907 | |
| 5908 | if (!httpWait(http, (int)(1000 * http->timeout_value))) |
| 5909 | { |
| 5910 | /* |
| 5911 | * Signal no data... |
| 5912 | */ |
| 5913 | |
| 5914 | bytes = -1; |
| 5915 | break; |
| 5916 | } |
| 5917 | } |
| 5918 | |
| 5919 | if ((bytes = httpRead2(http, (char *)buffer, length - (size_t)tbytes)) < 0) |