From 89abeab564abac85e0cd33e8e6333193cb9cbe9f Mon Sep 17 00:00:00 2001 From: rubin Date: Fri, 22 May 2026 16:23:18 +0200 Subject: merge aura_addbufferdata with meowiero Signed-off-by: rubin --- child.c | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/child.c b/child.c index 58ee999..34b086e 100644 --- a/child.c +++ b/child.c @@ -18,36 +18,31 @@ struct ConnectionData { struct ConnectionDataBuffer *buffer; }; -static int -aura_addbufferdata(struct ConnectionDataBuffer *buffer, char *data, size_t length) -{ - if (buffer->length + length > buffer->capacity) { - aura_printf("FUCK!\n"); - aura_printf("buffer->length: %ld\n", buffer->length); - aura_printf("buffer->capacity: %ld\n", buffer->capacity); - aura_printf("length: %ld\n", length); - - abort(); - } - - memcpy(buffer->buf, data, length); - buffer->length = buffer->length + length; - - return 0; -} - static int meowiero(struct FDWatchHandle *handle, enum FDWatch_EventType type, int fd, void *data) { struct ConnectionData *connectiondata = (struct ConnectionData *)data; + ssize_t readSize = 0; char c = 0; switch (type) { case FDWATCH_EVENT_INP: aura_printf("INPUT event in fd:%d\n", fd); - read(fd, &c, 2); - aura_addbufferdata(connectiondata->buffer, &c, 2); + readSize = read(fd, &connectiondata->buffer->buf[connectiondata->buffer->length], + connectiondata->buffer->capacity - connectiondata->buffer->length); + + connectiondata->buffer->length = connectiondata->buffer->length + readSize; + printf("%ld\n", readSize); + if (errno != 0) { + perror("read(2)"); + abort(); + } + + if (connectiondata->buffer->length == connectiondata->buffer->capacity) { + aura_printf("Too much unread data!\n"); + abort(); + } aura_printf("%c\n", c); break; -- cgit 1.4.1