* @return This function should return true if the application accepts the incoming channel, false otherwise.
* If returning false, the channel is invalid and may not be used anymore.
*/
- typedef bool (*channel_accept_cb_t)(mesh *mesh, channel *channel, node *node, uint16_t port, void *data, size_t len);
+ typedef bool (*channel_accept_cb_t)(mesh *mesh, channel *channel, node *node, uint16_t port, const void *data, size_t len);
/// A callback for receiving data from a channel.
/** @param mesh A handle which represents an instance of MeshLink.
* @param data A pointer to a buffer containing data sent by the source.
* @param len The length of the data.
*/
- typedef void (*channel_receive_cb_t)(mesh *mesh, channel *channel, void *data, size_t len);
+ typedef void (*channel_receive_cb_t)(mesh *mesh, channel *channel, const void *data, size_t len);
/// A class describing a MeshLink node.
class node: public meshlink_node_t {
* @param nodes A pointer to an array of pointers to meshlink::node, which should be allocated by the application.
* @param nmemb The maximum number of pointers that can be stored in the nodes array.
*
- * @return The number of known nodes. This can be larger than nmemb, in which case not all nodes were stored in the nodes array.
+ * @return The number of known nodes, or -1 in case of an error.
+ * This can be larger than nmemb, in which case not all nodes were stored in the nodes array.
*/
- size_t get_all_nodes(node **nodes, size_t nmemb) {
+ ssize_t get_all_nodes(node **nodes, size_t nmemb) {
return meshlink_get_all_nodes(this, (meshlink_node_t **)nodes, nmemb);
}
* to hand the data over to the application's thread.
* The callback should also not block itself and return as quickly as possible.
*
+ * @param channel A handle for the channel.
* @param cb A pointer to the function which will be called when another node sends data to the local node.
*/
void set_channel_accept_cb(channel *channel, channel_accept_cb_t cb) {
*
* @return A handle for the channel, or NULL in case of an error.
*/
- channel *channel_open(node *node, uint16_t port, channel_receive_cb_t recv, void *data, size_t len) {
- return (channel *)meshlink_channel_open(this, node, port, (meshlink_channel_receive_cb_t)recv, data, len);
+ channel *channel_open(node *node, uint16_t port, channel_receive_cb_t cb, const void *data, size_t len) {
+ return (channel *)meshlink_channel_open(this, node, port, (meshlink_channel_receive_cb_t)cb, data, len);
}
/// Partially close a reliable stream channel.
static void close(mesh *mesh) {
meshlink_close(mesh);
}
+
+ static const char *strerror(errno_t err = meshlink_errno) {
+ return meshlink_strerror(err);
+ }
};
#endif // MESHLINKPP_H