*/
typedef void (*channel_poll_cb_t)(mesh *mesh, channel *channel, size_t len);
+/// A callback for cleaning up buffers submitted for asynchronous I/O.
+/** This callbacks signals that MeshLink has finished using this buffer.
+ * The ownership of the buffer is now back into the application's hands.
+ *
+ * @param mesh A handle which represents an instance of MeshLink.
+ * @param channel A handle for the channel which used this buffer.
+ * @param data A pointer to a buffer containing the enqueued data.
+ * @param len The length of the buffer.
+ * @param priv A private pointer which was set by the application when submitting the buffer.
+ */
+typedef void (*aio_cb_t)(mesh *mesh, channel *channel, const void *data, size_t len, void *priv);
+
/// A class describing a MeshLink node.
class node: public meshlink_node_t {
};
static const uint32_t ORDERED = MESHLINK_CHANNEL_ORDERED;
static const uint32_t FRAMED = MESHLINK_CHANNEL_FRAMED;
static const uint32_t DROP_LATE = MESHLINK_CHANNEL_DROP_LATE;
+ static const uint32_t NO_PARTIAL = MESHLINK_CHANNEL_NO_PARTIAL;
static const uint32_t TCP = MESHLINK_CHANNEL_TCP;
static const uint32_t UDP = MESHLINK_CHANNEL_UDP;
};
* @param len The length of the data.
*
* @return The amount of data that was queued, which can be less than len, or a negative value in case of an error.
+ * If MESHLINK_CHANNEL_NO_PARTIAL is set, then the result will either be len,
+ * 0 if the buffer is currently too full, or -1 if len is too big even for an empty buffer.
*/
ssize_t channel_send(channel *channel, void *data, size_t len) {
return meshlink_channel_send(handle, channel, data, len);
}
+ /// Transmit data on a channel asynchronously
+ /** This queues data to send to the remote node.
+ *
+ * @param channel A handle for the channel.
+ * @param data A pointer to a buffer containing data sent by the source, or NULL if there is no data to send.
+ * After meshlink_channel_aio_send() returns, the buffer may not be modified or freed by the application
+ * until the callback routine is called.
+ * @param len The length of the data, or 0 if there is no data to send.
+ * @param cb A pointer to the function which will be called when MeshLink has finished using the buffer.
+ *
+ * @return True if the buffer was enqueued, false otherwise.
+ */
+ bool channel_aio_send(channel *channel, const void *data, size_t len, meshlink_aio_cb_t cb, void *priv) {
+ return meshlink_channel_aio_send(handle, channel, data, len, cb, priv);
+ }
+
/// Get the amount of bytes in the send buffer.
/** This returns the amount of bytes in the send buffer.
* These bytes have not been received by the peer yet.