From 0376e5419643778f36b6f8226e780db6b9f5e0e0 Mon Sep 17 00:00:00 2001 From: z3APA3A <3APA3A@3proxy.ru> Date: Fri, 27 Apr 2018 19:23:20 +0300 Subject: [PATCH] simlify sockgetline --- src/sockgetchar.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/sockgetchar.c b/src/sockgetchar.c index be95022..da2105c 100644 --- a/src/sockgetchar.c +++ b/src/sockgetchar.c @@ -156,15 +156,11 @@ int sockgetcharsrv(struct clientparam * param, int timeosec, int timeousec){ int sockgetlinebuf(struct clientparam * param, DIRECTION which, unsigned char * buf, int bufsize, int delim, int to){ int c; int i=0; - if(bufsize < 1) return 0; - c = (which)?sockgetcharsrv(param, to, 0):sockgetcharcli(param, to, 0); - if (c == EOF) { - return 0; - } - do { + + while(i < bufsize && (c = (which)?sockgetcharsrv(param, to, 0):sockgetcharcli(param, to, 0)) != EOF){ buf[i++] = c; if(delim != EOF && c == delim) break; - }while(i < bufsize && (c = (which)?sockgetcharsrv(param, to, 0):sockgetcharcli(param, to, 0)) != EOF); + } return i; }