terom@1: terom@1: #include "sock_internal.h" terom@2: #include "sock_gnutls.h" terom@2: terom@3: #include terom@3: terom@9: // global sock_stream_ctx instance terom@9: struct sock_stream_ctx _sock_stream_ctx; terom@9: terom@9: err_t sock_init (struct event_base *ev_base, struct error_info *err) terom@2: { terom@9: // store ev_base terom@9: _sock_stream_ctx.ev_base = ev_base; terom@9: terom@4: // XXX: just call these all directly for now terom@5: if (sock_gnutls_global_init(err)) terom@4: return ERROR_CODE(err); terom@3: terom@4: // done terom@4: return SUCCESS; terom@2: } terom@1: terom@3: void sock_stream_init (struct sock_stream *sock, struct sock_stream_type *type) terom@3: { terom@3: // be strict terom@3: assert(sock->type == NULL); terom@3: terom@3: // store type terom@3: sock->type = type; terom@3: } terom@3: terom@9: void sock_stream_set_callbacks (struct sock_stream *sock, const struct sock_stream_callbacks *callbacks, void *arg) terom@9: { terom@9: // store terom@9: sock->cb_info = callbacks; terom@9: sock->cb_arg = arg; terom@9: } terom@9: terom@3: err_t sock_stream_read (struct sock_stream *sock, void *buf, size_t len) terom@1: { terom@1: // proxy off to method handler terom@1: return sock->type->methods.read(sock, buf, len); terom@1: } terom@1: terom@3: err_t sock_stream_write (struct sock_stream *sock, const void *buf, size_t len) terom@1: { terom@1: // proxy off to method handler terom@1: return sock->type->methods.write(sock, buf, len); terom@1: } terom@1: terom@8: const struct error_info* sock_stream_error (struct sock_stream *sock) terom@3: { terom@8: // return pointer terom@8: return SOCK_ERR(sock); terom@3: }