Commit 0b8517e1 authored by Rob Swindell's avatar Rob Swindell 💬
Browse files

comReadBuf() supports an infinite timeout (0)

parent 4c33738e
/* comio.c */
/* Synchronet Serial Communications I/O Library Common Functions */
/* $Id: comio.c,v 1.4 2020/06/26 19:33:08 deuce Exp $ */
/****************************************************************************
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
......@@ -17,21 +13,9 @@
* See the GNU Lesser General Public License for more details: lgpl.txt or *
* http://www.fsf.org/copyleft/lesser.html *
* *
* Anonymous FTP access to the most recent released source is available at *
* ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
* *
* Anonymous CVS access to the development source and modification history *
* is available at cvs.synchro.net:/cvsroot/sbbs, example: *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login *
* (just hit return, no password is necessary) *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src *
* *
* For Synchronet coding style and modification guidelines, see *
* http://www.synchro.net/source.html *
* *
* You are encouraged to submit any modifications (preferably in Unix diff *
* format) via e-mail to mods@synchro.net *
* *
* Note: If this box doesn't appear square, then you need to fix your tabs. *
****************************************************************************/
......@@ -46,7 +30,7 @@ size_t comReadBuf(COM_HANDLE handle, char* buf, size_t buflen, const char* termi
while(len < buflen) {
if(!comReadByte(handle, &ch)) {
if(msclock()-start >= timeout)
if(timeout > 0 && msclock()-start >= timeout)
break;
YIELD();
continue;
......
  • This seems very dangerous since it will continue block across a disconnection/new connection. Is that the intended use case?

  • Yeah, I mentioned the risks to the requester (Nelgin) and he tested and was okay with the change: upon disconnect, the modem is always sending something to the application (SexPOTS), so it always aborts this loop. Still, I made the default timeout non-zero (60 seconds).

  • While that works fine for his modem usage, I don't understand why he needs more than the 24 days allowed by the timeout value.

    Edited by Deucе
  • I'm also not sure why his ask is important enough to potentially break existing consumers and/or add a special-case value.

  • I think passing INT_MAX for infinite timeout would be much better than zero.

  • I did search and could not locate any caller of this function with a timeout parameter value of 0. Seemed like a safe-enough change but using INT_MAX or INT_MIN is fine too.

Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment