|
M_io_error_t | M_io_block_connect (M_io_t *io) |
|
M_io_error_t | M_io_block_accept (M_io_t **io_out, M_io_t *server_io, M_uint64 timeout_ms) |
|
M_io_error_t | M_io_block_read (M_io_t *io, unsigned char *buf, size_t buf_len, size_t *len_read, M_uint64 timeout_ms) |
|
M_io_error_t | M_io_block_read_into_buf (M_io_t *io, M_buf_t *buf, M_uint64 timeout_ms) |
|
M_io_error_t | M_io_block_read_into_parser (M_io_t *io, M_parser_t *parser, M_uint64 timeout_ms) |
|
M_io_error_t | M_io_block_write (M_io_t *io, const unsigned char *buf, size_t buf_len, size_t *len_written, M_uint64 timeout_ms) |
|
M_io_error_t | M_io_block_write_from_buf (M_io_t *io, M_buf_t *buf, M_uint64 timeout_ms) |
|
M_io_error_t | M_io_block_disconnect (M_io_t *io) |
|
The io system can be used with blocking operations. An explicit event loop is not required. This allows the stacked layers to be utilized with a more traditional blocking design.
Here is an example of the system using the loopback io back end to simulate a network connection to a remote server.
#include <mstdlib/mstdlib.h>
#include <mstdlib/mstdlib_io.h>
int main(int argc, char *argv)
{
char *out;
return 0;
}
struct M_buf M_buf_t
Definition: m_buf.h:77
M_buf_t * M_buf_create(void) M_WARN_UNUSED_RESULT M_MALLOC
void M_buf_add_str(M_buf_t *buf, const char *str)
void M_buf_cancel(M_buf_t *buf) M_FREE(1)
ssize_t M_printf(const char *fmt,...)
M_io_error_t M_io_block_write_from_buf(M_io_t *io, M_buf_t *buf, M_uint64 timeout_ms)
M_io_error_t M_io_block_disconnect(M_io_t *io)
M_io_error_t M_io_block_read_into_parser(M_io_t *io, M_parser_t *parser, M_uint64 timeout_ms)
M_io_error_t M_io_block_connect(M_io_t *io)
M_io_error_t M_io_loopback_create(M_io_t **io_out)
struct M_io M_io_t
Definition: m_io.h:59
void M_free(void *ptr) M_FREE(1)
size_t M_parser_len(const M_parser_t *parser)
void M_parser_destroy(M_parser_t *parser)
char * M_parser_read_strdup(M_parser_t *parser, size_t len)
struct M_parser M_parser_t
Definition: m_parser.h:52
M_parser_t * M_parser_create(M_uint32 flags)
@ M_PARSER_FLAG_NONE
Definition: m_parser.h:60
◆ M_io_block_connect()
Connect the io object to the remote end point.
- Parameters
-
- Returns
- Result.
◆ M_io_block_accept()
Accept an io connection.
- Parameters
-
[out] | io_out | io object created from the accept. |
[in] | server_io | io object which was listening. |
[in] | timeout_ms | Amount of time in milliseconds to wait for data. |
- Returns
- Result.
◆ M_io_block_read()
M_io_error_t M_io_block_read |
( |
M_io_t * |
io, |
|
|
unsigned char * |
buf, |
|
|
size_t |
buf_len, |
|
|
size_t * |
len_read, |
|
|
M_uint64 |
timeout_ms |
|
) |
| |
Read from an io object.
- Parameters
-
[in] | io | 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] | timeout_ms | Amount of time in milliseconds to wait for data. |
- Returns
- Result.
◆ M_io_block_read_into_buf()
Read from an io object into an M_buf_t.
This will read all available data into the buffer.
- Parameters
-
[in] | io | io object. |
[out] | buf | Buffer to store data read from io object. |
[in] | timeout_ms | Amount of time in milliseconds to wait for data. |
- Returns
- Result.
◆ M_io_block_read_into_parser()
Read from an io object into an M_parser_t.
This will read all available data into the buffer.
- Parameters
-
[in] | io | io object. |
[out] | parser | Parser to store data read from io object. |
[in] | timeout_ms | Amount of time in milliseconds to wait for data. |
- Returns
- Result.
◆ M_io_block_write()
M_io_error_t M_io_block_write |
( |
M_io_t * |
io, |
|
|
const unsigned char * |
buf, |
|
|
size_t |
buf_len, |
|
|
size_t * |
len_written, |
|
|
M_uint64 |
timeout_ms |
|
) |
| |
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 try again.
- Parameters
-
[in] | io | 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] | timeout_ms | Amount of time in milliseconds to wait for data. |
- Returns
- Result.
◆ M_io_block_write_from_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 try again.
- Parameters
-
[in] | io | io object. |
[in] | buf | Buffer to write from. |
[in] | timeout_ms | Amount of time in milliseconds to wait for data. |
- Returns
- Result.
◆ M_io_block_disconnect()
Gracefully issue a disconnect to the communications object.
- Parameters
-
- Returns
- Result.