DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T d

⟦88414b2b0⟧ TextFile

    Length: 6663 (0x1a07)
    Types: TextFile
    Names: »dsa_wait.c«

Derivation

└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0
    └─⟦35176feda⟧ »EurOpenD22/isode/isode-6.tar.Z« 
        └─⟦de7628f85⟧ 
            └─⟦this⟧ »isode-6.0/quipu/dsa_wait.c« 

TextFile

/* dsa_wait.c - accept and process events listened for */

#ifndef lint
static char *rcsid = "$Header: /f/osi/quipu/RCS/dsa_wait.c,v 7.1 89/12/19 16:20:30 mrose Exp $";
#endif

/*
 * $Header: /f/osi/quipu/RCS/dsa_wait.c,v 7.1 89/12/19 16:20:30 mrose Exp $
 *
 *
 * $Log:	dsa_wait.c,v $
 * Revision 7.1  89/12/19  16:20:30  mrose
 * sync
 * 
 * Revision 7.0  89/11/23  22:17:25  mrose
 * Release 6.0
 * 
 */

/*
 *                                NOTICE
 *
 *    Acquisition, use, and distribution of this module and related
 *    materials are subject to the restrictions of a license agreement.
 *    Consult the Preface in the User's Manual for the full terms of
 *    this agreement.
 *
 */


#include "rosap.h"
#include "tsap.h"
#include "quipu/util.h"
#include "quipu/connection.h"
#include <signal.h>

extern LLog * log_dsap;
extern int start_nameserver;
extern int nameserver_unused;

extern unsigned watchdog_time;
extern unsigned watchdog_delta;

