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>
58 lines
1.7 KiB
C
58 lines
1.7 KiB
C
#ifndef STREAM_H
|
|
#define STREAM_H
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include <sys/types.h>
|
|
#include <sys/socket.h>
|
|
#include <errno.h>
|
|
#define STREAM_CAPACITY 64
|
|
#define STREAM_QUOTA 64
|
|
enum stream_status {
|
|
STREAM_OK = 0,
|
|
STREAM_WAIT = 1,
|
|
STREAM_END = 2,
|
|
STREAM_FAULT = 3,
|
|
STREAM_CLOSED = 4,
|
|
STREAM_INVALID = 5,
|
|
STREAM_FULL = 6,
|
|
STREAM_BUSY = 7
|
|
};
|
|
typedef struct stream_port {
|
|
void *context;
|
|
ssize_t (*send_bytes)(void *, const unsigned char *, size_t, int);
|
|
ssize_t (*recv_bytes)(void *, unsigned char *, size_t, int);
|
|
int (*shutdown_write)(void *);
|
|
} stream_port;
|
|
typedef struct byte_ring {
|
|
unsigned char bytes[STREAM_CAPACITY];
|
|
size_t head;
|
|
size_t size;
|
|
} byte_ring;
|
|
typedef struct stream {
|
|
stream_port port;
|
|
byte_ring outgoing;
|
|
byte_ring incoming;
|
|
unsigned generation;
|
|
int opened;
|
|
int read_end;
|
|
int write_end;
|
|
int last_error;
|
|
uint64_t accepted;
|
|
uint64_t received;
|
|
uint64_t delivered;
|
|
} stream;
|
|
void ring_reset(byte_ring *ring);
|
|
size_t ring_space(const byte_ring *ring);
|
|
size_t ring_copy(const byte_ring *ring, unsigned char *out, size_t limit);
|
|
void ring_append(byte_ring *ring, const unsigned char *data, size_t count);
|
|
void ring_drop(byte_ring *ring, size_t count);
|
|
void stream_init(stream *value, stream_port port);
|
|
int stream_open(stream *value);
|
|
int stream_close(stream *value);
|
|
int stream_queue(stream *value, const unsigned char *bytes, size_t count);
|
|
int stream_take(stream *value, unsigned char *bytes, size_t count, size_t *taken);
|
|
int stream_finish(stream *value);
|
|
int stream_transmit(stream *value, size_t quota, size_t *progress);
|
|
int stream_receive(stream *value, size_t quota, size_t *progress);
|
|
#endif
|