From f947465fe4e6cefb66f49408696b964fe14f3949 Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Tue, 25 Oct 2016 10:07:04 -0700 Subject: [PATCH] libftdi: Disable Nagle algorithm and buffer sends internally. This significantly improves performance by not waiting for TCP timeout on transmission. --- src/platforms/libftdi/gdb_if.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/platforms/libftdi/gdb_if.c b/src/platforms/libftdi/gdb_if.c index e2981b29..e6c451e7 100644 --- a/src/platforms/libftdi/gdb_if.c +++ b/src/platforms/libftdi/gdb_if.c @@ -27,6 +27,7 @@ #ifndef WIN32 # include # include +# include # include #else # include @@ -57,6 +58,7 @@ int gdb_if_init(void) assert((gdb_if_serv = socket(PF_INET, SOCK_STREAM, 0)) != -1); opt = 1; assert(setsockopt(gdb_if_serv, SOL_SOCKET, SO_REUSEADDR, (void*)&opt, sizeof(opt)) != -1); + assert(setsockopt(gdb_if_serv, IPPROTO_TCP, TCP_NODELAY, (void*)&opt, sizeof(opt)) != -1); assert(bind(gdb_if_serv, (void*)&addr, sizeof(addr)) != -1); assert(listen(gdb_if_serv, 1) != -1); @@ -109,9 +111,13 @@ unsigned char gdb_if_getchar_to(int timeout) void gdb_if_putchar(unsigned char c, int flush) { - (void)flush; - - if (gdb_if_conn > 0) - send(gdb_if_conn, (void*)&c, 1, 0); + static uint8_t buf[2048]; + static int bufsize = 0; + if (gdb_if_conn > 0) { + buf[bufsize++] = c; + if (flush || (bufsize == sizeof(buf))) { + send(gdb_if_conn, buf, bufsize, 0); + bufsize = 0; + } + } } -