return 0;
}
+/** delete the current message in the dtio, and reset counters */
+static void dtio_cur_msg_free(struct dt_io_thread* dtio)
+{
+ free(dtio->cur_msg);
+ dtio->cur_msg = NULL;
+ dtio->cur_msg_len = 0;
+ dtio->cur_msg_done = 0;
+ dtio->cur_msg_len_done = 0;
+}
+
/** del the output file descriptor event for listening */
static void dtio_del_output_event(struct dt_io_thread* dtio)
{
closesocket(dtio->fd);
#endif
dtio->fd = -1;
+
+ /* if there is a (partial) message, discard it
+ * we cannot send (the remainder of) it, and a new
+ * connection needs to start with a control frame. */
+ if(dtio->cur_msg) {
+ dtio_cur_msg_free(dtio);
+ }
}
/** check for pending nonblocking connect errors,
}
/* done with the current message */
- free(dtio->cur_msg);
- dtio->cur_msg = NULL;
- dtio->cur_msg_len = 0;
- dtio->cur_msg_done = 0;
- dtio->cur_msg_len_done = 0;
+ dtio_cur_msg_free(dtio);
}
}
}
verbose(VERB_ALGO, "dnstap io: stop flush completed "
"last frame");
- free(dtio->cur_msg);
- dtio->cur_msg = NULL;
- dtio->cur_msg_len = 0;
- dtio->cur_msg_done = 0;
- dtio->cur_msg_len_done = 0;
+ dtio_cur_msg_free(dtio);
}
/* write stop frame */
if(info->stop_frame_done < info->stop_frame_len) {
_close(dtio->commandpipe[0]);
#endif
dtio->commandpipe[0] = -1;
- free(dtio->cur_msg);
- dtio->cur_msg = NULL;
+ dtio_cur_msg_free(dtio);
ub_event_base_free(dtio->event_base);
}