Annotation of 43BSDReno/contrib/isode-beta/quipu/dsa_wait.c, revision 1.1

1.1     ! root        1: /* dsa_wait.c - accept and process events listened for */
        !             2: 
        !             3: #ifndef lint
        !             4: static char *rcsid = "$Header: /f/osi/quipu/RCS/dsa_wait.c,v 7.4 90/07/09 14:46:03 mrose Exp $";
        !             5: #endif
        !             6: 
        !             7: /*
        !             8:  * $Header: /f/osi/quipu/RCS/dsa_wait.c,v 7.4 90/07/09 14:46:03 mrose Exp $
        !             9:  *
        !            10:  *
        !            11:  * $Log:       dsa_wait.c,v $
        !            12:  * Revision 7.4  90/07/09  14:46:03  mrose
        !            13:  * sync
        !            14:  * 
        !            15:  * Revision 7.3  90/04/18  08:49:51  mrose
        !            16:  * 6.2
        !            17:  * 
        !            18:  * Revision 7.2  90/03/15  11:19:00  mrose
        !            19:  * quipu-sync
        !            20:  * 
        !            21:  * Revision 7.1  89/12/19  16:20:30  mrose
        !            22:  * sync
        !            23:  * 
        !            24:  * Revision 7.0  89/11/23  22:17:25  mrose
        !            25:  * Release 6.0
        !            26:  * 
        !            27:  */
        !            28: 
        !            29: /*
        !            30:  *                                NOTICE
        !            31:  *
        !            32:  *    Acquisition, use, and distribution of this module and related
        !            33:  *    materials are subject to the restrictions of a license agreement.
        !            34:  *    Consult the Preface in the User's Manual for the full terms of
        !            35:  *    this agreement.
        !            36:  *
        !            37:  */
        !            38: 
        !            39: 
        !            40: #include "rosap.h"
        !            41: #include "tsap.h"
        !            42: #include "quipu/util.h"
        !            43: #include "quipu/connection.h"
        !            44: #include <signal.h>
        !            45: 
        !            46: extern LLog * log_dsap;
        !            47: extern LLog * tsap_log;
        !            48: 
        !            49: extern unsigned watchdog_time;
        !            50: extern unsigned watchdog_delta;
        !            51: extern time_t  time();
        !            52: time_t timenow;
        !            53: 
        !            54: dsa_wait(secs)
        !            55: int      secs;
        !            56: {
        !            57:     int                         vecp = 0;
        !            58:     char                        *vec[4];
        !            59:     fd_set                      iads;
        !            60:     fd_set                      wads;
        !            61:     int                         nads;
        !            62:     struct TSAPdisconnect       td_s;
        !            63:     struct TSAPdisconnect       *td = &td_s;
        !            64:     struct connection          * cn;
        !            65:     struct connection          * next_cn;
        !            66:     char                       ibuffer[BUFSIZ];
        !            67:     char                       *ibp;
        !            68:     char                       wbuffer[BUFSIZ];
        !            69:     char                       *wbp;
        !            70:     SFD                        attempt_restart();
        !            71:     int                                newfd;
        !            72: 
        !            73:     nads = 0;
        !            74:     FD_ZERO(&iads);
        !            75:     FD_ZERO(&wads);
        !            76:     ibp = ibuffer;
        !            77:     wbp = wbuffer;
        !            78: 
        !            79: /*
        !            80:     DLOG(log_dsap, LLOG_DEBUG, ("dsa_wait connections:"));
        !            81:     conn_list_log(connlist);
        !            82: */ 
        !            83: 
        !            84:     for(cn=connlist; cn != NULLCONN; cn=cn->cn_next)
        !            85:     {
        !            86:        if (cn->cn_state == CN_CONNECTING1)
        !            87:        {
        !            88:            if (cn->cn_ad > 0)
        !            89:                    FD_SET(cn->cn_ad, &wads);
        !            90:            else
        !            91:                SLOG (tsap_log, LLOG_EXCEPTIONS, NULLCP,
        !            92:                      ("fd=%d for connection block(1)", cn -> cn_ad));
        !            93:            (void) sprintf(wbp, ", %d.", cn->cn_ad);
        !            94:            wbp += (strlen(wbp) - 1);
        !            95:        }
        !            96:        else
        !            97:        {
        !            98:            if (cn->cn_ad > 0)
        !            99:                    FD_SET(cn->cn_ad, &iads);
        !           100:            else
        !           101:                SLOG (tsap_log, LLOG_EXCEPTIONS, NULLCP,
        !           102:                      ("fd=%d for connection block(2)", cn -> cn_ad));
        !           103:            (void) sprintf(ibp, ", %d.", cn->cn_ad);
        !           104:            ibp += (strlen(ibp) - 1);
        !           105:        }
        !           106: 
        !           107:        if(cn->cn_ad >= nads)
        !           108:            nads = cn->cn_ad + 1;
        !           109:     }
        !           110: 
        !           111:     if(ibp == ibuffer)
        !           112:     {
        !           113:        DLOG (log_dsap, LLOG_DEBUG, ("Listening for new associations"));
        !           114:     }
        !           115:     else
        !           116:     {
        !           117:        LLOG (log_dsap, LLOG_NOTICE, ("Listening on ads: %s", (ibuffer+1)));
        !           118:     }
        !           119: 
        !           120:     if(wbp == wbuffer)
        !           121:     {
        !           122:        DLOG (log_dsap, LLOG_DEBUG, ("Not making new associations"));
        !           123:     }
        !           124:     else
        !           125:     {
        !           126:        LLOG (log_dsap, LLOG_NOTICE, ("Making ads: %s", (wbuffer+1)));
        !           127:     }
        !           128: 
        !           129:     DLOG (log_dsap, LLOG_NOTICE, ("secs: %d; nads: %d; iads 0x%x, wads 0x%x", 
        !           130:        secs, nads, iads.fds_bits[0], wads.fds_bits[0]));
        !           131: 
        !           132:     if (secs != NOTOK) {
        !           133:        /* if secs == NOTOK we want to block, otherwise set watchdog, but
        !           134:           beware of setting watchdog off accidentally !
        !           135:        */
        !           136:        if (secs > (watchdog_time - watchdog_delta))
        !           137:                watch_dog_aux ("TNetAccept (long)",(unsigned)secs + watchdog_delta);
        !           138:        else
        !           139:                watch_dog ("TNetAccept");
        !           140:     }
        !           141: 
        !           142:     if(TNetAcceptAux(&vecp, vec, &newfd, NULLTA, nads, &iads, &wads, NULLFD, secs, td) == NOTOK)
        !           143:     {
        !           144:        watch_dog_reset();
        !           145: 
        !           146:        td_log (td, "TNetAccept");
        !           147: 
        !           148: /*
        !           149:  *     if (td -> td_reason == DR_PROTOCOL || td -> td_reason == DR_NETWORK) 
        !           150:  */
        !           151:                return;
        !           152: /*
        !           153:  *     attempt_restart (NOTOK);
        !           154:  *     exit (0);                       */ /* should not be reached */
        !           155: 
        !           156:     }
        !           157:     watch_dog_reset();
        !           158: 
        !           159:     (void) time (&timenow);
        !           160: 
        !           161:     if (vecp > 0) 
        !           162:        conn_pre_init (newfd,vecp,vec);
        !           163: 
        !           164:     for(cn = connlist; cn != NULLCONN; cn = next_cn)
        !           165:     {
        !           166:        next_cn = cn->cn_next;
        !           167: 
        !           168:        switch(cn->cn_state)
        !           169:        {
        !           170:        case CN_CONNECTING1:
        !           171:            DLOG(log_dsap, LLOG_TRACE, ("Checking %d", cn->cn_ad));
        !           172:            if(FD_ISSET(cn->cn_ad, &wads))
        !           173:            {
        !           174:                DLOG(log_dsap, LLOG_DEBUG, ("Polling %d", cn->cn_ad));
        !           175:                conn_retry(cn);
        !           176:            }
        !           177:        break;
        !           178: 
        !           179:        case CN_CONNECTING2:
        !           180:            DLOG (log_dsap, LLOG_TRACE, ("Checking %d (2)", cn ->cn_ad));
        !           181:            if (FD_ISSET(cn->cn_ad, &iads))
        !           182:            {
        !           183:                DLOG(log_dsap, LLOG_DEBUG, ("Polling %d (2)", cn->cn_ad));
        !           184:                conn_retry(cn);
        !           185:            }
        !           186:        break;
        !           187: 
        !           188:        case CN_OPEN:
        !           189:            if (FD_ISSET (cn->cn_ad, &iads))
        !           190:            {
        !           191:                DLOG (log_dsap,LLOG_DEBUG,( "Activity on association: %d", cn->cn_ad));
        !           192:                conn_dispatch(cn);
        !           193:            } /* if there is work on this connection */
        !           194:        break;
        !           195: 
        !           196:        case CN_CLOSING:
        !           197:            if (FD_ISSET (cn->cn_ad, &iads)) 
        !           198:                (void) conn_release_retry(cn);
        !           199:        break;
        !           200: 
        !           201:        case CN_OPENING:
        !           202:            if (FD_ISSET (cn->cn_ad, &iads))
        !           203:                conn_init(cn);
        !           204:        break;
        !           205: 
        !           206:        case CN_INDICATED:
        !           207:            if (FD_ISSET (cn->cn_ad, &iads))
        !           208:            {
        !           209:                if(cn->cn_start.cs_bind_compare == NULLOPER)
        !           210:                {
        !           211:                    LLOG(log_dsap, LLOG_EXCEPTIONS, ("cn_state = INDICATED but no bind_compare operation"));
        !           212:                }
        !           213:                else
        !           214:                {
        !           215:                    cn->cn_start.cs_bind_compare->on_bind_compare = NULLCONN;
        !           216:                }
        !           217:            }
        !           218:            /* FALL THROUGH */
        !           219:        
        !           220:        default:
        !           221:            if (FD_ISSET (cn->cn_ad, &iads))
        !           222:            {
        !           223:                LLOG (log_dsap,LLOG_EXCEPTIONS,( "Unexpected activity on association %d ... aborting",cn->cn_ad));
        !           224:                net_send_abort(cn);
        !           225:                conn_extract(cn);
        !           226:            } /* if there is work on this connection */
        !           227:        break;
        !           228:        }
        !           229:     } /* for each connection */
        !           230: 
        !           231: } /* dsa_wait */
        !           232: 
        !           233: 
        !           234: static char * watch_dog_where;
        !           235: 
        !           236: static SFD watch_dog_activate ()
        !           237: {
        !           238: static char called = FALSE;
        !           239: 
        !           240:        if (!called) {
        !           241:                called = TRUE;
        !           242:                LLOG (log_dsap, LLOG_FATAL, ("Watchdog activated in %s", watch_dog_where));
        !           243:                attempt_restart (-2);
        !           244:        } else 
        !           245:                LLOG (log_dsap, LLOG_FATAL, ("Repeated lower level blocking in %s", watch_dog_where));
        !           246:                
        !           247:        exit(-1);
        !           248: }
        !           249: 
        !           250: watch_dog (where)
        !           251: char * where;
        !           252: {
        !           253: /*
        !           254:        A simple timer to stop DSAs holding onto associations, due to
        !           255:        a lower level failure.
        !           256: */
        !           257:        watch_dog_where = where;
        !           258:        (void) signal (SIGALRM, watch_dog_activate);
        !           259:        (void) alarm (watchdog_time);
        !           260: }
        !           261: 
        !           262: watch_dog_aux (where,secs)
        !           263: char * where;
        !           264: unsigned secs;
        !           265: {
        !           266:        watch_dog_where = where;
        !           267:        (void) signal (SIGALRM, watch_dog_activate);
        !           268:        (void) alarm (secs);
        !           269: }
        !           270: 
        !           271: watch_dog_reset ()
        !           272: {
        !           273:        (void) signal (SIGALRM, SIG_IGN);
        !           274:        (void) alarm ((unsigned) 0);
        !           275: }
        !           276: 

unix.superglobalmegacorp.com

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