diff -Naur gpsd-3.16_orig/gpsd.c gpsd-3.16_patched_server_v2/gpsd.c --- gpsd-3.16_orig/gpsd.c 2016-01-04 15:22:45.000000000 -0500 +++ gpsd-3.16_patched_server_v2/gpsd.c 2017-06-28 15:05:19.561846185 -0400 @@ -87,12 +87,16 @@ * * DEVICE_RECONNECT sets interval on retries when (re)connecting to * a device. + * + * READ_TIMEOUT sets the maximum time we will wait for the balance of + * an incomplete request to arrive before giving up. */ #define COMMAND_TIMEOUT 60*15 #define NOREAD_TIMEOUT 60*3 #define RELEASE_TIMEOUT 60 #define DEVICE_REAWAKE 0.01 #define DEVICE_RECONNECT 2 +#define READ_TIMEOUT 10 #define QLEN 5 @@ -2328,7 +2332,8 @@ lock_subscriber(sub); if (FD_ISSET(sub->fd, &rfds)) { char buf[BUFSIZ]; - int buflen; + int buflen, tmpbuflen; + time_t tmptime; unlock_subscriber(sub); @@ -2339,6 +2344,10 @@ (int)recv(sub->fd, buf, sizeof(buf) - 1, 0)) <= 0) { detach_client(sub); } else { + for (tmptime = time(NULL); (time(NULL) - READ_TIMEOUT) < tmptime && buflen == 1;){ + tmpbuflen = (int)recv(sub->fd, buf+1, sizeof(buf) - 2, 0); + if (tmpbuflen > 0) buflen += tmpbuflen; + } if (buf[buflen - 1] != '\n') buf[buflen++] = '\n'; buf[buflen] = '\0';