Created
October 26, 2016 09:14
-
-
Save edenhill/f369268986c89095562cd45b0dbf5a2b to your computer and use it in GitHub Desktop.
Test sockets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @brief Test sockets | |
* | |
* By plugging in to librdkafka's socket_cb and connect_cb the test framework | |
* adds an interim socket between the socket exposed to librdkafka (tsk_fd) | |
* and the socket connecting to the broker (tsk_intfd). | |
* A thread is created to pass data between the two sockets according | |
* to test parameters. | |
* This allows the following network simulations: | |
* - connection close (abrupt or timeout) | |
* - throughput limiting | |
* - delay & jitter | |
*/ | |
#include "../src/rdsysqueue.h" | |
typedef struct test_socket_s { | |
LIST_ENTRY(test_socket_s) tsk_link; | |
int tsk_fd; /* public fd */ | |
int tsk_intfd; /* internal fd */ | |
thrd_t tsk_thrd; | |
mtx_t tsk_lock: /* protects the fields below */ | |
int tsk_thruput; /* bytes per second */ | |
int tsk_delay; /* ms */ | |
int tsk_jitter; /* ms, variation */ | |
} test_socket_t; | |
/** | |
* @brief Update socket characteristics | |
*/ | |
test_socket_t *test_socket_set_params (test_socket_t *tsk, | |
int thruput, int delay, int jitter); | |
/** | |
* @brief Close both sockets, frees the \p tsk. | |
*/ | |
void test_socket_close (test_socket_t *tsk); | |
/** | |
* @brief Find socket by \p peer | |
*/ | |
test_socket_t *test_socket_find (struct test *test, | |
const struct sockaddr *peer); | |
/** | |
* @brief Create new tsk (from socket_cb) and create socket fd. | |
*/ | |
test_socket_t *test_socket_new (struct test *test, | |
int domain, int type, int protocol); | |
/** | |
* @brief Connect socket | |
*/ | |
int test_socket_connect (test_socket_t *tsk, const struct sockaddr *peer); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment