Changeset - a286c28bcdcf
[Not reviewed]
6 4 6
Christopher Esterhuyse - 5 years ago 2020-05-04 13:19:30
christopher.esterhuyse@gmail.com
new examples
13 files changed with 100 insertions and 143 deletions:
0 comments (0 inline, 0 general)
examples/2_dynamic_pdl/amy.c
Show inline comments
 
@@ -8,13 +8,13 @@ int main() {
 
	// Protocol is loaded from file.
 
	char * pdl = buffer_pdl("eg_protocols.pdl");
 
	
 
	// create a connector with one outgoing network channel.
 
	Connector* c = connector_new();
 
	printf("configuring...\n");
 
	check("config ", connector_configure(c, pdl, "forward"));
 
	check("config ", connector_configure(c, pdl, "dynamic"));
 
	check("bind 0 ", connector_bind_native(c, 0));
 
	check("bind 1 ", connector_bind_passive(c, 1, "127.0.0.1:7000"));
 
	printf("connecting...\n");
 
	check("connect", connector_connect(c, 5000));
 
	
 
	// send "hello" message three times
examples/3_atomicity/amy.c
Show inline comments
 
new file 100644
 
#include <stdio.h>
 
#include <stdlib.h>
 
#include <string.h>
 
#include "../../reowolf.h"
 
#include "../utility.c"
 

	
 
int main() { // AMY
 
	char * pdl = buffer_pdl("eg_protocols.pdl");
 
	
 
	Connector* c = connector_new();
 
	printf("configuring...\n");
 

	
 
	check("config ", connector_configure(c, pdl, "sync_two"));
 
	check("bind 0 ", connector_bind_native(c, 0));
 
	check("bind 1 ", connector_bind_native(c, 1));
 
	check("bind 2 ", connector_bind_passive(c, 2, "127.0.0.1:7000"));
 
	check("bind 3 ", connector_bind_passive(c, 3, "127.0.0.1:7001"));
 
	printf("connecting...\n");
 
	check("connect", connector_connect(c, 5000));
 

	
 
	int round, code;
 
	for(round = 0; true; round++) {
 
		printf("\nround %d\n", round);
 

	
 
		check("put  ", connector_put(c, 0, "one", 3));
 
		check("put  ", connector_put(c, 1, "two", 3));
 
		check("sync ", connector_sync(c, 10000));
 
	}
 
	
 
	printf("cleaning up...\n");
 
	connector_destroy(c);
 
	free(pdl);
 
	return 0;
 
}
 
\ No newline at end of file
examples/3_atomicity/bob.c
Show inline comments
 
file renamed from examples/4_atomicity/bob.c to examples/3_atomicity/bob.c
 
@@ -31,13 +31,13 @@ int main() {
 
				continue;
 
			}
 
		}
 
		printf("Receiving messages [%c, %c]\n", yn[0], yn[1]);
 
		if (yn[0] == 'y') check("get first  ", connector_get(c, 0));
 
		if (yn[1] == 'y') check("get second ", connector_get(c, 1));
 
		check("sync ", connector_sync(c, 3000));
 
		check("sync ", connector_sync(c, 1000));
 
		for (i = 0; i < 2; i++) {
 
			if (yn[i] == 'y') {
 
				check("read ", connector_gotten(c, i, &msg, &msg_len));
 
				printf("Got %s msg `%.*s`\n", nth[i], msg_len, msg);
 
			}
 
		}
examples/3_atomicity/make.sh
Show inline comments
 
file renamed from examples/3_nondeterminism/make.sh to examples/3_atomicity/make.sh
examples/3_nondeterminism/amy.c
Show inline comments
 
deleted file
examples/3_nondeterminism/bob.c
Show inline comments
 
deleted file
examples/4_atomicity/make.sh
Show inline comments
 
deleted file
examples/4_nondeterminism/amy.c
Show inline comments
 
new file 100644
 
#include <stdio.h>
 
#include <stdlib.h>
 
#include <string.h>
 
#include "../../reowolf.h"
 
#include "../utility.c"
 

	
 
int main() { // AMY
 
	char * pdl = buffer_pdl("eg_protocols.pdl");
 
	
 
	Connector* c = connector_new();
 
	printf("configuring...\n");
 

	
 
	check("config ", connector_configure(c, pdl, "sync_two"));
 
	check("bind 0 ", connector_bind_native(c, 0));
 
	check("bind 1 ", connector_bind_native(c, 1));
 
	check("bind 2 ", connector_bind_passive(c, 2, "127.0.0.1:7000"));
 
	check("bind 3 ", connector_bind_passive(c, 3, "127.0.0.1:7001"));
 
	printf("connecting...\n");
 
	check("connect", connector_connect(c, 5000));
 

	
 
	int round, code;
 
	for(round = 0; true; round++) {
 
		printf("\nround %d\n", round);
 
	
 
		check("next ", connector_next_batch(c));
 
		check("put  ", connector_put(c, 0, "one", 3));
 
		check("put  ", connector_put(c, 1, "two", 3));
 
		code = connector_sync(c, 3000);
 
		check("sync ", code);
 
		if(code == 0)      printf("sent neither message!");
 
		else               printf("sent both messages!");
 
	}
 
	
 
	printf("cleaning up...\n");
 
	connector_destroy(c);
 
	free(pdl);
 
	return 0;
 
}
 
