Skip to content

File io.h

FileList > docs > sandwich_c > io.h

Go to the source code of this file

I/O abstraction for Sandwich.

  • #include <sys/types.h>
  • #include "sandwich_c/export.h"
  • #include "sandwich_c/ioerrors.h"

Classes

Type Name
struct SandwichIO
A generic I/O interface.
struct SandwichIOOwned
An IO owned by the Sandwich Library.

Public Types

Type Name
typedef SandwichIOFlushFunction * SandwichIOFlushFunctionPtr
typedef size_t() SandwichIOReadFunction
Read function for the I/O interface.
typedef SandwichIOReadFunction * SandwichIOReadFunctionPtr
typedef size_t() SandwichIOWriteFunction
Write function for the I/O interface.
typedef SandwichIOWriteFunction * SandwichIOWriteFunctionPtr
typedef void() SandwichOwnedIOFreeFunction
A destructor function for owned I/O interface.
typedef SandwichOwnedIOFreeFunction * SandwichOwnedIOFreeFunctionPtr

Public Functions

Type Name
enum SandwichIOError() SandwichIOFlushFunction (void * uarg)
Flush function for the I/O interface.
SANDWICH_API enum SandwichIOError sandwich_io_client_tcp_new (const char * hostname, uint16_t port, bool async, struct SandwichIOOwned ** ownedIO)
Creates a TCP based IO object to be used as an IO.
SANDWICH_API void sandwich_io_owned_free (struct SandwichIOOwned * ownedIO)
Frees a SandwichIOOwned object created by one of the sandwich_io_*_new() functions.
SANDWICH_API enum SandwichIOError sandwich_io_socket_wrap_new (int fd, struct SandwichIOOwned ** ownedIO)
Creates an IO object that wraps a UNIX socket.

Public Types Documentation

typedef SandwichIOFlushFunctionPtr

typedef SandwichIOFlushFunction* SandwichIOFlushFunctionPtr;

typedef SandwichIOReadFunction

Read function for the I/O interface.

typedef size_t() SandwichIOReadFunction(void *uarg, void *buf, size_t count, enum SandwichIOError *err);

Parameters:

  • uarg User opaque argument.
  • buf Destination buffer.
  • count Amount of bytes to read.
  • err Error, if any.

Returns:

The amount of bytes successfully read, or 0.

typedef SandwichIOReadFunctionPtr

typedef SandwichIOReadFunction* SandwichIOReadFunctionPtr;

typedef SandwichIOWriteFunction

Write function for the I/O interface.

typedef size_t() SandwichIOWriteFunction(void *uarg, const void *buf, size_t count, enum SandwichIOError *err);

Parameters:

  • uarg User opaque argument.
  • buf Source buffer.
  • count Amount of bytes to write.
  • err Error, if any.

Returns:

The amount of bytes successfully written, or 0.

typedef SandwichIOWriteFunctionPtr

typedef SandwichIOWriteFunction* SandwichIOWriteFunctionPtr;

typedef SandwichOwnedIOFreeFunction

typedef void() SandwichOwnedIOFreeFunction(struct SandwichIO *io);

typedef SandwichOwnedIOFreeFunctionPtr

typedef SandwichOwnedIOFreeFunction* SandwichOwnedIOFreeFunctionPtr;

Public Functions Documentation

function SandwichIOFlushFunction

Flush function for the I/O interface.

enum SandwichIOError () SandwichIOFlushFunction (
    void * uarg
) 

Parameters:

  • uarg User opaque argument.

Returns:

IOERROR_OK if success, else an IO error.

function sandwich_io_client_tcp_new

Creates a TCP based IO object to be used as an IO.

SANDWICH_API enum SandwichIOError sandwich_io_client_tcp_new (
    const char * hostname,
    uint16_t port,
    bool async,
    struct SandwichIOOwned ** ownedIO
) 

Parameters:

  • hostname the hostname of the target server.
  • port the port number of the target server.
  • async indicates whether sockets should be non-blocking or not.
  • ownedIO the created TCP based sandwich owned IO object.

Returns:

IOERROR_OK if the operation was a success, otherwise returns the error that occurred.

function sandwich_io_owned_free

SANDWICH_API void sandwich_io_owned_free (
    struct SandwichIOOwned * ownedIO
) 

function sandwich_io_socket_wrap_new

Creates an IO object that wraps a UNIX socket.

SANDWICH_API enum SandwichIOError sandwich_io_socket_wrap_new (
    int fd,
    struct SandwichIOOwned ** ownedIO
) 

Parameters:

  • fd the file descriptor of the unix socket.
  • ownedIO the created UNIX socket sandwich owned IO object. The caller is responsible for freeing that object with sandwich_io_owned_free.

Returns:

IOERROR_OK if the operation was a success, otherwise returns the error that occurred.


The documentation for this class was generated from the following file docs/sandwich_c/io.h