2021-01-02 13:10:00 -05:00
|
|
|
#pragma once
|
|
|
|
|
2024-02-20 21:41:37 -05:00
|
|
|
/**
|
|
|
|
** \defgroup packetstream Packet Stream
|
|
|
|
** Primitive helper for sending packets of known size across a pipe.
|
|
|
|
** @{
|
|
|
|
*/
|
|
|
|
|
2021-01-02 13:10:00 -05:00
|
|
|
#include <stddef.h>
|
|
|
|
|
2024-03-05 21:17:20 -05:00
|
|
|
/** A handle to a UNIX-style pipe. */
|
2021-01-02 13:10:00 -05:00
|
|
|
typedef struct uv_pipe_s uv_pipe_t;
|
|
|
|
|
2024-03-05 21:17:20 -05:00
|
|
|
/** A packet stream instance. */
|
2021-01-02 13:10:00 -05:00
|
|
|
typedef struct _tf_packetstream_t tf_packetstream_t;
|
|
|
|
|
2024-03-05 21:17:20 -05:00
|
|
|
/**
|
|
|
|
** A function called when a packet is received.
|
|
|
|
** @param packet_type The type of the packet as specified by the sender.
|
|
|
|
** @param begin The beginning of the data.
|
|
|
|
** @param length The length of the data.
|
|
|
|
** @param user_data User data.
|
|
|
|
*/
|
2024-02-15 18:35:01 -05:00
|
|
|
typedef void(tf_packetstream_onreceive_t)(int packet_type, const char* begin, size_t length, void* user_data);
|
2021-01-02 13:10:00 -05:00
|
|
|
|
2024-03-05 21:17:20 -05:00
|
|
|
/**
|
|
|
|
** Create a packet stream.
|
|
|
|
** @return The packet stream.
|
|
|
|
*/
|
2021-01-02 13:10:00 -05:00
|
|
|
tf_packetstream_t* tf_packetstream_create();
|
2024-03-05 21:17:20 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
** Destroy a packet stream.
|
|
|
|
** @param stream The packet stream.
|
|
|
|
*/
|
2021-01-02 13:10:00 -05:00
|
|
|
void tf_packetstream_destroy(tf_packetstream_t* stream);
|
|
|
|
|
2024-03-05 21:17:20 -05:00
|
|
|
/**
|
|
|
|
** Start a packet stream receiving.
|
|
|
|
** @param stream The packet stream.
|
|
|
|
*/
|
2021-01-02 13:10:00 -05:00
|
|
|
void tf_packetstream_start(tf_packetstream_t* stream);
|
2024-03-05 21:17:20 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
** Send a discrete packet over a packet stream.
|
|
|
|
** @param stream The packet stream.
|
|
|
|
** @param packet_type The type of the packet.
|
|
|
|
** @param begin The start of the packet data.
|
|
|
|
** @param length The length of the packet data.
|
|
|
|
*/
|
2022-01-02 13:17:58 -05:00
|
|
|
void tf_packetstream_send(tf_packetstream_t* stream, int packet_type, const char* begin, size_t length);
|
2024-03-05 21:17:20 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
** Register the callback to be called when a message is received.
|
|
|
|
** @param stream The packet stream.
|
|
|
|
** @param callback The callback function.
|
|
|
|
** @param user_data User data to pass to the callback.
|
|
|
|
*/
|
2021-01-02 13:10:00 -05:00
|
|
|
void tf_packetstream_set_on_receive(tf_packetstream_t* stream, tf_packetstream_onreceive_t* callback, void* user_data);
|
2024-03-05 21:17:20 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
** Close a packet stream.
|
|
|
|
** @param stream The packet stream.
|
|
|
|
*/
|
2021-01-02 13:10:00 -05:00
|
|
|
void tf_packetstream_close(tf_packetstream_t* stream);
|
2024-03-05 21:17:20 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
** Get the internal pipe object from a packet stream.
|
|
|
|
** @param stream The packet stream.
|
|
|
|
** @return The pipe.
|
|
|
|
*/
|
2021-01-02 13:10:00 -05:00
|
|
|
uv_pipe_t* tf_packetstream_get_pipe(tf_packetstream_t* stream);
|
2024-02-20 21:41:37 -05:00
|
|
|
|
|
|
|
/** @} */
|