tildefriends/src/packetstream.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

75 lines
2.0 KiB
C
Raw Permalink Normal View History

#pragma once
/**
** \defgroup packetstream Packet Stream
** Primitive helper for sending packets of known size across a pipe.
** @{
*/
#include <stddef.h>
2024-03-05 21:17:20 -05:00
/** A handle to a UNIX-style pipe. */
typedef struct uv_pipe_s uv_pipe_t;
2024-03-05 21:17:20 -05:00
/** A packet stream instance. */
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.
*/
typedef void(tf_packetstream_onreceive_t)(int packet_type, const char* begin, size_t length, void* user_data);
2024-03-05 21:17:20 -05:00
/**
** Create a packet stream.
** @return The packet stream.
*/
tf_packetstream_t* tf_packetstream_create();
2024-03-05 21:17:20 -05:00
/**
** Destroy a packet stream.
** @param stream The packet stream.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
uv_pipe_t* tf_packetstream_get_pipe(tf_packetstream_t* stream);
/** @} */