Changeset - 952d4edf0cbb
[Not reviewed]
0 3 6
sirkibsirkib - 5 years ago 2020-02-08 10:35:58
christopher.esterhuyse@gmail.com
first C example
5 files changed:
0 comments (0 inline, 0 general)
examples/0_forward/alice.c
Show inline comments
 
new file 100644
 
#include <stdio.h>
 
#include <string.h>
 
#include "../../reowolf.h"
 

	
 
int main() {
 
	// ALICE
 
	
 
	char* pdl ="\
 
	primitive forward(in i, out o) {\
 
		while(true) synchronous {\
 
			put(o, get(i));\
 
		}\
 
	}";
 
	
 
	
 
	char msg_buf[128];
 
	memset(msg_buf, 0, 128);
 
	
 
	printf("input a message to send:");
 
	if (fgets(msg_buf, 128-1, stdin) == NULL) {
 
		printf("LINE READ BAD\n");
 
		return 1;
 
	}
 
	int msg_len = strlen(msg_buf);
 
	msg_buf[msg_len-1] = 0;
 
	printf("sending msg `%s`\n", msg_buf);
 
	
 
	Connector* c = connector_new();
 
	if (connector_configure(c, pdl, "forward")) {
 
		printf("CONFIG FAILED: %s\n", connector_error_peek());
 
		return 1;
 
	}
 
	if (connector_bind_native(c, 0)) {
 
		printf("BIND0 FAILED: %s\n", connector_error_peek());
 
		return 1;
 
	}
 
	if (connector_bind_passive(c, 1, "127.0.0.1:7000")) {
 
		printf("BIND1 FAILED: %s\n", connector_error_peek());
 
		return 1;
 
	}
 
	printf("connecting... \n");
 
	if (connector_connect(c, 10000)) {
 
		printf("CONNECT FAILED: %s\n", connector_error_peek());
 
		return 1;
 
	}
 
	
 
	int i;
 
	for (i = 0; i < 3; i++) {
 
		if (connector_put(c, 0, msg_buf, msg_len)) {
 
			printf("CONNECT PUT: %s\n", connector_error_peek());
 
			return 1;
 
		}
 
		if (connector_sync(c, 10000)) {
 
			printf("SYNC FAILED: %s\n", connector_error_peek());
 
			return 1;
 
		}
 
		printf("SEND OK\n");
 
	}
 
	
 
	printf("OK\n");
 
	connector_destroy(c);
 
	return 0;
 
}
 
\ No newline at end of file
examples/0_forward/alice.exe
Show inline comments
 
new file 100644
 
binary diff not shown
examples/0_forward/bob.c
Show inline comments
 
new file 100644
 
#include <stdio.h>
 
#include "../../reowolf.h"
 

	
 
int main() {
 
	
 
	char* pdl ="\
 
	primitive forward(in i, out o) {\
 
		while(true) synchronous {\
 
			put(o, get(i));\
 
		}\
 
	}";
 
	
 
	// BOB
 
	Connector* c = connector_new();
 
	if (connector_configure(c, pdl, "forward")) {
 
		printf("CONFIG FAILED: %s\n", connector_error_peek());
 
		return 1;
 
	}
 
	if (connector_bind_active(c, 0, "127.0.0.1:7000")) {
 
		printf("BIND0 FAILED: %s\n", connector_error_peek());
 
		return 1;
 
	}
 
	if (connector_bind_native(c, 1)) {
 
		printf("BIND1 FAILED: %s\n", connector_error_peek());
 
		return 1;
 
	}
 
	printf("connecting... \n");
 
	if (connector_connect(c, 10000)) {
 
		printf("CONNECT FAILED: %s\n", connector_error_peek());
 
		return 1;
 
	}
 
	
 
	int i;
 
	for (i = 0; i < 3; i++) {
 
		if (connector_get(c, 0)) {
 
			printf("CONNECT GET: %s\n", connector_error_peek());
 
			return 1;
 
		}
 
		if (connector_sync(c, 10000)) {
 
			printf("SYNC FAILED: %s\n", connector_error_peek());
 
			return 1;
 
		}
 
		int msg_len;
 
		const unsigned char * msg;
 
		if (connector_gotten(c, 0, &msg, &msg_len)) {
 
			printf("READ FAILED: %s\n", connector_error_peek());
 
			return 1;
 
		}
 
		printf("received: `%s`\n", msg);
 
	}
 
	
 
	printf("OK\n");
 
	connector_destroy(c);
 
	return 0;
 
}
 
\ No newline at end of file
examples/0_forward/bob.exe
Show inline comments
 
new file 100644
 
binary diff not shown
examples/0_forward/make.sh
Show inline comments
 
new file 100644
 
echo "MAKING!"
 
gcc main.c -L ../../target/release -lreowolf_rs -o main
 
echo "DONE!"

Changeset was too big and was cut off... Show full diff anyway

0 comments (0 inline, 0 general)