| 3036 | */ |
| 3037 | |
| 3038 | int /* O - 1 if data is available, 0 otherwise */ |
| 3039 | _httpWait(http_t *http, /* I - HTTP connection */ |
| 3040 | int msec, /* I - Milliseconds to wait */ |
| 3041 | int usessl) /* I - Use SSL context? */ |
| 3042 | { |
| 3043 | #ifdef HAVE_POLL |
| 3044 | struct pollfd pfd; /* Polled file descriptor */ |
| 3045 | #else |
| 3046 | fd_set input_set; /* select() input set */ |
| 3047 | struct timeval timeout; /* Timeout */ |
| 3048 | #endif /* HAVE_POLL */ |
| 3049 | int nfds; /* Result from select()/poll() */ |
| 3050 | |
| 3051 | |
| 3052 | DEBUG_printf(("4_httpWait(http=%p, msec=%d, usessl=%d)", (void *)http, msec, usessl)); |
| 3053 | |
| 3054 | if (http->fd < 0) |
| 3055 | { |
| 3056 | DEBUG_printf(("5_httpWait: Returning 0 since fd=%d", http->fd)); |
| 3057 | return (0); |
| 3058 | } |
| 3059 | |
| 3060 | /* |
| 3061 | * Check the SSL/TLS buffers for data first... |
| 3062 | */ |
| 3063 | |
| 3064 | #ifdef HAVE_TLS |
| 3065 | if (usessl && http->tls && _httpTLSPending(http)) |
| 3066 | { |
| 3067 | DEBUG_puts("5_httpWait: Return 1 since there is pending TLS data."); |
| 3068 | return (1); |
| 3069 | } |
| 3070 | #endif /* HAVE_TLS */ |
| 3071 | |
| 3072 | /* |
| 3073 | * Then try doing a select() or poll() to poll the socket... |
| 3074 | */ |
| 3075 | |
| 3076 | #ifdef HAVE_POLL |
| 3077 | pfd.fd = http->fd; |
| 3078 | pfd.events = POLLIN; |
| 3079 | |
| 3080 | do |
| 3081 | { |
| 3082 | nfds = poll(&pfd, 1, msec); |
| 3083 | } |
| 3084 | while (nfds < 0 && (errno == EINTR || errno == EAGAIN)); |
| 3085 | |
| 3086 | #else |
| 3087 | do |
| 3088 | { |
| 3089 | FD_ZERO(&input_set); |
| 3090 | FD_SET(http->fd, &input_set); |
| 3091 | |
| 3092 | DEBUG_printf(("6_httpWait: msec=%d, http->fd=%d", msec, http->fd)); |
| 3093 | |
| 3094 | if (msec >= 0) |
| 3095 | { |
no test coverage detected