src/sock_test.h
changeset 40 51678c7eae03
child 41 40f7aa051acb
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/sock_test.h	Thu Mar 12 20:00:48 2009 +0200
@@ -0,0 +1,72 @@
+#ifndef SOCK_TEST_H
+#define SOCK_TEST_H
+
+/**
+ * @file
+ *
+ * Dummy sock_stream implemention for local testing.
+ */
+#include "sock_internal.h"
+
+/**
+ * IO vector
+ */
+struct io_vec {
+    /** The buffer */
+    char *buf;
+
+    /** Buffer size */
+    size_t len;
+};
+
+/**
+ * Vectored IO-buffer
+ */
+struct io_buf {
+    /** The array of buffer-vectors, {NULL}-terminated */
+    struct io_vec *vecs;
+
+    /** The number of io_vecs */
+    size_t count;
+
+    /** Current vector */
+    struct io_vec *vec;
+
+    /** Offset into current vector */
+    size_t off;
+};
+
+/**
+ * The per-socket state
+ */
+struct sock_test {
+    /** The base struct for sock_stream_* functions */
+    struct sock_stream base;
+
+    /** The send/recieve buffers */
+    struct io_buf send_buf, recv_buf;
+};
+
+/**
+ * Get a sock_stream pointer from a sock_tcp pointer
+ */
+#define SOCK_TEST_BASE(sock_ptr) (&(sock_ptr)->base)
+
+/**
+ * A dummy stream socket intended for testing purposes.
+ */
+struct sock_test* sock_test_create (void);
+
+/**
+ * Set the recieve buffer contents.
+ *
+ * The data is not copied, but the vectors are stored as-is.
+ */
+void sock_test_set_recv_buffer (struct sock_test *sock, struct io_vec *vecs, size_t count);
+
+/**
+ * Get the send buffer contents as a single string, free() after use if you care about that
+ */
+void sock_test_get_send_data (struct sock_test *sock, char **buf, size_t *len);
+
+#endif