amos 8b7616bfd8 Batch 22 (20261027-C-hwe-hard-22): add 63 calibrated HWE hard-design tasks
From the 101 lk/man/pth code-gen sources: 63 tasks (C11 36, C++17 27,
11 canonical families), 38 skipped for scope or duplication. Each task
has at least one independent contract-edge defect, boundary types
rotate, and public docs state trap clauses as plain contract prose.
Claude reviewed 63/63 USABLE against current digests. Difficulty is
unmeasured.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 16:14:57 +08:00

44 lines
1.3 KiB
C

#include "stream.h"
#include <errno.h>
int stream_transmit(stream *value, size_t quota, size_t *progress)
{
unsigned char window[STREAM_CAPACITY];
*progress = 0;
if (quota > STREAM_QUOTA) {
return STREAM_INVALID;
}
if (!value->opened || value->write_end) {
return STREAM_CLOSED;
}
while (*progress < quota && value->outgoing.size != 0) {
size_t request = quota - *progress;
ssize_t result;
if (request > value->outgoing.size) {
request = value->outgoing.size;
}
ring_copy(&value->outgoing, window, request);
result = value->port.send_bytes(value->port.context, window,
request, 0);
if (result > 0) {
size_t committed = (size_t)result;
ring_drop(&value->outgoing, committed);
value->accepted += committed;
*progress += committed;
continue;
}
if (result == 0) {
return STREAM_WAIT;
}
if (errno == EINTR) {
continue;
}
if (errno == EAGAIN) {
return STREAM_WAIT;
}
value->last_error = errno;
value->write_end = 1;
return STREAM_FAULT;
}
return STREAM_OK;
}