Skip to content

Commit

Permalink
Tidy up async test outputs.
Browse files Browse the repository at this point in the history
  • Loading branch information
ralight committed Nov 6, 2019
1 parent cf1f422 commit aceabcd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 30 deletions.
25 changes: 8 additions & 17 deletions test/lib/c/02-subscribe-qos1-async1.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,24 @@ int main(int argc, char *argv[])
mosquitto_connect_callback_set(mosq, on_connect);
mosquitto_disconnect_callback_set(mosq, on_disconnect);
mosquitto_subscribe_callback_set(mosq, on_subscribe);
printf("ok, about to call connect_async\n");

// this only works if loop_start is first. with loop_start second,
// it fails on both 1.6.4 _and_ 1.6.5
// in this order, 1.6.4 works and 1.6.5 fails.
rc = mosquitto_loop_start(mosq);
printf("loop_start returned rc: %d\n", rc);
if (rc) {
printf("which is: %s\n", mosquitto_strerror(rc));
if(rc){
printf("loop_start failed: %s\n", mosquitto_strerror(rc));
return rc;
}

// not sure which rc you want to be returned....
rc = mosquitto_connect_async(mosq, "localhost", port, 60);
printf("connect async returned rc: %d\n", rc);
if (rc) {
printf("which is: %s\n", mosquitto_strerror(rc));
if(rc){
printf("connect_async failed: %s\n", mosquitto_strerror(rc));
return rc;
}

printf("ok, so we can start just waiting now, loop_start will run in it's thread\n");
/* 10 millis to be system polite */
//struct timespec tv = { 0, 10e6 };
struct timespec tv = { 1, 0 };
/* 50 millis to be system polite */
struct timespec tv = { 0, 50e6 };
while(should_run){
nanosleep(&tv, NULL);
printf("...waiting...\n");
}
printf("Already exited should_run....\n");

mosquitto_disconnect(mosq);
mosquitto_loop_stop(mosq, false);
Expand Down
19 changes: 6 additions & 13 deletions test/lib/c/02-subscribe-qos1-async2.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,22 @@ int main(int argc, char *argv[])
mosquitto_connect_callback_set(mosq, on_connect);
mosquitto_disconnect_callback_set(mosq, on_disconnect);
mosquitto_subscribe_callback_set(mosq, on_subscribe);
printf("ok, about to call connect_async\n");

rc = mosquitto_connect_async(mosq, "localhost", port, 60);
printf("connect async returned rc: %d\n", rc);
if (rc) {
printf("which is: %s\n", mosquitto_strerror(rc));
if(rc){
printf("connect_async failed: %s\n", mosquitto_strerror(rc));
}

rc = mosquitto_loop_start(mosq);
printf("loop_start returned rc: %d\n", rc);
if (rc) {
printf("which is: %s\n", mosquitto_strerror(rc));
if(rc){
printf("loop_start failed: %s\n", mosquitto_strerror(rc));
}

printf("ok, so we can start just waiting now, loop_start will run in it's thread\n");
/* 10 millis to be system polite */
//struct timespec tv = { 0, 10e6 };
struct timespec tv = { 1, 0 };
/* 50 millis to be system polite */
struct timespec tv = { 0, 50e6 };
while(should_run){
nanosleep(&tv, NULL);
printf("...waiting...\n");
}
printf("Already exited should_run....\n");

mosquitto_disconnect(mosq);
mosquitto_loop_stop(mosq, false);
Expand Down

0 comments on commit aceabcd

Please sign in to comment.