Working dup2 algo
This commit is contained in:
parent
260e1810ba
commit
79929eb5c8
3 changed files with 27 additions and 6 deletions
|
@ -22,8 +22,11 @@ int algo_dup2_on_stream(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo
|
||||||
|
|
||||||
// Check that we didn't already received the packet
|
// Check that we didn't already received the packet
|
||||||
struct dup2_ctx* dup2c = app_ctx->misc;
|
struct dup2_ctx* dup2c = app_ctx->misc;
|
||||||
if (ring_ge(dup2c->recv_id, bp->ip.ap.str.id))
|
if (ring_ge(dup2c->recv_id, bp->ip.ap.str.id)) {
|
||||||
|
mv_buffer_rtof(app_ctx, fdinfo);
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
dup2c->recv_id = bp->ip.ap.str.id;
|
dup2c->recv_id = bp->ip.ap.str.id;
|
||||||
|
|
||||||
// 1. Find destination
|
// 1. Find destination
|
||||||
|
@ -54,17 +57,18 @@ int algo_dup2_on_datagram(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdin
|
||||||
// 1. A whole packet has been read, we will find someone to write it
|
// 1. A whole packet has been read, we will find someone to write it
|
||||||
to_fdinfo = evt_core_get_from_url (ctx, url[i]);
|
to_fdinfo = evt_core_get_from_url (ctx, url[i]);
|
||||||
if (to_fdinfo == NULL) {
|
if (to_fdinfo == NULL) {
|
||||||
fprintf(stderr, "No fd for URL %s in udp-read. Dropping packet :( \n", url[i]);
|
fprintf(stderr, "No fd for URL %s in udp-read.\n", url[i]);
|
||||||
mv_buffer_wtof (app_ctx, fdinfo);
|
continue;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. We move the buffer and notify the target
|
// 2. We move the buffer and notify the target
|
||||||
if (i == 0) dup_buffer_tow (app_ctx, bp, to_fdinfo);
|
dup_buffer_tow (app_ctx, bp, to_fdinfo);
|
||||||
else mv_buffer_rtow (app_ctx, fdinfo, to_fdinfo);
|
|
||||||
main_on_tcp_write(ctx, to_fdinfo);
|
main_on_tcp_write(ctx, to_fdinfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 3. Release the buffer
|
||||||
|
mv_buffer_rtof (app_ctx, fdinfo);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -105,6 +105,22 @@ void mv_buffer_rtow(struct algo_ctx* app_ctx, struct evt_core_fdinfo* from, stru
|
||||||
g_queue_push_tail(q, bp);
|
g_queue_push_tail(q, bp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void mv_buffer_rtof(struct algo_ctx* app_ctx, struct evt_core_fdinfo* from) {
|
||||||
|
struct buffer_packet* bp;
|
||||||
|
|
||||||
|
// 1. We get the packet buffer
|
||||||
|
bp = g_hash_table_lookup (app_ctx->used_buffer, &from->fd);
|
||||||
|
if (bp == NULL) {
|
||||||
|
fprintf(stderr, "Unable to find a buffer for fd=%d url=%s", from->fd, from->url);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
bp->mode = BP_READING;
|
||||||
|
bp->aread = 0;
|
||||||
|
g_queue_push_tail (app_ctx->free_buffer, bp);
|
||||||
|
g_hash_table_remove(app_ctx->used_buffer, &(from->fd));
|
||||||
|
}
|
||||||
|
|
||||||
void mv_buffer_wtof(struct algo_ctx* app_ctx, struct evt_core_fdinfo* fdinfo) {
|
void mv_buffer_wtof(struct algo_ctx* app_ctx, struct evt_core_fdinfo* fdinfo) {
|
||||||
struct buffer_packet* bp = g_hash_table_lookup (app_ctx->used_buffer, &(fdinfo->fd));
|
struct buffer_packet* bp = g_hash_table_lookup (app_ctx->used_buffer, &(fdinfo->fd));
|
||||||
if (bp == NULL) {
|
if (bp == NULL) {
|
||||||
|
|
|
@ -46,6 +46,7 @@ struct algo_ctx {
|
||||||
};
|
};
|
||||||
|
|
||||||
void mv_buffer_rtow(struct algo_ctx* app_ctx, struct evt_core_fdinfo* from, struct evt_core_fdinfo* to);
|
void mv_buffer_rtow(struct algo_ctx* app_ctx, struct evt_core_fdinfo* from, struct evt_core_fdinfo* to);
|
||||||
|
void mv_buffer_rtof(struct algo_ctx* app_ctx, struct evt_core_fdinfo* from);
|
||||||
void mv_buffer_wtof(struct algo_ctx* app_ctx, struct evt_core_fdinfo* from);
|
void mv_buffer_wtof(struct algo_ctx* app_ctx, struct evt_core_fdinfo* from);
|
||||||
void mv_buffer_rtoa(struct algo_ctx* app_ctx, struct evt_core_fdinfo* from, void* to);
|
void mv_buffer_rtoa(struct algo_ctx* app_ctx, struct evt_core_fdinfo* from, void* to);
|
||||||
void mv_buffer_atow(struct algo_ctx* app_ctx, void* from, struct evt_core_fdinfo* to);
|
void mv_buffer_atow(struct algo_ctx* app_ctx, void* from, struct evt_core_fdinfo* to);
|
||||||
|
|
Loading…
Reference in a new issue