src/sock.c
changeset 3 cc94ae754e2a
parent 2 a834f0559939
child 4 a3ca0f97a075
equal deleted inserted replaced
2:a834f0559939 3:cc94ae754e2a
     1 
     1 
     2 #include "sock_internal.h"
     2 #include "sock_internal.h"
     3 #include "sock_gnutls.h"
     3 #include "sock_gnutls.h"
     4 
     4 
     5 void sock_init (void)
     5 #include <assert.h>
       
     6 
       
     7 err_t sock_init (void)
     6 {
     8 {
     7     // XXX: just call directly for now
     9     err_t err;
     8     sock_gnutls_init();
    10 
       
    11     // XXX: just call these all directly for now
       
    12 
       
    13     if ((err = sock_gnutls_init()))
       
    14         return err;
     9 }
    15 }
    10 
    16 
    11 int sock_stream_read (struct sock_stream *sock, void *buf, size_t len)
    17 void sock_stream_init (struct sock_stream *sock, struct sock_stream_type *type)
       
    18 {
       
    19     // be strict
       
    20     assert(sock->type == NULL);
       
    21 
       
    22     // store type
       
    23     sock->type = type;
       
    24 }
       
    25 
       
    26 err_t sock_stream_read (struct sock_stream *sock, void *buf, size_t len)
    12 {
    27 {
    13     // proxy off to method handler
    28     // proxy off to method handler
    14     return sock->type->methods.read(sock, buf, len);
    29     return sock->type->methods.read(sock, buf, len);
    15 }
    30 }
    16 
    31 
    17 int sock_stream_write (struct sock_stream *sock, const void *buf, size_t len)
    32 err_t sock_stream_write (struct sock_stream *sock, const void *buf, size_t len)
    18 {
    33 {
    19     // proxy off to method handler
    34     // proxy off to method handler
    20     return sock->type->methods.write(sock, buf, len);
    35     return sock->type->methods.write(sock, buf, len);
    21 }
    36 }
    22 
    37 
       
    38 void sock_stream_error (struct sock_stream *sock, struct error_info *err)
       
    39 {
       
    40     // copy from SOCK_ER
       
    41     *err = SOCK_ERR(sock);
       
    42 }