Annotation of sbbs/src/comio/comio.c, revision 1.1

1.1     ! root        1: /* comio.c */
        !             2: 
        !             3: /* Synchronet Serial Communications I/O Library Common Functions */
        !             4: 
        !             5: /* $Id: comio.c,v 1.1 2007/04/21 01:36:35 rswindell Exp $ */
        !             6: 
        !             7: /****************************************************************************
        !             8:  * @format.tab-size 4          (Plain Text/Source Code File Header)                    *
        !             9:  * @format.use-tabs true       (see http://www.synchro.net/ptsc_hdr.html)              *
        !            10:  *                                                                                                                                                     *
        !            11:  * Copyright 2007 Rob Swindell - http://www.synchro.net/copyright.html         *
        !            12:  *                                                                                                                                                     *
        !            13:  * This library is free software; you can redistribute it and/or                       *
        !            14:  * modify it under the terms of the GNU Lesser General Public License          *
        !            15:  * as published by the Free Software Foundation; either version 2                      *
        !            16:  * of the License, or (at your option) any later version.                                      *
        !            17:  * See the GNU Lesser General Public License for more details: lgpl.txt or     *
        !            18:  * http://www.fsf.org/copyleft/lesser.html                                                                     *
        !            19:  *                                                                                                                                                     *
        !            20:  * Anonymous FTP access to the most recent released source is available at     *
        !            21:  * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net     *
        !            22:  *                                                                                                                                                     *
        !            23:  * Anonymous CVS access to the development source and modification history     *
        !            24:  * is available at cvs.synchro.net:/cvsroot/sbbs, example:                                     *
        !            25:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs login                       *
        !            26:  *     (just hit return, no password is necessary)                                                     *
        !            27:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src                *
        !            28:  *                                                                                                                                                     *
        !            29:  * For Synchronet coding style and modification guidelines, see                                *
        !            30:  * http://www.synchro.net/source.html                                                                          *
        !            31:  *                                                                                                                                                     *
        !            32:  * You are encouraged to submit any modifications (preferably in Unix diff     *
        !            33:  * format) via e-mail to [email protected]                                                                      *
        !            34:  *                                                                                                                                                     *
        !            35:  * Note: If this box doesn't appear square, then you need to fix your tabs.    *
        !            36:  ****************************************************************************/
        !            37: 
        !            38: #include "comio.h"
        !            39: #include "genwrap.h"   /* msclock */
        !            40: 
        !            41: size_t comReadBuf(COM_HANDLE handle, char* buf, size_t buflen, const char* terminators, int timeout)
        !            42: {
        !            43:        BYTE            ch;
        !            44:        size_t          len=0;
        !            45:        msclock_t       start=msclock();
        !            46: 
        !            47:        while(len < buflen) {
        !            48:                if(!comReadByte(handle, &ch)) {
        !            49:                        if(msclock()-start >= timeout)
        !            50:                                break;
        !            51:                        YIELD();
        !            52:                        continue;
        !            53:                }
        !            54:                if(len && terminators!=NULL && strchr(terminators, ch)!=NULL)
        !            55:                        break;
        !            56:                buf[len++]=ch;
        !            57:        }
        !            58: 
        !            59:        return len;
        !            60: }
        !            61: 
        !            62: size_t comReadLine(COM_HANDLE handle, char* buf, size_t buflen, int timeout)
        !            63: {
        !            64:        size_t  len;
        !            65: 
        !            66:        len=comReadBuf(handle, buf, buflen-1, "\n", timeout);
        !            67: 
        !            68:        buf[len]=0;
        !            69: 
        !            70:        return len;
        !            71: }
        !            72: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.