commit 63187b6

uint  ·  2026-10-30 13:12:16 +0000 UTC
parent 529a451
Pipe: Add test master program
1 files changed,  +42, -6
+42, -6
 1@@ -1,17 +1,53 @@
 2+#include <stdio.h>
 3 #include <stdlib.h>
 4+#include <string.h>
 5 
 6 #include "ulepipe.h"
 7 
 8-struct {
 9-	int   x;
10-	int   y;
11-	int   z;
12-	char* name;
13-} state = { 0 };
14+#define sockpath "/tmp/ulepipe_test.sock"
15+
16+enum type {
17+	TEST_STOP,
18+	TEST_NAME_CHANGE,
19+} type;
20+
21+typedef struct {
22+	int       x, y;
23+	char      name[64];
24+	enum type type;
25+} some_data_layout;
26+
27+some_data_layout data;
28+char name[64] = { 0 };
29 
30 int main(void)
31 {
32 	ulepipe master = { 0 };
33+	ulepipe_open(&master, sockpath);
34+	if (master.fd < 0)
35+		return EXIT_FAILURE;
36+	
37+	for (;;) {
38+		ssize_t n = ulepipe_recieve(&master, &data, sizeof(data));
39+		if (!(n == sizeof(data))) {
40+			printf("recieved data too small\n");
41+			continue;
42+		}
43+		
44+		switch (data.type) {
45+		case TEST_STOP:
46+			goto end;
47+		case TEST_NAME_CHANGE:
48+			strncpy(name, data.name, 64);
49+		default:
50+			continue;
51+			break;
52+		}
53+	}
54+	
55+end:
56+	printf("%s", data.name);
57+
58 	return EXIT_SUCCESS;
59 }
60