#undef NDEBUG
#endif
+#define _POSIX_C_SOURCE 200809L
+
#include <assert.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/time.h>
+#include <time.h>
#include "meshlink.h"
#include "utils.h"
struct aio_info {
int callbacks;
size_t size;
- struct timeval tv;
+ struct timespec ts;
struct sync_flag flag;
};
};
static size_t b_received_len;
-static struct timeval b_received_tv;
+static struct timespec b_received_ts;
static struct sync_flag b_received_flag;
static void aio_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *data, size_t len, void *priv) {
(void)len;
struct aio_info *info = priv;
- gettimeofday(&info->tv, NULL);
+ clock_gettime(CLOCK_MONOTONIC, &info->ts);
info->callbacks++;
info->size += len;
set_sync_flag(&info->flag, true);
}
-static bool reject_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *data, size_t len) {
- (void)mesh;
- (void)channel;
- (void)port;
- (void)data;
- (void)len;
-
- return false;
-}
-
static void receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *data, size_t len) {
(void)mesh;
(void)channel;
b_received_len += len;
if(b_received_len >= smallsize) {
- gettimeofday(&b_received_tv, NULL);
+ clock_gettime(CLOCK_MONOTONIC, &b_received_ts);
set_sync_flag(&b_received_flag, true);
}
}
return true;
}
-int main(int argc, char *argv[]) {
- (void)argc;
- (void)argv;
+int main(void) {
+ init_sync_flag(&b_received_flag);
meshlink_set_log_cb(NULL, MESHLINK_WARNING, log_cb);
memset(out_infos, 0, sizeof(out_infos));
for(size_t i = 0; i < nchannels; i++) {
+ init_sync_flag(&in_infos[i].aio_infos[0].flag);
+ init_sync_flag(&in_infos[i].aio_infos[1].flag);
+ init_sync_flag(&out_infos[i].aio_infos[0].flag);
+ init_sync_flag(&out_infos[i].aio_infos[1].flag);
+
in_infos[i].data = malloc(size);
assert(in_infos[i].data);
out_infos[i].data = outdata;
mesh_b->priv = in_infos;
- meshlink_set_channel_accept_cb(mesh_a, reject_cb);
meshlink_set_channel_accept_cb(mesh_b, accept_cb);
// Start both instances
// First batch of data should all be sent and received before the second batch
for(size_t j = 0; j < nchannels; j++) {
- assert(timercmp(&out_infos[i].aio_infos[0].tv, &out_infos[j].aio_infos[1].tv, <=));
- assert(timercmp(&in_infos[i].aio_infos[0].tv, &in_infos[j].aio_infos[1].tv, <=));
+ assert(timespec_lt(&out_infos[i].aio_infos[0].ts, &out_infos[j].aio_infos[1].ts));
+ assert(timespec_lt(&in_infos[i].aio_infos[0].ts, &in_infos[j].aio_infos[1].ts));
}
// The non-AIO transfer should have completed before everything else
- assert(timercmp(&out_infos[i].aio_infos[0].tv, &b_received_tv, >=));
- assert(timercmp(&in_infos[i].aio_infos[0].tv, &b_received_tv, >=));
+ assert(!timespec_lt(&out_infos[i].aio_infos[0].ts, &b_received_ts));
+ assert(!timespec_lt(&in_infos[i].aio_infos[0].ts, &b_received_ts));
}
// Clean up.