src/sock_internal.h
author Tero Marttila <terom@fixme.fi>
Sun, 22 Feb 2009 03:57:44 +0200
changeset 1 cf0e1bb6bcab
child 3 cc94ae754e2a
permissions -rw-r--r--
a fancy socket abstraction layer, with TCP, next, SSL. Also, .hgignore
#ifndef SOCK_INTERNAL_H
#define SOCK_INTERNAL_H

#include "sock.h"

/*
 * The base type struct, which defines the method table.
 */
struct sock_stream_type {
    /* method table */
    struct sock_stream_methods {
        /* Normal read(2) */
        int (*read) (struct sock_stream *sock, void *buf, size_t len);

        /* Normal write(2) */
        int (*write) (struct sock_stream *sock, const void *buf, size_t len);

    } methods;
};

/*
 * The base sock_stream type, as used by the sock_stream_* functions.
 *
 * The specific implementations should embed this at the start of their type-specific struct, and then cast around
 * as appropriate.
 */
struct sock_stream {
    struct sock_stream_type *type;
};

#define SOCK_FROM_BASE(sock, type) ((type*) sock)

#endif /* SOCK_INTERNAL_H */