src/sock.c
changeset 3 cc94ae754e2a
parent 2 a834f0559939
child 4 a3ca0f97a075
--- a/src/sock.c	Sun Feb 22 05:27:29 2009 +0200
+++ b/src/sock.c	Sun Feb 22 06:44:16 2009 +0200
@@ -2,21 +2,41 @@
 #include "sock_internal.h"
 #include "sock_gnutls.h"
 
-void sock_init (void)
+#include <assert.h>
+
+err_t sock_init (void)
 {
-    // XXX: just call directly for now
-    sock_gnutls_init();
+    err_t err;
+
+    // XXX: just call these all directly for now
+
+    if ((err = sock_gnutls_init()))
+        return err;
 }
 
-int sock_stream_read (struct sock_stream *sock, void *buf, size_t len)
+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);
 }
 
-int sock_stream_write (struct sock_stream *sock, const void *buf, size_t 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);
+}