[MPlayer-cvslog] r35429 - trunk/stream/stream_ftp.c

al subversion at mplayerhq.hu
Tue Nov 20 23:18:25 CET 2012


Author: al
Date: Tue Nov 20 23:18:25 2012
New Revision: 35429

Log:
stream ftp: readline: Always try to read complete lines

If there is not enough space in the provided line buffer just
skip the remaining bytes until reaching EOL.

Usually we are only interested in the first 5 characters and
for everything else the (on-stack) response buffer should still
be big enough.

Modified:
   trunk/stream/stream_ftp.c

Modified: trunk/stream/stream_ftp.c
==============================================================================
--- trunk/stream/stream_ftp.c	Tue Nov 20 23:16:29 2012	(r35428)
+++ trunk/stream/stream_ftp.c	Tue Nov 20 23:18:25 2012	(r35429)
@@ -105,6 +105,11 @@ static int fd_can_read(int fd,int timeou
 /*
  * read a line of text
  *
+ * If the line is too long to fit in the buffer, provided via parameters
+ * buf and max, the remaining characters are skipped. So the next call to
+ * this function is synchronized to the start of the following response
+ * line.
+ *
  * The parameter buf will always be initialized as long as max is bigger
  * then 1. If nothing is read it will contain an empty string.
  *
@@ -144,8 +149,18 @@ static int readline(char *buf,int max,st
 	}
       }
       if (max == 1) {
-	*buf = '\0';
-	break;
+        char *q = memchr(ctl->cget, '\n', ctl->cavail);
+
+        if (q) { // found EOL: update state and return
+          ++q;
+          ctl->cavail -= q - ctl->cget;
+          ctl->cget = q;
+
+          break;
+        }
+
+        // receive more data to find end of current line
+        ctl->cget = ctl->cput;
       }
       if (ctl->cput == ctl->cget) {
 	ctl->cput = ctl->cget = ctl->buf;


More information about the MPlayer-cvslog mailing list