\ No newline at end of file
examples/4_nondeterminism/make.sh
Show inline comments
 
new file 100644
 
#!/bin/sh
 

	
 
LIB_PATH="../"
 
gcc -L $LIB_PATH -lreowolf_rs -Wl,-R$LIB_PATH amy.c -o amy
 
\ No newline at end of file
examples/5_recovery/amy.c
Show inline comments
 
file renamed from examples/4_atomicity/amy.c to examples/5_recovery/amy.c
 
@@ -15,32 +15,26 @@ int main() { // AMY
 
	check("bind 1 ", connector_bind_native(c, 1));
 
	check("bind 2 ", connector_bind_passive(c, 2, "127.0.0.1:7000"));
 
	check("bind 3 ", connector_bind_passive(c, 3, "127.0.0.1:7001"));
 
	printf("connecting...\n");
 
	check("connect", connector_connect(c, 5000));
 

	
 
	int i, code;
 
	while (1) {
 
		printf("\nround %d\n", i);
 
	int round, code;
 
	for(round = 0; true; round++) {
 
		printf("\nround %d\n", round);
 
	
 
		// batch 0: no messages sent
 
		check("next_batch ", connector_next_batch(c));
 
		
 
		// batch 1: put 0 and put 1
 
		check("next ", connector_next_batch(c));
 
		check("put  ", connector_put(c, 0, "one", 3));
 
		check("put  ", connector_put(c, 1, "two", 3));
 
		code = connector_sync(c, 3000);
 
		
 
		if (code == 0) printf("Sent neither message!");
 
		else if (code == 1) printf("Sent both messages!");
 
		else if (code == -1) printf("Sync failed!\n");
 
		if(code == 0)       printf("sent neither message!");
 
		else if(code == 1 ) printf("sent both messages!");
 
		else if(code == -1) printf("No interaction! Recovered state.\n");
 
		else {
 
			printf(
 
				"Connector error! %d (%s)\nBreaking loop!\n",
 
				code, connector_error_peek()
 
			);
 
			printf("Unrecoverable error!\n");
 
			connector_dump_log(c);
 
			break;
 
		}
 
	}
 
	
 
	printf("cleaning up...\n");
 
	connector_destroy(c);
examples/5_recovery/bob.c
Show inline comments
 
@@ -31,29 +31,27 @@ int main() {
 
				continue;
 
			}
 
		}
 
		printf("Receiving messages [%c, %c]\n", yn[0], yn[1]);
 
		if (yn[0] == 'y') check("get first  ", connector_get(c, 0));
 
		if (yn[1] == 'y') check("get second ", connector_get(c, 1));
 
			
 
		code = connector_sync(c, 1000);
 
		if (code == 0) printf("sync succeeded!\n");
 
		else if (code == -1) {
 
			printf("sync failed; state recovered!\n");
 
			continue;
 
		} else {
 
			printf("Unrecoverable error! code %d\n", code);
 
			connector_dump_log(c);
 
		}
 
		
 
		if(code >= 0) {
 
			for (i = 0; i < 2; i++) {
 
				if (yn[i] == 'y') {
 
				check("read ", connector_gotten(c, i, &msg, &msg_len));
 
					printf("Got %s msg `%.*s`\n", nth[i], msg_len, msg);
 
				}
 
			}
 
		} else if(code == -1) {
 
			printf("No interaction! Recovered state.\n");
 
		} else {
 
			printf("Unrecoverable error!\n");
 
			connector_dump_log(c);
 
			break;
 
		}
 
	}
 

	
 
	printf("cleaning up\n");
 
	connector_destroy(c);
 
	free(pdl);
 
	return 0;
examples/5_recovery/make.sh
Show inline comments
 
#!/bin/sh
 

	
 
LIB_PATH="../"
 
gcc -L $LIB_PATH -lreowolf_rs -Wl,-R$LIB_PATH amy.c -o amy
 
gcc -L $LIB_PATH -lreowolf_rs -Wl,-R$LIB_PATH bob.c -o bob
examples/eg_protocols.pdl
Show inline comments
 

	
 
primitive forward(in i, out o) {
 
	while(true) synchronous {
 
		put(o, get(i));
 
	}
 
}
 
composite dynamic(in i, out o) {
 
	new forward(i, o);
 
}
 
primitive sync(in i, out o) {
 
	while(true) synchronous {
 
		if(fires(i)) {
 
			put(o, get(i));
 
		}
 
	}
 
@@ -17,19 +21,12 @@ primitive sync_two(in ia, in ib, out oa, out ob) {
 
			put(oa, get(ia));
 
			put(ob, get(ib));
 
		}
 
	}
 
}
 

	
 
composite bob3(in i, out o) {
 
	new sync(i, o);
 
}
 
composite bob5(in i, out o) {
 
	new sync(i, o);
 
}
 

	
 
primitive xor_three(in ai, out ao, in bi, out bo, in ci, out co) {
 
	synchronous {
 
		if      (fires(ai)) put(ao, get(ai));
 
		else if (fires(bi)) put(bo, get(bi));
 
		else                put(co, get(ci)); 
 
	}
0 comments (0 inline, 0 general)