#include "sock_internal.h"
#include "sock_gnutls.h"
#include <assert.h>
// global sock_stream_ctx instance
struct sock_stream_ctx _sock_stream_ctx;
err_t sock_init (struct event_base *ev_base, struct error_info *err)
{
// store ev_base
_sock_stream_ctx.ev_base = ev_base;
// 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;
}
void sock_stream_set_callbacks (struct sock_stream *sock, const struct sock_stream_callbacks *callbacks, void *arg)
{
// store
sock->cb_info = callbacks;
sock->cb_arg = arg;
}
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);
}