Unified bufferd network I/O

## Unified bufferd network I/O Unified bufferd network I/O — Posix style buffered network input/output. |

## Synopsis

    typedef             MateVFSSocketBuffer;
    MateVFSSocketBuffer *  mate_vfs_socket_buffer_new     (MateVFSSocket *socket);
    MateVFSResult      mate_vfs_socket_buffer_destroy     (MateVFSSocketBuffer *socket_buffer,
                                                             gboolean close_socket,
                                                             MateVFSCancellation *cancellation);
    MateVFSResult      mate_vfs_socket_buffer_read        (MateVFSSocketBuffer *socket_buffer,
                                                             gpointer buffer,
                                                             MateVFSFileSize bytes,
                                                             MateVFSFileSize *bytes_read,
                                                             MateVFSCancellation *cancellation);
    MateVFSResult      mate_vfs_socket_buffer_peekc       (MateVFSSocketBuffer *socket_buffer,
                                                             char *character,
                                                             MateVFSCancellation *cancellation);
    MateVFSResult      mate_vfs_socket_buffer_write       (MateVFSSocketBuffer *socket_buffer,
                                                             gconstpointer buffer,
                                                             MateVFSFileSize bytes,
                                                             MateVFSFileSize *bytes_written,
                                                             MateVFSCancellation *cancellation);
    MateVFSResult      mate_vfs_socket_buffer_flush       (MateVFSSocketBuffer *socket_buffer,
                                                             MateVFSCancellation *cancellation);
    MateVFSResult      mate_vfs_socket_buffer_read_until  (MateVFSSocketBuffer *socket_buffer,
                                                             gpointer buffer,
                                                             MateVFSFileSize bytes,
                                                             gconstpointer boundary,
                                                             MateVFSFileSize boundary_len,
                                                             MateVFSFileSize *bytes_read,
                                                             gboolean *got_boundary,
                                                             MateVFSCancellation *cancellation);

## Description

The MateVFSSocketBuffer functions are very similar to the MateVFSSocket ones. The only difference is that all input/output is done through an internally managed buffer. This might increase I/O performance as well as give you the possibility to use some convenient functions like mate_vfs_socket_buffer_peekc and mate_vfs_socket_buffer_read_until.

You can manually force all internally buffered data to get written with mate_vfs_socket_buffer_flush.

## Details

### MateVFSSocketBuffer

    typedef struct MateVFSSocketBuffer MateVFSSocketBuffer;

A handle to a socket buffer. A socket buffer is a temporary in-memory storage for data that is read from or written to a MateVFSSocket.

### mate_vfs_socket_buffer_new ()

    MateVFSSocketBuffer *  mate_vfs_socket_buffer_new     (MateVFSSocket *socket);

Create a socket buffer around `socket`. A buffered socket allows data to be poked at without reading it as it will be buffered. A future read will retrieve the data again.

`socket` : | socket to be buffered.
Returns : | a newly allocated MateVFSSocketBuffer.

### mate_vfs_socket_buffer_destroy ()

    MateVFSResult      mate_vfs_socket_buffer_destroy     (MateVFSSocketBuffer *socket_buffer,
                                                             gboolean close_socket,
                                                             MateVFSCancellation *cancellation);

Free the socket buffer.

`socket_buffer` : | buffered socket to destroy.
`close_socket` : | if `TRUE`, the socket being buffered will be closed.
`cancellation` : | handle allowing cancellation of the operation.
Returns : | MateVFSResult indicating the success of the operation.

### mate_vfs_socket_buffer_read ()

    MateVFSResult      mate_vfs_socket_buffer_read        (MateVFSSocketBuffer *socket_buffer,
                                                             gpointer buffer,
                                                             MateVFSFileSize bytes,
                                                             MateVFSFileSize *bytes_read,
                                                             MateVFSCancellation *cancellation);

Read `bytes` bytes of data from the `socket` into `socket_buffer`.

