master uint/libule / tests / ulepipe_test.c
 1#include <stdio.h>
 2#include <stdlib.h>
 3#include <string.h>
 4
 5#include "ulepipe.h"
 6
 7#define sockpath "/tmp/ulepipe_test.sock"
 8
 9enum type {
10	TEST_STOP,
11	TEST_NAME_CHANGE,
12} type;
13
14typedef struct {
15	int       x, y;
16	char      name[64];
17	enum type type;
18} some_data_layout;
19
20some_data_layout data;
21char name[64] = { 0 };
22
23int main(void)
24{
25	ulepipe master = { 0 };
26	ulepipe_open(&master, sockpath);
27	if (master.fd < 0)
28		return EXIT_FAILURE;
29	
30	for (;;) {
31		ssize_t n = ulepipe_receive(&master, &data, sizeof(data));
32		if (!(n == sizeof(data))) {
33			printf("received data too small\n");
34			continue;
35		}
36		
37		switch (data.type) {
38		case TEST_STOP:
39			printf("received stop\n");
40			fflush(stdout);
41			goto end;
42		case TEST_NAME_CHANGE:
43			printf("received name_change\n");
44			fflush(stdout);
45			strncpy(name, data.name, 64);
46		default:
47			continue;
48			break;
49		}
50	}
51	
52end:
53	printf("%s\n", name);
54
55	ulepipe_close(&master);
56	return EXIT_SUCCESS;
57}
58