11 static bool accept_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *data, size_t len) {
21 int main(int argc, char *argv[]) {
25 meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
27 // Start two new meshlink instance.
29 meshlink_handle_t *mesh_a;
30 meshlink_handle_t *mesh_b;
32 open_meshlink_pair(&mesh_a, &mesh_b, "channels_no_partial");
33 meshlink_set_channel_accept_cb(mesh_b, accept_cb);
34 start_meshlink_pair(mesh_a, mesh_b);
38 meshlink_node_t *b = meshlink_get_node(mesh_a, "b");
41 meshlink_channel_t *channel = meshlink_channel_open_ex(mesh_a, b, 1, NULL, NULL, 0, MESHLINK_CHANNEL_TCP | MESHLINK_CHANNEL_NO_PARTIAL);
44 // Stop a to ensure we get deterministic behaviour for the channel send queue.
46 meshlink_stop(mesh_a);
48 // Verify that no partial sends succeed.
49 // If rejected sends would fit an empty send buffer, 0 should be returned, otherwise -1.
51 char buf[512] = "data";
53 meshlink_set_channel_sndbuf(mesh_a, channel, 256);
54 assert(meshlink_channel_send(mesh_a, channel, buf, 257) == -1);
55 assert(meshlink_channel_send(mesh_a, channel, buf, 256) == 256);
57 meshlink_set_channel_sndbuf(mesh_a, channel, 512);
58 assert(meshlink_channel_send(mesh_a, channel, buf, 257) == 0);
59 assert(meshlink_channel_send(mesh_a, channel, buf, 128) == 128);
60 assert(meshlink_channel_send(mesh_a, channel, buf, 129) == 0);
61 assert(meshlink_channel_send(mesh_a, channel, buf, 100) == 100);
62 assert(meshlink_channel_send(mesh_a, channel, buf, 29) == 0);
63 assert(meshlink_channel_send(mesh_a, channel, buf, 513) == -1);
65 // Restart a to ensure it gets to flush the channel send queue.
67 meshlink_start(mesh_a);
69 assert_after(!meshlink_channel_get_sendq(mesh_a, channel), 30);
70 assert(meshlink_channel_send(mesh_a, channel, buf, 512) == 512);
74 close_meshlink_pair(mesh_a, mesh_b);