* @param cb A pointer to the function which will be called when the remote node sends data to the local node.
* @param data A pointer to a buffer containing data to already queue for sending.
* @param len The length of the data.
+ * If len is 0, the data pointer is copied into the channel's priv member.
* @param flags A bitwise-or'd combination of flags that set the semantics for this channel.
*
* @return A handle for the channel, or NULL in case of an error.
* @param port The port number the peer wishes to connect to.
* @param data A pointer to a buffer containing data to already queue for sending.
* @param len The length of the data.
+ * If len is 0, the data pointer is copied into the channel's priv member.
* @param flags A bitwise-or'd combination of flags that set the semantics for this channel.
*
* @return A handle for the channel, or NULL in case of an error.
}
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) {
+ if(data && len) {
abort(); // TODO: handle non-NULL data
}
meshlink_channel_t *channel = xzalloc(sizeof(*channel));
channel->node = n;
channel->receive_cb = cb;
+
+ if(data && !len) {
+ channel->priv = (void *)data;
+ }
+
channel->c = utcp_connect_ex(n->utcp, port, channel_recv, channel, flags);
pthread_mutex_unlock(&mesh->mutex);
* The pointer may be NULL, in which case incoming data is ignored.
* @param data A pointer to a buffer containing data to already queue for sending, or NULL if there is no data to send.
* After meshlink_send() returns, the application is free to overwrite or free this buffer.
+ * If len is 0, the data pointer is copied into the channel's priv member.
* @param len The length of the data, or 0 if there is no data to send.
* @param flags A bitwise-or'd combination of flags that set the semantics for this channel.
*
* @param data A pointer to a buffer containing data to already queue for sending, or NULL if there is no data to send.
* After meshlink_send() returns, the application is free to overwrite or free this buffer.
* @param len The length of the data, or 0 if there is no data to send.
+ * If len is 0, the data pointer is copied into the channel's priv member.
*
* @return A handle for the channel, or NULL in case of an error.
* The handle is valid until meshlink_channel_close() is called.