- struct databag *mydata = data;
- uint8_t buf[BUFSIZE];
- uint64_t nb_to_send = 0;
- int bytes_written;
- double time_cur, time_last, time_diff;
-
- time_last = g_timer_elapsed(mydata->timer, NULL);
-
- while (thread_running) {
- /* Rate control */
- time_cur = g_timer_elapsed(mydata->timer, NULL);
-
- time_diff = time_cur - time_last;
- time_last = time_cur;
-
- nb_to_send = cur_samplerate * time_diff;
-
- if (limit_samples) {
- nb_to_send = MIN(nb_to_send,
- limit_samples - mydata->samples_counter);
- }
-
- /* Make sure we don't overflow. */
- nb_to_send = MIN(nb_to_send, BUFSIZE);
-
- if (nb_to_send) {
- samples_generator(buf, nb_to_send, data);
- mydata->samples_counter += nb_to_send;