Fix simple algorithms
This commit is contained in:
parent
77b6027feb
commit
778181a153
5 changed files with 10 additions and 10 deletions
|
@ -22,15 +22,15 @@ 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.content.clear.id)) {
|
||||||
mv_buffer_rtof(app_ctx, fdinfo);
|
mv_buffer_rtof(app_ctx, fdinfo);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
dup2c->recv_id = bp->ip.ap.str.id;
|
dup2c->recv_id = bp->ip.ap.content.clear.id;
|
||||||
|
|
||||||
// 1. Find destination
|
// 1. Find destination
|
||||||
sprintf(url, "udp:write:127.0.0.1:%d", bp->ip.ap.str.port);
|
sprintf(url, "udp:write:127.0.0.1:%d", bp->ip.ap.content.clear.port);
|
||||||
to_fdinfo = evt_core_get_from_url (ctx, url);
|
to_fdinfo = evt_core_get_from_url (ctx, url);
|
||||||
if (to_fdinfo == NULL) {
|
if (to_fdinfo == NULL) {
|
||||||
fprintf(stderr, "No fd for URL %s in tcp-read. Dropping packet :( \n", url);
|
fprintf(stderr, "No fd for URL %s in tcp-read. Dropping packet :( \n", url);
|
||||||
|
@ -49,7 +49,7 @@ int algo_dup2_on_datagram(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdin
|
||||||
struct algo_ctx* app_ctx = fdinfo->cat->app_ctx;
|
struct algo_ctx* app_ctx = fdinfo->cat->app_ctx;
|
||||||
|
|
||||||
struct dup2_ctx* dup2c = app_ctx->misc;
|
struct dup2_ctx* dup2c = app_ctx->misc;
|
||||||
bp->ip.ap.str.id = dup2c->emit_id;
|
bp->ip.ap.content.clear.id = dup2c->emit_id;
|
||||||
dup2c->emit_id = dup2c->emit_id + 1;
|
dup2c->emit_id = dup2c->emit_id + 1;
|
||||||
|
|
||||||
struct evt_core_cat* cat = evt_core_get_from_cat (ctx, "tcp-write");
|
struct evt_core_cat* cat = evt_core_get_from_cat (ctx, "tcp-write");
|
||||||
|
|
|
@ -11,7 +11,7 @@ int algo_naive_on_stream(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinf
|
||||||
struct algo_ctx* app_ctx = fdinfo->cat->app_ctx;
|
struct algo_ctx* app_ctx = fdinfo->cat->app_ctx;
|
||||||
|
|
||||||
// 1. Find destination
|
// 1. Find destination
|
||||||
sprintf(url, "udp:write:127.0.0.1:%d", bp->ip.ap.str.port);
|
sprintf(url, "udp:write:127.0.0.1:%d", bp->ip.ap.content.clear.port);
|
||||||
to_fdinfo = evt_core_get_from_url (ctx, url);
|
to_fdinfo = evt_core_get_from_url (ctx, url);
|
||||||
if (to_fdinfo == NULL) {
|
if (to_fdinfo == NULL) {
|
||||||
fprintf(stderr, "No fd for URL %s in tcp-read. Dropping packet :( \n", url);
|
fprintf(stderr, "No fd for URL %s in tcp-read. Dropping packet :( \n", url);
|
||||||
|
|
|
@ -235,12 +235,12 @@ void notify_read(struct evt_core_ctx* ctx, struct algo_ctx* app_ctx) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int append_buffer(union abstract_packet* dest, int pos, union abstract_packet* src) {
|
int append_buffer(struct abstract_packet* dest, int pos, struct abstract_packet* src) {
|
||||||
char* target = &(dest->raw);
|
char* target = &(dest->raw);
|
||||||
while (pos-- > 0) {
|
while (pos-- > 0) {
|
||||||
target += dest->str.size;
|
target += dest->headers.size;
|
||||||
}
|
}
|
||||||
memcpy(target, src, src->str.size);
|
memcpy(target, src, src->headers.size);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ void mv_buffer_atow(struct algo_ctx* app_ctx, void* from, struct evt_core_fdinfo
|
||||||
void mv_buffer_atof(struct algo_ctx* app_ctx, void* from);
|
void mv_buffer_atof(struct algo_ctx* app_ctx, void* from);
|
||||||
void dup_buffer_tow(struct algo_ctx* app_ctx, struct buffer_packet* bp, struct evt_core_fdinfo* to);
|
void dup_buffer_tow(struct algo_ctx* app_ctx, struct buffer_packet* bp, struct evt_core_fdinfo* to);
|
||||||
|
|
||||||
int append_buffer(union abstract_packet* dest, int pos, union abstract_packet* src);
|
int append_buffer(struct abstract_packet* dest, int pos, struct abstract_packet* src);
|
||||||
|
|
||||||
struct buffer_packet* get_write_buffer(struct algo_ctx *app_ctx, struct evt_core_fdinfo *fdinfo);
|
struct buffer_packet* get_write_buffer(struct algo_ctx *app_ctx, struct evt_core_fdinfo *fdinfo);
|
||||||
struct buffer_packet* get_read_buffer(struct algo_ctx *app_ctx, struct evt_core_fdinfo *fdinfo);
|
struct buffer_packet* get_read_buffer(struct algo_ctx *app_ctx, struct evt_core_fdinfo *fdinfo);
|
||||||
|
|
|
@ -71,7 +71,7 @@ int main_on_udp_read(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
|
||||||
if ((bp = get_read_buffer(app_ctx, fdinfo)) == NULL) return 1;
|
if ((bp = get_read_buffer(app_ctx, fdinfo)) == NULL) return 1;
|
||||||
|
|
||||||
// 2. Read packet from socket
|
// 2. Read packet from socket
|
||||||
bp->ip.ap.str.port = url_get_port_int (fdinfo->url);
|
bp->ip.ap.content.clear.port = url_get_port_int (fdinfo->url);
|
||||||
read_res = read_packet_from_udp (fdinfo->fd, bp, fdinfo->other);
|
read_res = read_packet_from_udp (fdinfo->fd, bp, fdinfo->other);
|
||||||
if (read_res == FDS_ERR) goto co_error;
|
if (read_res == FDS_ERR) goto co_error;
|
||||||
if (read_res == FDS_AGAIN) return 1;
|
if (read_res == FDS_AGAIN) return 1;
|
||||||
|
|
Loading…
Reference in a new issue