Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions sratunnel/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ static bool out_nmsg_mod_checked = false;
void
out_close(void)
{
out_flush();
// Try to flush for up to 10 seconds
int n = 0;
do {
out_flush();
usleep(10000);
} while (out_buf_len > 0 && n++ < 1000);

if (out_pcap_dumper != NULL) {
pcap_dump_close(out_pcap_dumper);
Expand Down Expand Up @@ -98,7 +103,8 @@ out_flush(void)
&& errno != EINTR) {
axa_error_msg("write(%s): %s",
out_addr, strerror(errno));
stop(EX_IOERR);
// Can't call stop as it recurses....
exit(EX_IOERR);
}
} else {
out_buf_base += wlen;
Expand Down Expand Up @@ -590,10 +596,10 @@ out_ip_pcap_file(const uint8_t *pkt, size_t caplen, size_t len,
return;
}

if (caplen + sizeof(sf_hdr) > sizeof(out_buf) - out_buf_len
if (caplen + sizeof(sf_hdr) + out_buf_len > sizeof(out_buf) / 2
|| out_buf_base != 0) {
out_flush();
if (caplen > sizeof(out_buf) - sizeof(sf_hdr) - out_buf_len) {
if (caplen + sizeof(sf_hdr) + out_buf_len > sizeof(out_buf)) {
out_error("forwarding output stalled; dropping");
return;
}
Expand Down