src/transport_test.h
author Tero Marttila <terom@fixme.fi>
Sun, 03 May 2009 17:19:05 +0300
branchnew-transport
changeset 166 cb8cb023cf06
parent 85 src/sock_test.h@75bc8b164ef8
child 196 873796250c60
permissions -rw-r--r--
replace old sock_test with new transport_test
#ifndef TRANSPORT_TEST_H
#define TRANSPORT_TEST_H

/**
 * @file
 *
 * Dummy transport implemention for local testing.
 */
#include "transport.h"

/**
 * The opaque transport state
 */
struct transport_test;

/**
 * Construct a new, empty, connected transport_test.
 */
struct transport_test* transport_test_create (struct transport_info *info);

/**
 * A transport_test is a valid transport, this performs the cast
 */
transport_t* transport_test_cast (struct transport_test *tp);

/**
 * Invoke the transport's user callbacks for the given event mask, unless masked out.
 */
void transport_test_event (struct transport_test *tp, short what);

/**
 * Adds a data buffer to the recieve buffer.
 *
 * The given data is copied.
 *
 * If events are enabled, they are triggered.
 */
void transport_test_push_buf (struct transport_test *tp, const char *buf, size_t len);

/**
 * Add a string to the recieve buffer using transport_test_push_buf()
 */
void transport_test_push_str (struct transport_test *tp, const char *str);

/**
 * Maximum length of a formatted string pushed
 */
#define TRANSPORT_TEST_FMT_MAX 4096

/**
 * Add a formatted string to the recieve buffer
 *
 * @see TRANSPORT_TEST_FMT_MAX
 */
void transport_test_push_fmt (struct transport_test *tp, const char *fmt, ...);

/**
 * Set EOF on recv.
 */
void transport_test_push_eof (struct transport_test *tp);

/**
 * Get the send buffer contents as a single buffer, free() after use.
 *
 * This clears the send buffer, so this doesn't return the same data twice.
 */
void transport_test_pull_buf (struct transport_test *tp, char **buf_ptr, size_t *len_ptr);

/**
 * Destroy the transport buffer, releasing any buffers we allocated ourself
 */
void transport_test_destroy (struct transport_test *tp);

#endif /* TRANSPORT_TEST_H */