Fix packet handling bug
This commit is contained in:
parent
b985e0041a
commit
cf027261c8
2 changed files with 21 additions and 11 deletions
|
@ -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;
|
||||
union abstract_packet* ap = (union abstract_packet*) &bp->ip;
|
||||
|
||||
// 1. Find destination
|
||||
if (ctx->verbose > 1) fprintf(stderr, " [algo_naive] 1/2 Find destination\n");
|
||||
sprintf(url, "udp:write:127.0.0.1:%d", ap->fmt.content.udp_encapsulated.port);
|
||||
to_fdinfo = evt_core_get_from_url (ctx, url);
|
||||
if (to_fdinfo == NULL) {
|
||||
|
@ -20,7 +20,7 @@ int algo_naive_on_stream(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinf
|
|||
return 1;
|
||||
}
|
||||
|
||||
// 2. Move buffer
|
||||
if (ctx->verbose > 1) fprintf(stderr, " [algo_naive] 2/2 Move buffer\n");
|
||||
mv_buffer_rtow (&app_ctx->br, fdinfo, to_fdinfo);
|
||||
main_on_udp_write(ctx, to_fdinfo);
|
||||
|
||||
|
|
26
src/packet.c
26
src/packet.c
|
@ -7,27 +7,34 @@ union abstract_packet* ap_next(union abstract_packet* ap) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
union abstract_packet* buffer_last_ptr(struct buffer_packet* bp) {
|
||||
union abstract_packet* buffer_last_ap(struct buffer_packet* bp) {
|
||||
union abstract_packet* ap = (union abstract_packet*) &bp->ip, *apn = NULL;
|
||||
while ((apn = ap_next(ap)) != NULL) ap = apn;
|
||||
|
||||
return ap;
|
||||
}
|
||||
|
||||
union abstract_packet* buffer_free_ptr(struct buffer_packet* bp) {
|
||||
union abstract_packet* ap = buffer_last_ptr (bp);
|
||||
union abstract_packet* buffer_free_ap(struct buffer_packet* bp) {
|
||||
union abstract_packet* ap = buffer_last_ap (bp);
|
||||
ap = (union abstract_packet*)(&ap->raw + ap->fmt.headers.size);
|
||||
|
||||
return ap;
|
||||
}
|
||||
|
||||
size_t buffer_count_ap(struct buffer_packet* bp) {
|
||||
size_t s = 1;
|
||||
union abstract_packet* ap = (union abstract_packet*) &bp->ip;
|
||||
while ((ap = ap_next(ap)) != NULL) s++;
|
||||
return s;
|
||||
}
|
||||
|
||||
size_t get_full_size(struct buffer_packet* bp) {
|
||||
return &(buffer_free_ptr (bp))->raw - &bp->ip[0];
|
||||
return &(buffer_free_ap (bp))->raw - &bp->ip[0];
|
||||
}
|
||||
|
||||
void buffer_append_ap(struct buffer_packet* bp, union abstract_packet* ap) {
|
||||
buffer_last_ptr(bp)->fmt.headers.flags |= FLAG_READ_NEXT;
|
||||
memcpy(buffer_last_ptr(bp), ap, ap->fmt.headers.size);
|
||||
buffer_last_ap(bp)->fmt.headers.flags |= FLAG_READ_NEXT;
|
||||
memcpy(buffer_last_ap(bp), ap, ap->fmt.headers.size);
|
||||
}
|
||||
|
||||
enum FD_STATE read_packet_from_tcp(struct evt_core_fdinfo* fdinfo, struct buffer_packet* bp) {
|
||||
|
@ -53,7 +60,10 @@ enum FD_STATE read_packet_from_tcp(struct evt_core_fdinfo* fdinfo, struct buffer
|
|||
}
|
||||
|
||||
bp->ap_count++;
|
||||
if (bp->ap_count != get_full_size (bp)) return FDS_AGAIN;
|
||||
if (bp->ap_count != buffer_count_ap (bp)) {
|
||||
printf(" Expected %ld packets in buffer, received %d\n", get_full_size(bp), bp->ap_count);
|
||||
return FDS_AGAIN;
|
||||
}
|
||||
|
||||
bp->mode = BP_WRITING;
|
||||
bp->awrite = 0;
|
||||
|
@ -83,7 +93,7 @@ enum FD_STATE write_packet_to_tcp(struct evt_core_fdinfo* fdinfo, struct buffer_
|
|||
enum FD_STATE write_packet_to_udp(struct evt_core_fdinfo* fdinfo, struct buffer_packet* bp, struct udp_target* udp_t) {
|
||||
ssize_t nwrite;
|
||||
union abstract_packet* ap = (union abstract_packet*) (&bp->ip + bp->awrite);
|
||||
union abstract_packet* end = buffer_free_ptr (bp);
|
||||
union abstract_packet* end = buffer_free_ap(bp);
|
||||
if (bp->mode != BP_WRITING) return FDS_ERR;
|
||||
|
||||
while (ap != end) {
|
||||
|
|
Loading…
Reference in a new issue