| 905 | } |
| 906 | |
| 907 | bool HTTPClient::SendRequest(std::string_view request) |
| 908 | { |
| 909 | const auto deadline{std::chrono::steady_clock::now() + m_timeout}; |
| 910 | |
| 911 | while (!request.empty()) { |
| 912 | Sock::Event event{0}; |
| 913 | auto time_left = std::chrono::duration_cast<std::chrono::milliseconds>( |
| 914 | deadline - std::chrono::steady_clock::now()); |
| 915 | if (time_left.count() <= 0 || !m_socket->Wait(time_left, Sock::SendEvent, &event)) { |
| 916 | return false; |
| 917 | } |
| 918 | |
| 919 | if (!(event & Sock::SendEvent)) { |
| 920 | continue; |
| 921 | } |
| 922 | |
| 923 | ssize_t sent = m_socket->Send(request.data(), request.size(), MSG_NOSIGNAL); |
| 924 | if (sent < 0) { |
| 925 | int err = WSAGetLastError(); |
| 926 | if (!IOErrorIsPermanent(err)) { |
| 927 | std::this_thread::yield(); |
| 928 | continue; |
| 929 | } |
| 930 | return false; |
| 931 | } |
| 932 | request.remove_prefix(sent); |
| 933 | } |
| 934 | return true; |
| 935 | } |
| 936 | |
| 937 | HTTPResponse HTTPClient::ReadResponse() |
| 938 | { |