using namespace std;
-int main() {
+int main(void) {
assert(meshlink::destroy("basicpp_conf"));
// Open a new meshlink instance.
}
int main(void) {
+ init_sync_flag(&bar_connected);
+ init_sync_flag(&bar_disconnected);
+ init_sync_flag(&baz_connected);
+
meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
// Create three instances.
struct aio_info aio_infos[2];
};
-static size_t b_received_len;
-static struct timeval b_received_tv;
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) {
switch(port) {
case 1:
case 3:
- meshlink_channel_aio_receive(mesh, channel, info->data, size / 4, aio_cb, &info->aio_infos[0]);
- meshlink_channel_aio_receive(mesh, channel, info->data + size / 4, size - size / 4, aio_cb_close, &info->aio_infos[1]);
+ assert(meshlink_channel_aio_receive(mesh, channel, info->data, size / 4, aio_cb, &info->aio_infos[0]));
+ assert(meshlink_channel_aio_receive(mesh, channel, info->data + size / 4, size - size / 4, aio_cb_close, &info->aio_infos[1]));
break;
case 2:
case 4:
- meshlink_channel_aio_receive(mesh, channel, info->data, size / 4, aio_cb_close, &info->aio_infos[0]);
- meshlink_channel_aio_receive(mesh, channel, info->data + size / 4, size - size / 4, aio_cb, &info->aio_infos[1]);
+ assert(meshlink_channel_aio_receive(mesh, channel, info->data, size / 4, aio_cb_close, &info->aio_infos[0]));
+ assert(meshlink_channel_aio_receive(mesh, channel, info->data + size / 4, size - size / 4, aio_cb, &info->aio_infos[1]));
set_sync_flag(&info->aio_infos[1].flag, true);
break;
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;
return true;
}
-int main(int argc, char *argv[]) {
- (void)argc;
- (void)argv;
-
+int main(void) {
meshlink_set_log_cb(NULL, MESHLINK_WARNING, log_cb);
// Prepare file
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);
+
char filename[PATH_MAX];
snprintf(filename, sizeof(filename), "channels_aio_fd.out%d", (int)i);
in_infos[i].file = fopen(filename, "w");
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;
assert(nb);
struct sync_flag channel_opened = {.flag = false};
+ init_sync_flag(&channel_opened);
meshlink_channel_t *channel = meshlink_channel_open(a, nb, 7, a_receive_cb, &channel_opened, 0);
assert(channel);
// Send a message to b
struct sync_flag channel_closed = {.flag = false};
+ init_sync_flag(&channel_closed);
channel->priv = &channel_closed;
assert(meshlink_channel_send(a, channel, "Hello", 5) == 5);
// Try to create a second channel
struct sync_flag channel_polled = {.flag = false};
+ init_sync_flag(&channel_polled);
meshlink_channel_t *channel2 = meshlink_channel_open(a, nb, 7, a_receive_cb, &channel_polled, 0);
assert(channel2);
}
int main(void) {
+ init_sync_flag(&poll_flag);
+ init_sync_flag(&receive_flag);
+
meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
// Open two meshlink instances.
}
int main(void) {
+ init_sync_flag(&bar_responded);
+ init_sync_flag(&foo_connected);
+ init_sync_flag(&foo_gone);
+
int fda[2], fdb[2];
- assert(pipe2(fda, 0) != -1);
- assert(pipe2(fdb, 0) != -1);
+ assert(pipe(fda) != -1);
+ assert(pipe(fdb) != -1);
if(!fork()) {
return main2(fdb[0], fda[1]);
}
int main(void) {
+ init_sync_flag(&accept_flag);
+ init_sync_flag(&close_flag);
+
meshlink_set_log_cb(NULL, MESHLINK_WARNING, log_cb);
// Open four new meshlink instance, the server and three peers.
}
const struct timespec req = {0, 2000000};
- clock_nanosleep(CLOCK_MONOTONIC, 0, &req, NULL);
+ nanosleep(&req, NULL);
}
// Let the clients close the channels
}
int main(void) {
+ init_sync_flag(&b_responded);
+
meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
// Open two new meshlink instance.
}
int main(void) {
+ init_sync_flag(&duplicate_detected);
+
meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
// Open meshlink instances
int main(void) {
+ init_sync_flag(&a_started);
+ init_sync_flag(&a_stopped);
+ init_sync_flag(&b_responded);
+
meshlink_set_log_cb(NULL, MESHLINK_WARNING, log_cb);
// Initialize and exchange configuration.
}
int main(void) {
+ init_sync_flag(&bar_reachable);
+
struct meshlink_node **nodes = NULL;
size_t nnodes = 0;
}
int main(void) {
+ init_sync_flag(&bar_reachable);
+
meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
// Open two new meshlink instance.
}
int main(void) {
+ init_sync_flag(&baz_reachable);
+
meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
assert(meshlink_destroy("invite_join_conf.1"));
char *p = buf;
memcpy(buf, &now, sizeof(now));
+ clock_gettime(CLOCK_REALTIME, &now);
for(uint64_t *q = (uint64_t *)(buf + sizeof(now)); (char *)q < buf + framesize; q++) {
*q = counter++;
ssize_t sent = write(1, p, tosend);
if(sent <= 0) {
- err(1, "write(1, %p, %zu)", p, tosend);
+ err(1, "write(1, %p, %zu)", (void *)p, tosend);
}
tosend -= sent;
p += sent;
}
- next = now;
- next.tv_nsec += interval;
+ next.tv_sec = 0;
+ next.tv_nsec = interval;
while(next.tv_nsec >= 1000000000) {
next.tv_nsec -= 1000000000;
next.tv_sec++;
}
- clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &next, NULL);
- now = next;
+ nanosleep(&next, NULL);
total -= framesize;
} else {
struct timespec *ts = (struct timespec *)buf;
ssize_t result = read(0, p, toread);
if(result <= 0) {
- err(1, "read(1, %p, %zu)", p, toread);
+ err(1, "read(1, %p, %zu)", (void *)p, toread);
}
toread -= result;
ssize_t result = read(0, p, toread);
if(result <= 0) {
- err(1, "read(1, %p, %zu)", p, toread);
+ err(1, "read(1, %p, %zu)", (void *)p, toread);
}
toread -= result;
if(*q != counter++) {
uint64_t offset = (counter - 1) * 8;
offset += ((counter * 8) / (framesize - sizeof(now))) * sizeof(now);
- err(1, "verification failed at offset %lu", offset);
+ err(1, "verification failed at offset %lu", (unsigned long)offset);
}
}
}
int main(void) {
+ init_sync_flag(&received);
+ init_sync_flag(&bar_learned_baz);
+ init_sync_flag(&baz_learned_bar);
+
meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
// Create three instances.
}
int main(void) {
+ init_sync_flag(&received);
+ init_sync_flag(&bar_learned_baz);
+ init_sync_flag(&baz_learned_bar);
+
meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
// Create three instances.
#include "utils.h"
+void init_sync_flag(struct sync_flag *s) {
+ assert(pthread_mutex_init(&s->mutex, NULL) == 0);
+ assert(pthread_cond_init(&s->cond, NULL) == 0);
+}
+
void set_sync_flag(struct sync_flag *s, bool value) {
- pthread_mutex_lock(&s->mutex);
+ assert(pthread_mutex_lock(&s->mutex) == 0);
s->flag = value;
- pthread_cond_broadcast(&s->cond);
- pthread_mutex_unlock(&s->mutex);
+ assert(pthread_cond_broadcast(&s->cond) == 0);
+ assert(pthread_mutex_unlock(&s->mutex) == 0);
}
bool check_sync_flag(struct sync_flag *s) {
bool flag;
- pthread_mutex_lock(&s->mutex);
+ assert(pthread_mutex_lock(&s->mutex) == 0);
flag = s->flag;
- pthread_mutex_unlock(&s->mutex);
+ assert(pthread_mutex_unlock(&s->mutex) == 0);
return flag;
}
clock_gettime(CLOCK_REALTIME, &timeout);
timeout.tv_sec += seconds;
- pthread_mutex_lock(&s->mutex);
+ assert(pthread_mutex_lock(&s->mutex) == 0);
while(!s->flag) {
if(!pthread_cond_timedwait(&s->cond, &s->mutex, &timeout) || errno != EINTR) {
}
}
- pthread_mutex_unlock(&s->mutex);
+ assert(pthread_mutex_unlock(&s->mutex) == 0);
return s->flag;
}
void start_meshlink_pair(meshlink_handle_t *a, meshlink_handle_t *b) {
struct sync_flag pair_status = {.flag = false};
+ init_sync_flag(&pair_status);
a->priv = &pair_status;
meshlink_set_node_status_cb(a, pair_status_cb);
bool flag;
};
+extern void init_sync_flag(struct sync_flag *s);
extern void set_sync_flag(struct sync_flag *s, bool value);
extern bool check_sync_flag(struct sync_flag *s);
extern bool wait_sync_flag(struct sync_flag *s, int seconds);
#endif
/// Compare two timespec values.
-static bool timespec_lt(const struct timespec *a, const struct timespec *b) {
+static inline bool timespec_lt(const struct timespec *a, const struct timespec *b) {
if(a->tv_sec == b->tv_sec) {
return a->tv_nsec < b->tv_nsec;
} else {