| 632 | */ |
| 633 | |
| 634 | void |
| 635 | httpFlush(http_t *http) /* I - HTTP connection */ |
| 636 | { |
| 637 | char buffer[8192]; /* Junk buffer */ |
| 638 | int blocking; /* To block or not to block */ |
| 639 | http_state_t oldstate; /* Old state */ |
| 640 | |
| 641 | |
| 642 | DEBUG_printf(("httpFlush(http=%p), state=%s", (void *)http, httpStateString(http->state))); |
| 643 | |
| 644 | /* |
| 645 | * Nothing to do if we are in the "waiting" state... |
| 646 | */ |
| 647 | |
| 648 | if (http->state == HTTP_STATE_WAITING) |
| 649 | return; |
| 650 | |
| 651 | /* |
| 652 | * Temporarily set non-blocking mode so we don't get stuck in httpRead()... |
| 653 | */ |
| 654 | |
| 655 | blocking = http->blocking; |
| 656 | http->blocking = 0; |
| 657 | |
| 658 | /* |
| 659 | * Read any data we can... |
| 660 | */ |
| 661 | |
| 662 | oldstate = http->state; |
| 663 | while (httpRead2(http, buffer, sizeof(buffer)) > 0); |
| 664 | |
| 665 | /* |
| 666 | * Restore blocking and reset the connection if we didn't get all of |
| 667 | * the remaining data... |
| 668 | */ |
| 669 | |
| 670 | http->blocking = blocking; |
| 671 | |
| 672 | if (http->state == oldstate && http->state != HTTP_STATE_WAITING && |
| 673 | http->fd >= 0) |
| 674 | { |
| 675 | /* |
| 676 | * Didn't get the data back, so close the current connection. |
| 677 | */ |
| 678 | |
| 679 | #ifdef HAVE_LIBZ |
| 680 | if (http->coding) |
| 681 | http_content_coding_finish(http); |
| 682 | #endif /* HAVE_LIBZ */ |
| 683 | |
| 684 | DEBUG_puts("1httpFlush: Setting state to HTTP_STATE_WAITING and closing."); |
| 685 | |
| 686 | http->state = HTTP_STATE_WAITING; |
| 687 | |
| 688 | #ifdef HAVE_TLS |
| 689 | if (http->tls) |
| 690 | _httpTLSStop(http); |
| 691 | #endif /* HAVE_TLS */ |