summary refs log tree commit diff
path: root/child.c
diff options
context:
space:
mode:
authorrubin <rubinowyblask@meow.li>2026-05-22 16:23:18 +0200
committerrubin <rubinowyblask@meow.li>2026-05-22 16:23:18 +0200
commit89abeab564abac85e0cd33e8e6333193cb9cbe9f (patch)
tree38514de46959461d9b7f001aadcebc88423d0aa3 /child.c
parent7c8712572a48ad88e05b205edeaece5cfba8040a (diff)
merge aura_addbufferdata with meowiero
Signed-off-by: rubin <rubinowyblask@meow.li>
Diffstat (limited to 'child.c')
-rw-r--r--child.c35
1 files changed, 15 insertions, 20 deletions
diff --git a/child.c b/child.c
index 58ee999..34b086e 100644
--- a/child.c
+++ b/child.c
@@ -19,35 +19,30 @@ struct ConnectionData {
 };
 
 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;