tor_multipath_voip/src/algo_rr.c

59 lines
1.8 KiB
C

#include "algo_skel.h"
#include "algo_utils.h"
void algo_rr(struct algo_skel* as) {
struct algo_ctx* ctx = malloc(sizeof(struct algo_ctx));
if (ctx == NULL) goto init_err;
memset(ctx, 0, sizeof(struct algo_ctx));
ctx->free_buffer = g_queue_new ();
ctx->read_waiting = g_queue_new ();
ctx->used_buffer = g_hash_table_new(g_int_hash, g_int_equal);
ctx->write_waiting = g_hash_table_new_full (g_int_hash, g_int_equal, NULL, naive_free_simple);
for (int i = 0; i < sizeof(ctx->bps) / sizeof(ctx->bps[0]); i++) {
g_queue_push_tail(ctx->free_buffer, &(ctx->bps[i]));
}
/*
as->on_tcp_co.name = "tcp-listen";
as->on_tcp_co.flags = EPOLLIN;
as->on_tcp_co.free_app_ctx = free_nothing;
as->on_tcp_co.cb = on_tcp_co;
as->on_tcp_read.name = "tcp-read";
as->on_tcp_read.flags = EPOLLIN | EPOLLET | EPOLLRDHUP;
as->on_tcp_read.app_ctx = ctx;
as->on_tcp_read.free_app_ctx = free_naive;
as->on_tcp_read.cb = on_tcp_read;
as->on_tcp_read.err_cb = on_err;
ctx->ref_count++;
as->on_udp_read.name = "udp-read";
as->on_udp_read.flags = EPOLLIN | EPOLLET;
as->on_udp_read.app_ctx = ctx;
as->on_udp_read.free_app_ctx = free_naive;
as->on_udp_read.cb = on_udp_read;
as->on_udp_read.err_cb = on_err;
ctx->ref_count++;
as->on_tcp_write.name = "tcp-write";
as->on_tcp_write.flags = EPOLLOUT | EPOLLET | EPOLLRDHUP;
as->on_tcp_write.app_ctx = ctx;
as->on_tcp_write.free_app_ctx = free_naive;
as->on_tcp_write.cb = on_tcp_write;
as->on_tcp_write.err_cb = on_err;
ctx->ref_count++;
as->on_udp_write.name = "udp-write";
as->on_udp_write.flags = EPOLLOUT | EPOLLET;
as->on_udp_write.app_ctx = ctx;
as->on_udp_write.free_app_ctx = free_naive;
as->on_udp_write.cb = on_udp_write;
as->on_udp_write.err_cb = on_err;
ctx->ref_count++;
*/
return;
init_err:
fprintf(stderr, "Failed to init algo naive\n");
exit(EXIT_FAILURE);
}