Data Structures | Enumerations | Functions
socket_emitter.h File Reference

Nonblocking data transmission. More...

Data Structures

struct  vtm_socket_emitter
 

Enumerations

enum  vtm_socket_emitter_result { VTM_SOCK_EMIT_AGAIN, VTM_SOCK_EMIT_COMPLETE, VTM_SOCK_EMIT_ERROR }
 

Functions

VTM_API void vtm_socket_emitter_free_chain (struct vtm_socket_emitter *se)
 
VTM_API void vtm_socket_emitter_free_single (struct vtm_socket_emitter *se)
 
VTM_API struct vtm_socket_emittervtm_socket_emitter_for_raw (vtm_socket *sock, const void *src, size_t len)
 
VTM_API struct vtm_socket_emittervtm_socket_emitter_for_buffer (vtm_socket *sock, struct vtm_buf *buf, bool fr)
 
VTM_API struct vtm_socket_emittervtm_socket_emitter_for_file (vtm_socket *sock, FILE *fp)
 
VTM_API int vtm_socket_emitter_try_write (struct vtm_socket_emitter **se)
 
VTM_API int vtm_socket_emitter_get_chain_lensum (struct vtm_socket_emitter *se, uint64_t *out_sum)
 

Enumeration Type Documentation

Enumerator
VTM_SOCK_EMIT_AGAIN 

There is still data that needs to be transmitted

VTM_SOCK_EMIT_COMPLETE 

All data was transmitted

VTM_SOCK_EMIT_ERROR 

An error occured while transmitting data

Function Documentation

VTM_API void vtm_socket_emitter_free_chain ( struct vtm_socket_emitter se)

Releases the given emitter and all other linked emitters in the chain.

Parameters
sethe socket emitter that should be released
VTM_API void vtm_socket_emitter_free_single ( struct vtm_socket_emitter se)

Releases the given emitter.

Parameters
sethe socket emitter that should be released
VTM_API struct vtm_socket_emitter* vtm_socket_emitter_for_raw ( vtm_socket *  sock,
const void *  src,
size_t  len 
)

Creates a new socket emitter for sending a raw memory chunk.

Parameters
sockthe socket that should be used by the emitter
srcpointer to the memory chunk
lenthe size of the memory chunk in bytes
Returns
the created emitter
NULL if an error occured
VTM_API struct vtm_socket_emitter* vtm_socket_emitter_for_buffer ( vtm_socket *  sock,
struct vtm_buf buf,
bool  fr 
)

Creates a new socket emitter for sending the contents of buffer.

Parameters
sockthe socket that should be used by the emitter
bufthe buffer whose contents should be sent
frif true the buffer is released when the emitter is released
Returns
the created emitter
NULL if an error occured
VTM_API struct vtm_socket_emitter* vtm_socket_emitter_for_file ( vtm_socket *  sock,
FILE *  fp 
)

Creates a new socket emitter for sending the contents of file.

Parameters
sockthe socket that should be used by the emitter
fpthe already opened file
Returns
the created emitter
NULL if an error occured
VTM_API int vtm_socket_emitter_try_write ( struct vtm_socket_emitter **  se)

Tries to send the data of all emitters in the chain immediately.

Emitters that were able to send their data completely are automatically released.

Parameters
[in,out]sepointer to pointer to root emitter.
Returns
VTM_OK if the data of all emitters was transmitted successfully
VTM_E_IO_AGAIN if only some data was transmitted. In this case the se parameter points to the emitter that is now the head of the chain.
VTM_E_IO_UNKNOWN or VTM_ERROR if an error occured
VTM_API int vtm_socket_emitter_get_chain_lensum ( struct vtm_socket_emitter se,
uint64_t *  out_sum 
)

Calculates the sum of all length specifications of the emitter chain.

Parameters
sethe root emitter
[out]out_sumthe total number in bytes
Returns
VTM_OK if the sum was calculated successfully
VTM_ERROR if an error occured