`socket_buffer` : | buffered socket to read data from.
`buffer` : | allocated buffer of at least `bytes` bytes to be read into.
`bytes` : | number of bytes to read from `socket_buffer` into `buffer`.
`bytes_read` : | pointer to a MateVFSFileSize, will contain the number of bytes actually read from the `socket_buffer` on return.
`cancellation` : | handle allowing cancellation of the operation.
Returns : | MateVFSResult indicating the success of the operation.

### mate_vfs_socket_buffer_peekc ()

    MateVFSResult      mate_vfs_socket_buffer_peekc       (MateVFSSocketBuffer *socket_buffer,
                                                             char *character,
                                                             MateVFSCancellation *cancellation);

Peek at the next character in `socket_buffer` without actually reading the character in. The next read will retrieve `c` (as well as any following data if requested).

`socket_buffer` : | the socket buffer to read from.
`character` : | pointer to a char, will contain a character on return from a successful "peek".
`cancellation` : | handle allowing cancellation of the operation.
Returns : | MateVFSResult indicating the success of the operation.

### mate_vfs_socket_buffer_write ()

    MateVFSResult      mate_vfs_socket_buffer_write       (MateVFSSocketBuffer *socket_buffer,
                                                             gconstpointer buffer,
                                                             MateVFSFileSize bytes,
                                                             MateVFSFileSize *bytes_written,
                                                             MateVFSCancellation *cancellation);

Write `bytes` bytes of data from `buffer` to `socket_buffer`.

`socket_buffer` : | buffered socket to write data to.
`buffer` : | data to write to the `socket_buffer`.
`bytes` : | number of bytes to write from `buffer` to `socket_buffer`.
`bytes_written` : | pointer to a MateVFSFileSize, will contain the number of bytes actually written to the `socket_buffer` on return.
`cancellation` : | handle allowing cancellation of the operation.
Returns : | MateVFSResult indicating the success of the operation.

### mate_vfs_socket_buffer_flush ()

    MateVFSResult      mate_vfs_socket_buffer_flush       (MateVFSSocketBuffer *socket_buffer,
                                                             MateVFSCancellation *cancellation);

Write all outstanding data to `socket_buffer`.

`socket_buffer` : | buffer to flush.
`cancellation` : | handle allowing cancellation of the operation.
Returns : | MateVFSResult indicating the success of the operation.

### mate_vfs_socket_buffer_read_until ()

    MateVFSResult      mate_vfs_socket_buffer_read_until  (MateVFSSocketBuffer *socket_buffer,
                                                             gpointer buffer,
                                                             MateVFSFileSize bytes,
                                                             gconstpointer boundary,
                                                             MateVFSFileSize boundary_len,
                                                             MateVFSFileSize *bytes_read,
                                                             gboolean *got_boundary,
                                                             MateVFSCancellation *cancellation);

Read up to `bytes` bytes of data from the `socket_buffer` into `buffer` until boundary is reached. `got_boundary` will be set accordingly.

Note that if `bytes` is smaller than `boundary_len` there is no way to detected the boundary! So if you want to make sure that every boundary is found (in a loop maybe) assure that `bytes` is at least as big as `boundary_len`.

`socket_buffer` : | buffered socket to read data from.
`buffer` : | allocated buffer of at least `bytes` bytes to be read into.
`bytes` : | maximum number of bytes to read from `socket_buffer` into `buffer`.
`boundary` : | the boundary until which is read.
`boundary_len` : | the length of the `boundary`.
`bytes_read` : | pointer to a MateVFSFileSize, will contain the number of bytes actually read from the `socket_buffer` on return.
`got_boundary` : | pointer to a gboolean which will be `TRUE` if the boundary was found or `FALSE` otherwise.
`cancellation` : | handle allowing cancellation of the operation.
Returns : | MateVFSResult indicating the success of the operation.

Since 2.8