--- libaitcli/src/aitcli.c 2013/12/03 20:32:45 1.12.2.2 +++ libaitcli/src/aitcli.c 2016/08/18 09:27:37 1.15 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: aitcli.c,v 1.12.2.2 2013/12/03 20:32:45 misho Exp $ +* $Id: aitcli.c,v 1.15 2016/08/18 09:27:37 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 +Copyright 2004 - 2016 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -1304,17 +1304,11 @@ cliReadLine(linebuffer_t * __restrict cli_buffer, int memset(buf, 0, sizeof buf); readLen = read(cli_buffer->line_in, buf, BUFSIZ); - if (readLen == -1) { - LOGERR; - return str; + if (readLen < 1) { + if (readLen) + LOGERR; + return NULL; } - if (!readLen) { - if (cli_buffer->line_buf) - str = e_strdup(cli_buffer->line_buf); - else - cli_SetErr(EPIPE, "Unknown state ..."); - return str; - } recheck: for (code = RETCODE_OK, i = MAX_BINDKEY - 1; i > -1; i--) @@ -1361,7 +1355,7 @@ cliNetLoop(linebuffer_t * __restrict cli_buffer, const int sock, int timeout) { u_char buf[BUFSIZ]; - int pid, stat, pty, r, s, alen, flg, attrlen = 0, ret = 0; + int pid, stat, pty, s, alen, flg, attrlen = 0, ret = 0; fd_set fds; struct timeval tv = { DEFAULT_SOCK_TIMEOUT, 0 }; struct telnetAttrs *a, Attr[10]; @@ -1406,7 +1400,6 @@ cliNetLoop(linebuffer_t * __restrict cli_buffer, const break; } - r = FD_ISSET(sock, &fds) ? sock : pty; s = FD_ISSET(sock, &fds) ? pty : sock; if (FD_ISSET(sock, &fds)) { @@ -1446,8 +1439,9 @@ cliNetLoop(linebuffer_t * __restrict cli_buffer, const if (FD_ISSET(pty, &fds)) { memset(buf, 0, BUFSIZ); - if ((ret = read(pty, buf, BUFSIZ)) == -1) { - LOGERR; + if ((ret = read(pty, buf, BUFSIZ)) < 1) { + if (ret) + LOGERR; break; }