src/sock.c
author Tero Marttila <terom@fixme.fi>
Sun, 22 Feb 2009 07:08:57 +0200
changeset 5 a09a0797f6f0
parent 4 a3ca0f97a075
child 8 be88e543c8ff
permissions -rw-r--r--
ERROR-ify sock_gnutls

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

#include <assert.h>

err_t sock_init (struct error_info *err)
{
    // XXX: just call these all directly for now
    if (sock_gnutls_global_init(err))
        return ERROR_CODE(err);

    // done
    return SUCCESS;
}

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);
}