libEtPan! API
Prev | Chapter 2. Tools and datatypes | Next

# non-buffered I/O

    #include <libetpan/libetpan.h>

    struct mailstream_low_driver {
      ssize_t (* mailstream_read)(mailstream_low *, void *, size_t);
      ssize_t (* mailstream_write)(mailstream_low *, void *, size_t);
      int (* mailstream_close)(mailstream_low *);
      int (* mailstream_get_fd)(mailstream_low *);
      void (* mailstream_free)(mailstream_low *);
    };

    typedef struct mailstream_low_driver mailstream_low_driver;

    struct _mailstream_low {
      void * data;
      mailstream_low_driver * driver;
    };

mailstream_low is a non-buffered stream.

The mailstream_low_driver is a set of functions used to access the stream.

- mailstream_read/write/close() is the same interface as read/write/close() system calls, except that the file descriptor is replaced with the mailstream_low structure.

- mailstream_get_fd() returns the file descriptor used for this non-buffered stream.

- mailstream_free() is in charge to free the internal structure of the mailstream_low and the mailstream_low itself.

    mailstream_low * mailstream_low_new(void * data,
        mailstream_low_driver * driver);

mailstream_low_new() creates a low-level mailstream with the given internal structure (data) and using the given set of functions (driver).

    ssize_t mailstream_low_write(mailstream_low * s, void * buf, size_t count);

    ssize_t mailstream_low_read(mailstream_low * s, void * buf, size_t count);

    int mailstream_low_close(mailstream_low * s);

    int mailstream_low_get_fd(mailstream_low * s);

    void mailstream_low_free(mailstream_low * s);

Each of these calls will call the corresponding function defined in the driver.

Prev | Home | Next
Buffered I/O | Up | strings