dsa_wait(secs)
int	  secs;
{
    int                         vecp = 0;
    char                        *vec[4];
    fd_set                      iads;
    fd_set                      wads;
    int                         nads;
    struct TSAPdisconnect       td_s;
    struct TSAPdisconnect       *td = &td_s;
    struct connection		* cn;
    struct connection		* next_cn;
    char			ibuffer[BUFSIZ];
    char			*ibp;
    char			wbuffer[BUFSIZ];
    char			*wbp;
    extern int 			nameservice;
    SFD 			attempt_restart();
    int				newfd;

    nads = 0;
    FD_ZERO(&iads);
    FD_ZERO(&wads);
    ibp = ibuffer;
    wbp = wbuffer;

/*
    DLOG(log_dsap, LLOG_DEBUG, ("dsa_wait connections:"));
    conn_list_log(connlist);
*/ 

    for(cn=connlist; cn != NULLCONN; cn=cn->cn_next)
    {
	if (cn->cn_state == CN_CONNECTING1)
	{
	    FD_SET(cn->cn_ad, &wads);
	    (void) sprintf(wbp, ", %d.", cn->cn_ad);
	    wbp += (strlen(wbp) - 1);
	}
	else
	{
	    FD_SET(cn->cn_ad, &iads);
	    (void) sprintf(ibp, ", %d.", cn->cn_ad);
	    ibp += (strlen(ibp) - 1);
	}

	if(cn->cn_ad >= nads)
	    nads = cn->cn_ad + 1;
    }

    if(ibp == ibuffer)
    {
	DLOG (log_dsap, LLOG_DEBUG, ("Listening for new associations"));
    }
    else
    {
	LLOG (log_dsap, LLOG_NOTICE, ("Listening on ads: %s", (ibuffer+1)));
    }

    if(wbp == wbuffer)
    {
	DLOG (log_dsap, LLOG_DEBUG, ("Not making new associations"));
    }
    else
    {
	LLOG (log_dsap, LLOG_NOTICE, ("Making ads: %s", (wbuffer+1)));
    }

    if (start_nameserver)
    {
	if(nameserver_unused)
	{
	    DLOG (log_dsap, LLOG_DEBUG, ("Nameservice on ad: %d", nameservice));
	    if ( FD_ISSET (nameservice, &iads)) {
		LLOG(log_dsap, LLOG_EXCEPTIONS, ("Nameservice set by connection!"));
	    }
	    else {
		if (nameservice >= nads)
		    nads = nameservice + 1;
		FD_SET (nameservice,&iads);
		DLOG(log_dsap, LLOG_DEBUG, ("Set nameservice"));
	    }
	}
	else
	{
	    DLOG (log_dsap, LLOG_DEBUG, ("Nameservice in use (ad: %d)", nameservice));
	    if ( FD_ISSET (nameservice, &iads)) {
		LLOG(log_dsap, LLOG_EXCEPTIONS, ("Nameservice IN USE and set by connection!"));
	    }
	}
    }
    else {
	DLOG (log_dsap, LLOG_DEBUG, ("Nameservice off"));
    }

    DLOG (log_dsap, LLOG_NOTICE, ("secs: %d; nads: %d; iads 0x%x, wads 0x%x", 
	secs, nads, iads.fds_bits[0], wads.fds_bits[0]));

    if (secs != NOTOK) {
	/* if secs == NOTOK we want to block, otherwise set watchdog, but
	   beware of setting watchdog off accidentally !
	*/
	if (secs > (watchdog_time - watchdog_delta))
		watch_dog_aux ("TNetAccept (long)",(unsigned)secs + watchdog_delta);
	else
		watch_dog ("TNetAccept");
    }

    if(TNetAcceptAux(&vecp, vec, &newfd, NULLTA, nads, &iads, &wads, NULLFD, secs, td) == NOTOK)
    {
	watch_dog_reset();

	td_log (td, "TNetAccept");

	if (td -> td_reason == DR_PROTOCOL || td -> td_reason == DR_NETWORK) 
		return;

	attempt_restart (NOTOK);
	exit (0);			/* should not be reached */
    }
    watch_dog_reset();

    if (vecp > 0) 
	conn_pre_init (newfd,vecp,vec);

    if (start_nameserver)
    {
	if (FD_ISSET (nameservice,&iads))
	{
	    ns_process (nameservice);
    	}
    }

    for(cn = connlist; cn != NULLCONN; cn = next_cn)
    {
	next_cn = cn->cn_next;

	switch(cn->cn_state)
	{
	case CN_CONNECTING1:
	    DLOG(log_dsap, LLOG_TRACE, ("Checking %d", cn->cn_ad));
	    if(FD_ISSET(cn->cn_ad, &wads))
	    {
	        DLOG(log_dsap, LLOG_DEBUG, ("Polling %d", cn->cn_ad));
	        conn_retry(cn);
	    }
	break;

	case CN_CONNECTING2:
	    DLOG (log_dsap, LLOG_TRACE, ("Checking %d (2)", cn ->cn_ad));
	    if (FD_ISSET(cn->cn_ad, &iads))
	    {
		DLOG(log_dsap, LLOG_DEBUG, ("Polling %d (2)", cn->cn_ad));
		conn_retry(cn);
	    }
	break;

	case CN_OPEN:
	    if (FD_ISSET (cn->cn_ad, &iads))
	    {
		DLOG (log_dsap,LLOG_DEBUG,( "Activity on association: %d", cn->cn_ad));
		conn_dispatch(cn);
	    } /* if there is work on this connection */
	break;

	case CN_CLOSING:
	    if (FD_ISSET (cn->cn_ad, &iads)) 
		(void) conn_release_retry(cn);
	break;

	case CN_OPENING:
	    if (FD_ISSET (cn->cn_ad, &iads))
		conn_init(cn);
	break;

	case CN_INDICATED:
	    if (FD_ISSET (cn->cn_ad, &iads))
	    {
		if(cn->cn_bind_compare == NULLOPER)
		{
		    LLOG(log_dsap, LLOG_EXCEPTIONS, ("cn_state = INDICATED but no bind_compare operation"));
		}
		else
		{
		    cn->cn_bind_compare->on_bind_compare = NULLCONN;
		}
	    }
	    /* FALL THROUGH */
	
	default:
	    if (FD_ISSET (cn->cn_ad, &iads))
	    {
		if (cn->cn_initiator == INITIATED_BY_THIS) {
			LLOG (log_dsap,LLOG_EXCEPTIONS,( "Unexpected activity on association %d ... aborting",cn->cn_ad));
			net_send_abort(cn);
			conn_extract(cn);
		} else
			LLOG (log_dsap,LLOG_EXCEPTIONS,( "Unexpected activity on association %d ... ignoring",cn->cn_ad));
	    } /* if there is work on this connection */
	break;
	}
    } /* for each connection */

} /* dsa_wait */


static char * watch_dog_where;

static SFD watch_dog_activate ()
{
static char called = FALSE;

	if (!called) {
		called = TRUE;
		LLOG (log_dsap, LLOG_FATAL, ("Watchdog activated in %s", watch_dog_where));
		attempt_restart (-2);
	} else 
		LLOG (log_dsap, LLOG_FATAL, ("Repeated lower level blocking in %s", watch_dog_where));
		
	exit(-1);
}

watch_dog (where)
char * where;
{
/*
	A simple timer to stop DSAs holding onto associations, due to
	a lower level failure.
*/
	watch_dog_where = where;
	(void) signal (SIGALRM, watch_dog_activate);
	(void) alarm (watchdog_time);
}

watch_dog_aux (where,secs)
char * where;
unsigned secs;
{
	watch_dog_where = where;
	(void) signal (SIGALRM, watch_dog_activate);
	(void) alarm (secs);
}

watch_dog_reset ()
{
	(void) signal (SIGALRM, SIG_IGN);
	(void) alarm ((unsigned) 0);
}