Changeset - 49b9c766fe5a
[Not reviewed]
3 5 3
Christopher Esterhuyse - 5 years ago 2020-02-10 11:35:57
christopheresterhuyse@gmail.com
tracking new channel ekeys
7 files changed:
0 comments (0 inline, 0 general)
examples/0_forward/alice
Show inline comments
 
new file 100755
 
binary diff not shown
examples/0_forward/alice.c
Show inline comments
 
#include <stdio.h>
 
#include <string.h>
 
#include "../../reowolf.h"
 
#include "../check.c"
 

	
 
int main() {
 
	// ALICE
 
	
 
	char* pdl ="\
 
	primitive forward(in i, out o) {\
 
		while(true) synchronous {\
 
			put(o, get(i));\
 
		}\
 
	}";
 
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;
 
	}
 

	
 
	check("fgets", fgets(msg_buf, 128-1, stdin) == NULL);
 
	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;
 
	}
 
	check("config ", connector_configure(c, pdl, "forward"));
 
	check("bind 0 ", connector_bind_native(c, 0));
 
	check("bind 1 ", connector_bind_passive(c, 1, "127.0.0.1:7000"));
 
	check("connect", connector_connect(c, 10000));
 
	
 
	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;
 
		}
 
		check("put ", connector_put(c, 0, msg_buf, msg_len));
 
		check("sync", connector_sync(c, 10000));
 
		printf("SEND OK\n");
 
	}
 
	
examples/0_forward/alice.exe
Show inline comments
 
deleted file
 
binary diff not shown
examples/0_forward/bob
Show inline comments
 
new file 100755
 
binary diff not shown
examples/0_forward/bob.c
Show inline comments
 
#include <stdio.h>
 
#include "../../reowolf.h"
 
#include "../check.c"
 

	
 
int main() {
 
	
 
@@ -12,40 +13,20 @@ int main() {
 
	
 
	// 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;
 
	}
 
	check("config ", connector_configure(c, pdl, "forward"));
 
	check("bind 0 ", connector_bind_active(c, 0, "127.0.0.1:7000"));
 
	check("bind 1 ", connector_bind_native(c, 1));
 
	check("connect", connector_connect(c, 10000));
 
	
 
	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;
 
		}
 
		check("get ", connector_get(c, 0));
 
		check("sync", connector_sync(c, 10000));
 

	
 
		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;
 
		}
 
		check("read", connector_gotten(c, 0, &msg, &msg_len));
 

	
 
		printf("received: `%s`\n", msg);
 
	}
 
	
examples/0_forward/bob.exe
Show inline comments
 
deleted file
 
binary diff not shown
examples/0_forward/make.sh
Show inline comments
 
modified file chmod 100644 => 100755
 
echo "MAKING!"
 
gcc main.c -L ../../target/release -lreowolf_rs -o main
 
echo "DONE!"
 
#!/bin/sh
 

	
 
LIB_PATH="../../target/release"
 
gcc -L $LIB_PATH -lreowolf_rs -Wl,-R$LIB_PATH alice.c -o alice
 
gcc -L $LIB_PATH -lreowolf_rs -Wl,-R$LIB_PATH bob.c -o bob

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

0 comments (0 inline, 0 general)