Mstdlib-1.24.0
|
Macros | |
#define | M_IO_LAYER_FIND_FIRST_ID SIZE_MAX |
Typedefs | |
typedef enum M_io_type | M_io_type_t |
typedef struct M_io | M_io_t |
typedef struct M_io_meta | M_io_meta_t |
typedef enum M_io_error | M_io_error_t |
typedef enum M_io_state | M_io_state_t |
Enumerations | |
enum | M_io_type { M_IO_TYPE_STREAM = 1 , M_IO_TYPE_WRITER = 2 , M_IO_TYPE_READER = 3 , M_IO_TYPE_LISTENER = 4 , M_IO_TYPE_EVENT = 5 } |
enum | M_io_error { M_IO_ERROR_SUCCESS = 0 , M_IO_ERROR_WOULDBLOCK = 1 , M_IO_ERROR_DISCONNECT = 2 , M_IO_ERROR_ERROR = 3 , M_IO_ERROR_NOTCONNECTED = 4 , M_IO_ERROR_NOTPERM = 5 , M_IO_ERROR_CONNRESET = 6 , M_IO_ERROR_CONNABORTED = 7 , M_IO_ERROR_ADDRINUSE = 8 , M_IO_ERROR_PROTONOTSUPPORTED = 9 , M_IO_ERROR_CONNREFUSED = 10 , M_IO_ERROR_NETUNREACHABLE = 11 , M_IO_ERROR_TIMEDOUT = 12 , M_IO_ERROR_NOSYSRESOURCES = 13 , M_IO_ERROR_INVALID = 14 , M_IO_ERROR_NOTIMPL = 15 , M_IO_ERROR_NOTFOUND = 16 , M_IO_ERROR_BADCERTIFICATE = 17 , M_IO_ERROR_INTERRUPTED = 99 } |
enum | M_io_state { M_IO_STATE_INIT = 0 , M_IO_STATE_LISTENING = 1 , M_IO_STATE_CONNECTING = 2 , M_IO_STATE_CONNECTED = 3 , M_IO_STATE_DISCONNECTING = 4 , M_IO_STATE_DISCONNECTED = 5 , M_IO_STATE_ERROR = 6 } |
Common IO functions
#define M_IO_LAYER_FIND_FIRST_ID SIZE_MAX |
Passed to M_io_layer_acquire() to search for matching layer by name
typedef enum M_io_type M_io_type_t |
typedef struct M_io M_io_t |
typedef struct M_io_meta M_io_meta_t |
typedef enum M_io_error M_io_error_t |
typedef enum M_io_state M_io_state_t |
enum M_io_type |
io type
enum M_io_error |
io error.
enum M_io_state |
io state.
const char * M_io_error_string | ( | M_io_error_t | error | ) |
Convert an error code to a string.
[in] | error | Error code. |
M_io_meta_t * M_io_meta_create | ( | void | ) |
Create an io meta data object.
void M_io_meta_destroy | ( | M_io_meta_t * | meta | ) |
Destory an io meta data object.
[in] | meta | meta data object. |
M_io_error_t M_io_read | ( | M_io_t * | comm, |
unsigned char * | buf, | ||
size_t | buf_len, | ||
size_t * | len_read | ||
) |
Read from an io object.
[in] | comm | io object. |
[out] | buf | Buffer to store data read from io object. |
[in] | buf_len | Lenght of provided buffer. |
[out] | len_read | Number of bytes fread from the io object. |
M_io_error_t M_io_read_into_buf | ( | M_io_t * | comm, |
M_buf_t * | buf | ||
) |
Read from an io object into an M_buf_t.
This will read all available data into the buffer.
[in] | comm | io object. |
[out] | buf | Buffer to store data read from io object. |
M_io_error_t M_io_read_into_parser | ( | M_io_t * | comm, |
M_parser_t * | parser | ||
) |
Read from an io object into an M_parser_t.
This will read all available data into the buffer.
[in] | comm | io object. |
[out] | parser | Parser to store data read from io object. |
M_io_error_t M_io_read_meta | ( | M_io_t * | comm, |
unsigned char * | buf, | ||
size_t | buf_len, | ||
size_t * | len_read, | ||
M_io_meta_t * | meta | ||
) |
Read from an io object with a meta data object.
[in] | comm | io object. |
[out] | buf | Buffer to store data read from io object. |
[in] | buf_len | Lenght of provided buffer. |
[out] | len_read | Number of bytes fread from the io object. |
[in] | meta | Meta data object. |
M_io_error_t M_io_read_into_buf_meta | ( | M_io_t * | comm, |
M_buf_t * | buf, | ||
M_io_meta_t * | meta | ||
) |
Read from an io object into an M_buf_t with a meta data object.
This will read all available data into the buffer.
[in] | comm | io object. |
[out] | buf | Buffer to store data read from io object. |
[in] | meta | Meta data object. |
M_io_error_t M_io_read_into_parser_meta | ( | M_io_t * | comm, |
M_parser_t * | parser, | ||
M_io_meta_t * | meta | ||
) |
Read from an io object into an M_parser_t with a meta data object.
This will read all available data into the buffer.
[in] | comm | io object. |
[out] | parser | Parser to store data read from io object. |
[in] | meta | Meta data object. |
M_io_error_t M_io_read_clear | ( | M_io_t * | io | ) |
Clear/Flush the read buffer to consume all data and dispose of it.
[in] | io | io object |
M_io_error_t M_io_write | ( | M_io_t * | comm, |
const unsigned char * | buf, | ||
size_t | buf_len, | ||
size_t * | len_written | ||
) |
Write data to an io object.
This function will attempt to write as much data as possible. If not all data is written the application should wait until the next write event and then try writing more data.
[in] | comm | io object. |
[in] | buf | Buffer to write from. |
[in] | buf_len | Number of bytes in buffer to write. |
[out] | len_written | Number of bytes from the buffer written. |
M_io_error_t M_io_write_from_buf | ( | M_io_t * | comm, |
M_buf_t * | buf | ||
) |
Write data to an io object from an M_buf_t.
This function will attempt to write as much data as possible. If not all data is written the application should wait until the next write event and then try writing more data.
[in] | comm | io object. |
[in] | buf | Buffer to write from. |
M_io_error_t M_io_write_meta | ( | M_io_t * | comm, |
const unsigned char * | buf, | ||
size_t | buf_len, | ||
size_t * | len_written, | ||
M_io_meta_t * | meta | ||
) |
Write data to an io object with a meta data object.
This function will attempt to write as much data as possible. If not all data is written the application should wait until the next write event and then try writing more data.
[in] | comm | io object. |
[in] | buf | Buffer to write from. |
[in] | buf_len | Number of bytes in buffer to write. |
[out] | len_written | Number of bytes from the buffer written. |
[in] | meta | Meta data object. |
M_io_error_t M_io_write_from_buf_meta | ( | M_io_t * | comm, |
M_buf_t * | buf, | ||
M_io_meta_t * | meta | ||
) |
Write data to an io object from an M_buf_t with a meta data object.
This function will attempt to write as much data as possible. If not all data is written the application should wait until the next write event and then try writing more data.
[in] | comm | io object. |
[in] | buf | Buffer to write from. |
[in] | meta | Meta data object. |
M_io_error_t M_io_accept | ( | M_io_t ** | io_out, |
M_io_t * | server_io | ||
) |
Accept an io connection.
Typically used with network io when a connection is setup as a listening socket. The io object will remain valid and a new io object for the connection will be created.
A return of M_IO_ERROR_WOULDBLOCK should not be treated as an error. It means either there is more data that needs to be received and the event will trigger again. Or there is no more outstanding connections waiting to be accepted.
Example:
void ipserver_listen_callback(M_event_t *el, M_event_type_t type, M_io_t *io, void *thunk) { M_io_t *io_out = NULL; M_io_error_t ioerr; (void)thunk; if (type != M_EVENT_TYPE_ACCEPT) return; ioerr = M_io_accept(&io_out, io); if (ioerr != M_IO_ERROR_SUCCESS || io_out == NULL) { if (ioerr != M_IO_ERROR_WOULDBLOCK) { // Connection error } return; } M_event_add(el, io_out, ipserver_connection_callback, NULL); }
[out] | io_out | io object created from the accept. |
[in] | server_io | io object which was listening. |
M_io_state_t M_io_get_state | ( | M_io_t * | io | ) |
Current state of an io object
[in] | io | io object; |
M_io_state_t M_io_get_layer_state | ( | M_io_t * | io, |
size_t | id | ||
) |
Current state of a layer within an io object
[in] | io | io object |
[in] | id | id of a layer to query (0 for base layer) |
size_t M_io_layer_count | ( | M_io_t * | io | ) |
Retrieve the number of layers from an io object
[in] | io | io object |
const char * M_io_layer_name | ( | M_io_t * | io, |
size_t | idx | ||
) |
Retrieve the name of the layer at the specified index.
[in] | io | io object |
[in] | idx | index of layer (0 - M_io_layer_count()) |
M_io_error_t M_io_get_error | ( | M_io_t * | io | ) |
Get the last error associated with the io object.
[in] | io | io object. |
void M_io_get_error_string | ( | M_io_t * | io, |
char * | error, | ||
size_t | err_len | ||
) |
Get a textual error message associated with the io object.
This message is populated by the layer that reported the error. The message could come from an external library such as an TLS library. It is meant to be a human readable description and should not be used programmatically.
[in] | io | io object. |
[out] | error | Error buffer. |
[in] | err_len | Size of error buffer. |
M_bool M_io_reconnect | ( | M_io_t * | io | ) |
Request system to tear down existing connection and reconnect using the same configuration and layers as are currently in use. Will preserve existing event handle and callbacks.
[in] | io | io object. |
void M_io_disconnect | ( | M_io_t * | comm | ) |
Gracefully issue a disconnect to the communications object, a DISCONNECTED (or ERROR) event will be triggered when complete.
[in] | comm | io object. |
M_bool M_io_close | ( | M_io_t * | comm | ) |
Forcibly close the io object without destroying the entire object. If the connection is still active, this will perform a dirty disconnect (not recommended).
This is primarily used after receiving a disconnect or error event with the anticipation of performing a reconnect at some point in the future, but not immediately.
This will detach from the event subsystem and clean up the OS handles.
[in] | comm | io object. |
M_bool M_io_is_user_initiated_disconnect | ( | M_io_t * | io | ) |
Query if disconnect/error might have been generated by a call to M_io_disconnect() rather than triggered by a system-level event.
This might be useful for things like HTTP connections where we can M_io_reconnect() after a remote disconnect.
[in] | io | io object. |
void M_io_destroy | ( | M_io_t * | comm | ) |
Destroy any communications object.
This can be called from a different thread than the thread the event loop the io object is running on. When this happens the destroy is queued and will happen once the event loop the io object is associated with has finished processing all queued events.
[in] | comm | io object. |