diff --git a/examples/3_nondeterminism/bob.c b/examples/3_nondeterminism/bob.c index 60981663b22bc66ea5cee6806e55ec2d5bed4d5a..5ece1f5b47085cbb8ab3d97ac1a107387f629398 100644 --- a/examples/3_nondeterminism/bob.c +++ b/examples/3_nondeterminism/bob.c @@ -1,40 +1,46 @@ #include -#include #include "../../reowolf.h" #include "../utility.c" +// bob indefinitely chooses between receiving or not receiving a message (user inputs y/n) int main() { - char * pdl = buffer_pdl("eg_protocols.pdl"); Connector* c = connector_new(); printf("configuring...\n"); - check("config ", connector_configure(c, pdl, "sync")); + char * pdl = buffer_pdl("eg_protocols.pdl"); + check("config ", connector_configure(c, pdl, "bob3")); check("bind 0 ", connector_bind_active(c, 0, "127.0.0.1:7000")); check("bind 1 ", connector_bind_native(c, 1)); + printf("connecting...\n"); check("connect", connector_connect(c, 5000)); - int msg_len, i; const unsigned char * msg; - srand(time(NULL)); - for (i = 0; i < 10; i++) { + int i, code, msg_len; + char yn; + + for (i = 0; true; i++) { printf("\nround %d...\n", i); - int random = rand() % 2; - if (random == 0) { - printf("I don't want a message!\n"); - check("sync", connector_sync(c, 1000)); + printf("Should I receive a message? (y/n): "); + scanf(" %c", &yn); + if (yn == 'y') { + printf("OK! Let's receive a message!\n"); + connector_get(c, 0); + } else if (yn == 'n') { + printf("OK! Let's NOT receive a message!\n"); } else { - printf("I want a message!\n"); - check("get ", connector_get(c, 0)); - check("sync", connector_sync(c, 1000)); - check("read msg", connector_gotten(c, 0, &msg, &msg_len)); + printf("Expected (y/n) input!"); + continue; + } + check("sync ", connector_sync(c, 1000)); + if (yn == 'y') { + check("read ", connector_gotten(c, 0, &msg, &msg_len)); printf("Got message: `%.*s`\n", msg_len, msg); } } - - printf("destroying...\n"); + + printf("cleaning up\n"); connector_destroy(c); - printf("exiting...\n"); free(pdl); return 0; } \ No newline at end of file