25 if (
reinterpret_cast<uintptr_t
>(
src) < 0x40200000) {
26 std::memcpy(dst,
src,
len);
43 for (
int i = 0; i <
count; i++) {
44 total += iov[i].iov_len;
52 while (
count > 0 && sent >= iov->iov_len) {
58 iov->iov_base =
static_cast<char *
>(iov->iov_base) + sent;
67static constexpr int STREAM_HEAD_MAX_IOV = 24;
70inline bool has_header(std::span<const HttpHeader> headers,
const char *
name) {
71 for (
const auto &header : headers) {
72 if (strcasecmp(
name, header.name) == 0) {
83template<
typename Iovec,
typename Send>
84bool write_stream_head(Send &&send,
const char *status,
const char *content_type, std::span<const HttpHeader> headers,
85 std::span<const HttpHeader> default_headers,
const char *body) {
90 Iovec iov[STREAM_HEAD_MAX_IOV];
93 if (this->ok && this->
count > 0) {
94 this->ok = this->send(this->iov, this->
count);
98 void add(
const char *buf,
size_t len) {
99 if (this->
count == STREAM_HEAD_MAX_IOV) {
102 this->iov[this->
count++] = {
const_cast<char *
>(buf),
len};
104 void add(
const char *str) { this->add(str, strlen(str)); }
106 this->add(
"\r\n", 2);
107 this->add(header.
name);
109 this->add(header.
value);
113 batch.add(
"HTTP/1.1 ", 9);
115 batch.add(
"\r\nContent-Type: ", 16);
116 batch.add(content_type);
117 for (
const auto &header : headers) {
118 batch.add_header(header);
120 for (
const auto &header : default_headers) {
122 batch.add_header(header);
125 batch.add(
"\r\n\r\n", 4);
126 if (body !=
nullptr) {
134static constexpr uint8_t STREAM_ADD_FLAG_COPY = 0x01;
135static constexpr uint8_t STREAM_ADD_FLAG_MORE = 0x02;
140template<
typename Client,
typename Iovec>
147 const size_t piece = std::min(iov[i].iov_len - offset, scratch_size - fill);
151 if (offset == iov[i].iov_len) {
155 if (fill < scratch_size && i <
count) {
158 const uint8_t
flags = STREAM_ADD_FLAG_COPY | (i <
count ? STREAM_ADD_FLAG_MORE : 0);
How long sends have made no progress.
void start(uint32_t now)
Starts the clock; a running clock keeps its start time.
bool start_or_expired(uint32_t now, uint32_t timeout_ms)
Starts the clock if needed; true once it has run for timeout_ms.
uint32_t elapsed(uint32_t now) const
bool is_expired(uint32_t now, uint32_t timeout_ms) const
True once the clock has run for timeout_ms.
size_t iovecs_total(const Iovec *iov, int count)
Bytes in a gather list.
char name[sizeof(ORIGIN)]
constexpr size_t stream_head_iov_count(size_t header_count)
Pieces in a head: 4 for the status line and Content-Type, 4 per header, the blank line and the body.
void stream_memcpy(void *dst, const void *src, size_t len)
bool has_header(std::span< const HttpHeader > headers, const char *name)
True if headers holds a header named name, compared case insensitively.
void advance_iovecs(Iovec *&iov, int &count, size_t sent)
Drops the first sent bytes from a gather list after a write; a short write resumes inside the element...
bool write_stream_head(Send &&send, const char *status, const char *content_type, std::span< const HttpHeader > headers, std::span< const HttpHeader > default_headers, const char *body)
Gathers the head of a stream response: "HTTP/1.1 <status>", Content-Type, headers,...
size_t add_iovecs(Client &client, const Iovec *iov, int count, char *scratch, size_t scratch_size)
Queues a gather list on an AsyncClient-like client through scratch, so each add() carries up to scrat...