src/sock_test.h
changeset 40 51678c7eae03
child 41 40f7aa051acb
equal deleted inserted replaced
39:a4891d71aca9 40:51678c7eae03
       
     1 #ifndef SOCK_TEST_H
       
     2 #define SOCK_TEST_H
       
     3 
       
     4 /**
       
     5  * @file
       
     6  *
       
     7  * Dummy sock_stream implemention for local testing.
       
     8  */
       
     9 #include "sock_internal.h"
       
    10 
       
    11 /**
       
    12  * IO vector
       
    13  */
       
    14 struct io_vec {
       
    15     /** The buffer */
       
    16     char *buf;
       
    17 
       
    18     /** Buffer size */
       
    19     size_t len;
       
    20 };
       
    21 
       
    22 /**
       
    23  * Vectored IO-buffer
       
    24  */
       
    25 struct io_buf {
       
    26     /** The array of buffer-vectors, {NULL}-terminated */
       
    27     struct io_vec *vecs;
       
    28 
       
    29     /** The number of io_vecs */
       
    30     size_t count;
       
    31 
       
    32     /** Current vector */
       
    33     struct io_vec *vec;
       
    34 
       
    35     /** Offset into current vector */
       
    36     size_t off;
       
    37 };
       
    38 
       
    39 /**
       
    40  * The per-socket state
       
    41  */
       
    42 struct sock_test {
       
    43     /** The base struct for sock_stream_* functions */
       
    44     struct sock_stream base;
       
    45 
       
    46     /** The send/recieve buffers */
       
    47     struct io_buf send_buf, recv_buf;
       
    48 };
       
    49 
       
    50 /**
       
    51  * Get a sock_stream pointer from a sock_tcp pointer
       
    52  */
       
    53 #define SOCK_TEST_BASE(sock_ptr) (&(sock_ptr)->base)
       
    54 
       
    55 /**
       
    56  * A dummy stream socket intended for testing purposes.
       
    57  */
       
    58 struct sock_test* sock_test_create (void);
       
    59 
       
    60 /**
       
    61  * Set the recieve buffer contents.
       
    62  *
       
    63  * The data is not copied, but the vectors are stored as-is.
       
    64  */
       
    65 void sock_test_set_recv_buffer (struct sock_test *sock, struct io_vec *vecs, size_t count);
       
    66 
       
    67 /**
       
    68  * Get the send buffer contents as a single string, free() after use if you care about that
       
    69  */
       
    70 void sock_test_get_send_data (struct sock_test *sock, char **buf, size_t *len);
       
    71 
       
    72 #endif