Index: trunk/ntripserver/ntripserver.c
===================================================================
--- trunk/ntripserver/ntripserver.c	(revision 2276)
+++ trunk/ntripserver/ntripserver.c	(revision 8784)
@@ -1,7 +1,8 @@
 /*
- * $Id: ntripserver.c,v 1.50 2010/01/21 09:00:49 stoecker Exp $
+ * $Id$
  *
- * Copyright (c) 2003...2007
+ * Copyright (c) 2003...2019
  * German Federal Agency for Cartography and Geodesy (BKG)
+ * Dirk Stöcker (Alberding GmbH)
  *
  * Developed for Networked Transport of RTCM via Internet Protocol (NTRIP)
@@ -16,7 +17,7 @@
  *
  * For latest information and updates, access:
- * http://igs.bkg.bund.de/index_ntrip_down.htm
+ * https://igs.bkg.bund.de/ntrip/index
  *
- * BKG, Frankfurt, Germany, February 2007
+ * BKG, Frankfurt, Germany, August 2019
  * E-mail: euref-ip@bkg.bund.de
  *
@@ -31,12 +32,12 @@
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-/* CVS revision and version */
-static char revisionstr[] = "$Revision: 1.50 $";
-static char datestr[]     = "$Date: 2010/01/21 09:00:49 $";
+/* SVN revision and version */
+static char revisionstr[] = "$Revision$";
+static char datestr[]     = "$Date$";
 
 #include <ctype.h>
@@ -241,19 +242,14 @@
 
   {
-  char *a;
-  int i = 0;
-  for(a = revisionstr+11; *a && *a != ' '; ++a)
-    revisionstr[i++] = *a;
-  revisionstr[i] = 0;
-  datestr[0] = datestr[7];
-  datestr[1] = datestr[8];
-  datestr[2] = datestr[9];
-  datestr[3] = datestr[10];
-  datestr[5] = datestr[12];
-  datestr[6] = datestr[13];
-  datestr[8] = datestr[15];
-  datestr[9] = datestr[16];
-  datestr[4] = datestr[7] = '-';
-  datestr[10] = 0;
+    char *a;
+    int i = 2;
+    strcpy(revisionstr, "1.");
+    for(a = revisionstr+11; *a && *a != ' '; ++a)
+      revisionstr[i++] = *a;
+    revisionstr[i] = 0;
+    i = 0;
+    for(a = datestr+7; *a && *a != ' '; ++a)
+      datestr[i++] = *a;
+    datestr[i] = 0;
   }
 
@@ -1372,4 +1368,5 @@
   char     szSendBuffer[BUFSZ] = "";
   int      nBufferBytes = 0;
+  int      remainChunk = 0;
 
    /* RTSP / RTP Mode */
@@ -1590,11 +1587,7 @@
     else if((nBufferBytes)  && (outmode == HTTP))
     {
-      int i, nChunkBytes, j = 1;
-      nChunkBytes = snprintf(szSendBuffer, sizeof(szSendBuffer),"%x\r\n",
-      nBufferBytes);
-      send(sock, szSendBuffer, nChunkBytes, MSG_DONTWAIT);
-      if((i = send(sock, buffer, (size_t)nBufferBytes, MSG_DONTWAIT))
-      != nBufferBytes)
-      {
+      if(remainChunk)
+      {
+        int i = send(sock, buffer, (size_t)remainChunk, MSG_DONTWAIT);
         if(i < 0)
         {
@@ -1607,11 +1600,35 @@
         else if(i)
         {
-          while(j>0)
-          {
-            j = send(sock, buffer, (size_t)BUFSZ, MSG_DONTWAIT);
-          }
+          memmove(buffer, buffer+i, (size_t)(nBufferBytes-i));
+          nBufferBytes -= i;
+          remainChunk -= i;
         }
       }
       else
+      {
+        int i, nChunkBytes;
+        nChunkBytes = snprintf(szSendBuffer, sizeof(szSendBuffer),"%x\r\n",
+        nBufferBytes);
+        send(sock, szSendBuffer, nChunkBytes, 0);
+        if((i = send(sock, buffer, (size_t)nBufferBytes, MSG_DONTWAIT))
+        != nBufferBytes)
+        {
+          if(i < 0)
+          {
+            if(errno != EAGAIN)
+            {
+              perror("WARNING: could not send data to Destination caster");
+              return;
+            }
+          }
+          else if(i)
+          {
+            memmove(buffer, buffer+i, (size_t)(nBufferBytes-i));
+            nBufferBytes -= i;
+            remainChunk = nBufferBytes;
+          }
+        }
+      }
+      if(!remainChunk)
       {
         send(sock, "\r\n", strlen("\r\n"), MSG_DONTWAIT);
