src/sock.c
author Tero Marttila <terom@fixme.fi>
Sun, 22 Feb 2009 06:44:16 +0200
changeset 3 cc94ae754e2a
parent 2 a834f0559939
child 4 a3ca0f97a075
permissions -rw-r--r--
error handling magic

#include "sock_internal.h"
#include "sock_gnutls.h"

#include <assert.h>

err_t sock_init (void)
{
    err_t err;

    // XXX: just call these all directly for now

    if ((err = sock_gnutls_init()))
        return err;
}

void sock_stream_init (struct sock_stream *sock, struct sock_stream_type *type)
{
    // be strict
    assert(sock->type == NULL);

    // store type
    sock->type = type;
}

err_t sock_stream_read (struct sock_stream *sock, void *buf, size_t len)
{
    // proxy off to method handler
    return sock->type->methods.read(sock, buf, len);
}

err_t sock_stream_write (struct sock_stream *sock, const void *buf, size_t len)
{
    // proxy off to method handler
    return sock->type->methods.write(sock, buf, len);
}

void sock_stream_error (struct sock_stream *sock, struct error_info *err)
{
    // copy from SOCK_ER
    *err = SOCK_ERR(sock);
}