[MPlayer-dev-eng] [PATCHv2 3/8] stream ftp: readline: Always try to read complete lines

Alexander Strasser eclipse7 at gmx.net
Sat Nov 17 01:01:58 CET 2012


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.

Signed-off-by: Alexander Strasser <eclipse7 at gmx.net>
---
 stream/stream_ftp.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/stream/stream_ftp.c b/stream/stream_ftp.c
index 4dd48b7..3f666a0 100644
--- a/stream/stream_ftp.c
+++ b/stream/stream_ftp.c
@@ -105,6 +105,11 @@ static int fd_can_read(int fd,int timeout) {
 /*
  * 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,20 @@ static int readline(char *buf,int max,struct stream_priv_s *ctl)
 	}
       }
       if (max == 1) {
-	*buf = '\0';
-	break;
+        int found_eol = 0;
+
+        while (ctl->cavail > 0) { // skip remaining response line
+          found_eol = *ctl->cget == '\n';
+          --ctl->cavail; ++ctl->cget;
+
+          if (found_eol) {
+            break;
+          }
+        }
+
+        if (found_eol) {
+	  break;
+        }
       }
       if (ctl->cput == ctl->cget) {
 	ctl->cput = ctl->cget = ctl->buf;
-- 
1.7.10.2.552.gaa3bb87


More information about the MPlayer-dev-eng mailing list