meshlink_set_channel_rcvbuf(handle, channel, size);
}
+ /// Set the flags of a channel.
+ /** This function allows changing some of the channel flags.
+ * Currently only MESHLINK_CHANNEL_NO_PARTIAL and MESHLINK_CHANNEL_DROP_LATE are supported, other flags are ignored.
+ * These flags only affect the local side of the channel with the peer.
+ * The changes take effect immediately.
+ *
+ * @param channel A handle for the channel.
+ * @param flags A bitwise-or'd combination of flags that set the semantics for this channel.
+ */
+ void set_channel_flags(channel *channel, uint32_t flags) {
+ meshlink_set_channel_flags(handle, channel, flags);
+ }
+
/// Set the connection timeout used for channels to the given node.
/** This sets the timeout after which unresponsive channels will be reported as closed.
* The timeout is set for all current and future channels to the given node.
pthread_mutex_unlock(&mesh->mutex);
}
+void meshlink_set_channel_flags(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint32_t flags) {
+ if(!mesh || !channel) {
+ meshlink_errno = MESHLINK_EINVAL;
+ return;
+ }
+
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
+ utcp_set_flags(channel->c, flags);
+ pthread_mutex_unlock(&mesh->mutex);
+}
+
meshlink_channel_t *meshlink_channel_open_ex(meshlink_handle_t *mesh, meshlink_node_t *node, uint16_t port, meshlink_channel_receive_cb_t cb, const void *data, size_t len, uint32_t flags) {
if(data && len) {
abort(); // TODO: handle non-NULL data
*/
void meshlink_set_channel_rcvbuf(struct meshlink_handle *mesh, struct meshlink_channel *channel, size_t size);
+/// Set the flags of a channel.
+/** This function allows changing some of the channel flags.
+ * Currently only MESHLINK_CHANNEL_NO_PARTIAL and MESHLINK_CHANNEL_DROP_LATE are supported, other flags are ignored.
+ * These flags only affect the local side of the channel with the peer.
+ * The changes take effect immediately.
+ *
+ * \memberof meshlink_channel
+ * @param mesh A handle which represents an instance of MeshLink.
+ * @param channel A handle for the channel.
+ * @param flags A bitwise-or'd combination of flags that set the semantics for this channel.
+ */
+void meshlink_set_channel_flags(struct meshlink_handle *mesh, struct meshlink_channel *channel, uint32_t flags);
+
/// Open a reliable stream channel to another node.
/** This function is called whenever a remote node wants to open a channel to the local node.
* The application then has to decide whether to accept or reject this channel.
meshlink_set_blacklisted_cb
meshlink_set_canonical_address
meshlink_set_channel_accept_cb
+meshlink_set_channel_flags
meshlink_set_channel_listen_cb
meshlink_set_channel_poll_cb
meshlink_set_channel_rcvbuf
}
}
+void utcp_set_flags(struct utcp_connection *c, uint32_t flags) {
+ c->flags &= ~UTCP_CHANGEABLE_FLAGS;
+ c->flags |= flags & UTCP_CHANGEABLE_FLAGS;
+}
+
void utcp_offline(struct utcp *utcp, bool offline) {
struct timespec now;
clock_gettime(UTCP_CLOCK, &now);
#define UTCP_TCP 3
#define UTCP_UDP 0
+#define UTCP_CHANGEABLE_FLAGS 0x18U
typedef bool (*utcp_listen_t)(struct utcp *utcp, uint16_t port);
typedef void (*utcp_accept_t)(struct utcp_connection *utcp_connection, uint16_t port);
void utcp_expect_data(struct utcp_connection *connection, bool expect);
+void utcp_set_flags(struct utcp_connection *connection, uint32_t flags);
+
// Completely global options
void utcp_set_clock_granularity(long granularity);
assert_after(!meshlink_channel_get_sendq(mesh_a, channel), 30);
assert(meshlink_channel_send(mesh_a, channel, buf, 512) == 512);
+ // Check that we can change the NO_PARTIAL flag
+
+ assert_after(!meshlink_channel_get_sendq(mesh_a, channel), 30);
+ meshlink_set_channel_sndbuf(mesh_a, channel, 256);
+ assert(meshlink_channel_send(mesh_a, channel, buf, 257) == -1);
+ meshlink_set_channel_flags(mesh_a, channel, 0);
+ assert(meshlink_channel_send(mesh_a, channel, buf, 257) == 256);
+
+ assert_after(!meshlink_channel_get_sendq(mesh_a, channel), 30);
+ meshlink_set_channel_flags(mesh_a, channel, MESHLINK_CHANNEL_NO_PARTIAL);
+ assert(meshlink_channel_send(mesh_a, channel, buf, 257) == -1);
+ assert(meshlink_channel_send(mesh_a, channel, buf, 256) == 256);
+
// Clean up.
close_meshlink_pair(mesh_a, mesh_b);