/* This provides a crude manner of testing the performance of a broker in messages/s. */ #include #include #include #include #include #include #include static bool run = true; static int message_count = 0; static struct timeval start, stop; void my_connect_callback(struct mosquitto *mosq, void *obj, int rc) { printf("rc: %d\n", rc); gettimeofday(&start, NULL); } void my_disconnect_callback(struct mosquitto *mosq, void *obj, int result) { run = false; } void my_publish_callback(struct mosquitto *mosq, void *obj, int mid) { message_count++; //printf("%d ", message_count); if(message_count == MESSAGE_COUNT){ gettimeofday(&stop, NULL); mosquitto_disconnect((struct mosquitto *)obj); } } int create_data(void) { int i; FILE *fptr, *rnd; int rc = 0; char buf[MESSAGE_SIZE]; fptr = fopen("msgsps_pub.dat", "rb"); if(fptr){ fseek(fptr, 0, SEEK_END); if(ftell(fptr) >= MESSAGE_SIZE*MESSAGE_COUNT){ fclose(fptr); return 0; } fclose(fptr); } fptr = fopen("msgsps_pub.dat", "wb"); if(!fptr) return 1; rnd = fopen("/dev/urandom", "rb"); if(!rnd){ fclose(fptr); return 1; } for(i=0; i