src/sock.c
author Tero Marttila <terom@fixme.fi>
Sun, 22 Feb 2009 08:21:22 +0200
changeset 8 be88e543c8ff
parent 5 a09a0797f6f0
child 9 4c4c906cc649
permissions -rw-r--r--
split off line_proto, and make sock_stream_error return a const error_info

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

const struct error_info* sock_stream_error (struct sock_stream *sock)
{
    // return pointer
    return SOCK_ERR(sock);
}