Don't fail when we free + memset to reset buffer

This commit is contained in:
Quentin 2019-05-24 13:51:56 +02:00
parent fd241b08f0
commit bf37e61e50
2 changed files with 4 additions and 13 deletions

View file

@ -120,12 +120,9 @@ void mv_buffer_rtof(struct algo_ctx* app_ctx, struct evt_core_fdinfo* from) {
bp = g_hash_table_lookup (app_ctx->used_buffer, &from->fd); bp = g_hash_table_lookup (app_ctx->used_buffer, &from->fd);
if (bp == NULL) { if (bp == NULL) {
fprintf(stderr, "Unable to find a buffer for fd=%d url=%s", from->fd, from->url); fprintf(stderr, "Unable to find a buffer for fd=%d url=%s", from->fd, from->url);
exit(EXIT_FAILURE);
} }
bp->mode = BP_READING; memset(bp, 0, sizeof(struct buffer_packet));
bp->aread = 0;
bp->ap_count = 0;
g_queue_push_tail (app_ctx->free_buffer, bp); g_queue_push_tail (app_ctx->free_buffer, bp);
g_hash_table_remove(app_ctx->used_buffer, &(from->fd)); g_hash_table_remove(app_ctx->used_buffer, &(from->fd));
} }
@ -134,11 +131,8 @@ 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) {
fprintf(stderr, "Unable to find a buffer for fd=%d url=%s", fdinfo->fd, fdinfo->url); fprintf(stderr, "Unable to find a buffer for fd=%d url=%s", fdinfo->fd, fdinfo->url);
exit(EXIT_FAILURE);
} }
bp->mode = BP_READING; memset(bp, 0, sizeof(struct buffer_packet));
bp->aread = 0;
bp->ap_count = 0;
g_queue_push_tail (app_ctx->free_buffer, bp); g_queue_push_tail (app_ctx->free_buffer, bp);
g_hash_table_remove(app_ctx->used_buffer, &(fdinfo->fd)); g_hash_table_remove(app_ctx->used_buffer, &(fdinfo->fd));
} }
@ -148,7 +142,6 @@ void mv_buffer_rtoa(struct algo_ctx* app_ctx, struct evt_core_fdinfo* from, void
bp = g_hash_table_lookup (app_ctx->used_buffer, &from->fd); bp = g_hash_table_lookup (app_ctx->used_buffer, &from->fd);
if (bp == NULL) { if (bp == NULL) {
fprintf(stderr, "Unable to find a buffer for fd=%d url=%s\n", from->fd, from->url); fprintf(stderr, "Unable to find a buffer for fd=%d url=%s\n", from->fd, from->url);
exit(EXIT_FAILURE);
} }
g_hash_table_remove(app_ctx->used_buffer, &from->fd); g_hash_table_remove(app_ctx->used_buffer, &from->fd);
if (g_hash_table_contains(app_ctx->application_waiting, to)) { if (g_hash_table_contains(app_ctx->application_waiting, to)) {
@ -193,9 +186,7 @@ void mv_buffer_atof(struct algo_ctx* app_ctx, void* from) {
} }
// 2. Reset it // 2. Reset it
bp->mode = BP_READING; memset(bp, 0, sizeof(struct buffer_packet));
bp->aread = 0;
bp->ap_count = 0;
// 3. We move it // 3. We move it
g_hash_table_remove (app_ctx->application_waiting, from); g_hash_table_remove (app_ctx->application_waiting, from);

View file

@ -143,7 +143,7 @@ void dump_abstract_packet(union abstract_packet* ap) {
printf(" size=%d, cmd=%d\n", ap->fmt.headers.size, ap->fmt.headers.cmd); printf(" size=%d, cmd=%d\n", ap->fmt.headers.size, ap->fmt.headers.cmd);
switch (ap->fmt.headers.cmd) { switch (ap->fmt.headers.cmd) {
case CMD_HEALTH: case CMD_HEALTH:
printf(" <Health>id=%d, deltat=%d, prevlink=%d, min_blocked_pkt=%d, bitfield=%08x</Health>\n", printf(" <Health>id=%d, deltat=%d, prevlink=%d, min_blocked_pkt=%d, bitfield=%02x</Health>\n",
ap->fmt.content.health.id, ap->fmt.content.health.id,
ap->fmt.content.health.deltat, ap->fmt.content.health.deltat,
ap->fmt.content.health.prevlink, ap->fmt.content.health.prevlink,