From 1cde8634ca2cd8b2cccdbd1b4b1b646e8ada3a34 Mon Sep 17 00:00:00 2001 From: Hoernchen Date: Wed, 9 Jan 2013 23:57:47 +0100 Subject: [PATCH] rtl_tcp: add option to tame the linked list --- src/rtl_tcp.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/rtl_tcp.c b/src/rtl_tcp.c index 13f20fa..9e9eb16 100644 --- a/src/rtl_tcp.c +++ b/src/rtl_tcp.c @@ -80,6 +80,7 @@ static rtlsdr_dev_t *dev = NULL; int global_numq = 0; static struct llist *ll_buffers = 0; +int llbuf_num=500; static int do_exit = 0; @@ -92,6 +93,7 @@ void usage(void) "\t[-g gain (default: 0 for auto)]\n" "\t[-s samplerate in Hz (default: 2048000 Hz)]\n" "\t[-b number of buffers (default: 32, set by library)]\n" + "\t[-n max number of linked list buffers to keep (default: 500)]\n" "\t[-d device index (default: 0)]\n"); exit(1); } @@ -157,6 +159,16 @@ void rtlsdr_callback(unsigned char *buf, uint32_t len, void *ctx) cur = cur->next; num_queued++; } + + if(llbuf_num && llbuf_num == num_queued-2){ + struct llist *curelem; + + free(ll_buffers->data); + curelem = ll_buffers->next; + free(ll_buffers); + ll_buffers = curelem; + } + cur->next = rpt; if (num_queued > global_numq) @@ -397,7 +409,7 @@ int main(int argc, char **argv) struct sigaction sigact, sigign; #endif - while ((opt = getopt(argc, argv, "a:p:f:g:s:b:d:")) != -1) { + while ((opt = getopt(argc, argv, "a:p:f:g:s:b:n:d:")) != -1) { switch (opt) { case 'd': dev_index = atoi(optarg); @@ -420,6 +432,9 @@ int main(int argc, char **argv) case 'b': buf_num = atoi(optarg); break; + case 'n': + llbuf_num = atoi(optarg); + break; default: usage(); break;