From da0e32587f4b06e42c398c38b2041de7cd550992 Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Mon, 4 Oct 1993 17:46:55 +0000 Subject: [PATCH] ANSI C conversion & select() under vxWorks --- src/ca/access.c | 885 ++++++++++++++++++++++++++---------------- src/ca/acctst.c | 130 +++++-- src/ca/ca_printf.c | 61 ++- src/ca/conn.c | 185 +++++---- src/ca/convert.c | 205 ++++++++-- src/ca/flow_control.c | 15 +- src/ca/iocinf.c | 577 +++++++++++++++------------ src/ca/repeater.c | 61 +-- src/ca/service.c | 179 +++++---- src/ca/test_event.c | 14 +- 10 files changed, 1460 insertions(+), 852 deletions(-) diff --git a/src/ca/access.c b/src/ca/access.c index eab584c79..1b651ff92 100644 --- a/src/ca/access.c +++ b/src/ca/access.c @@ -111,7 +111,7 @@ /************************************************************************/ /*_end */ -static char *sccsId = "@(#)access.c 1.34\t8/5/93"; +static char *sccsId = "$Id$"; /* * allocate error message string array @@ -132,6 +132,17 @@ static char *sccsId = "@(#)access.c 1.34\t8/5/93"; # include # include # include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include # else @@@@ dont compile @@@@ # endif @@ -143,11 +154,22 @@ static char *sccsId = "@(#)access.c 1.34\t8/5/93"; */ #define DB_TEXT_GLBLSOURCE #include - -#include #include #include #include +#ifdef vxWorks +#include +#endif + +/* + * logistical problems prevent including this file + */ +#ifdef vxWorks +#if 0 +#define caClient +#include +#endif +#endif /****************************************************************/ @@ -177,17 +199,16 @@ static char *sccsId = "@(#)access.c 1.34\t8/5/93"; /****************************************************************/ /* Macros for error checking */ /****************************************************************/ + /* - valid type check filters out disconnected channel -*/ + * valid type check filters out disconnected channel + */ #define CHIXCHK(CHIX) \ { \ - register unsigned short iocix = (CHIX)->iocix; \ - if( iocix == BROADCAST_IIU || \ - (iocix >= nxtiiu && iocix != LOCAL_IIU) || \ - INVALID_DB_REQ((CHIX)->type) ) \ - return ECA_BADCHID; \ + if( (CHIX)->state != cs_conn || INVALID_DB_REQ((CHIX)->type) ){ \ + return ECA_BADCHID; \ + } \ } /* type to detect them using deallocated channel in use block */ @@ -196,10 +217,9 @@ static char *sccsId = "@(#)access.c 1.34\t8/5/93"; /* allow them to add monitors to a disconnected channel */ #define LOOSECHIXCHK(CHIX) \ { \ - register unsigned short iocix = CHIX->iocix; \ - if( (iocix >= nxtiiu && iocix != LOCAL_IIU) || \ - (CHIX)->type==TYPENOTINUSE ) \ - return ECA_BADCHID; \ + if( (CHIX)->type==TYPENOTINUSE ){ \ + return ECA_BADCHID; \ + } \ } #define INITCHK \ @@ -216,22 +236,49 @@ static struct extmsg nullmsg; /* * local functions */ -void ca_default_exception_handler(); -void *db_init_events(); -void ca_default_exception_handler(); -static void spawn_repeater(); -static int check_for_fp(); -static void issue_get_callback(); -static void ca_event_handler(); -static void ca_pend_io_cleanup(); -static int ca_add_task_variable(); -int ca_import(); -struct extmsg *cac_alloc_msg(); +#ifdef __STDC__ + +LOCAL struct extmsg *cac_alloc_msg( +struct ioc_in_use *piiu, +unsigned extsize +); +LOCAL void spawn_repeater(); +LOCAL int check_for_fp(); +LOCAL int ca_add_task_variable(); #ifdef vxWorks -void ca_task_exit_tid(); -static void ca_task_exit_tcb(); +LOCAL void ca_task_exit_tcb(WIND_TCB *ptcb); +LOCAL void ca_task_exit_tid(int tid); #else void ca_process_exit(); +#endif +LOCAL void issue_get_callback(evid monix); +LOCAL void ca_event_handler( +evid monix, +struct db_addr *paddr, +int hold, +void *pfl +); +LOCAL void ca_pend_io_cleanup(); + +#else + +LOCAL struct extmsg *cac_alloc_msg(); +LOCAL void spawn_repeater(); +LOCAL int check_for_fp(); +LOCAL int ca_add_task_variable(); +#ifdef vxWorks +LOCAL void ca_task_exit_tcb(); +LOCAL void ca_task_exit_tid(); +#else +void ca_process_exit(); +#endif +LOCAL void issue_get_callback(); +LOCAL void ca_event_handler(); +LOCAL void ca_pend_io_cleanup(); + +void ca_default_exception_handler(); +void ca_default_exception_handler(); + #endif @@ -245,12 +292,16 @@ void ca_process_exit(); * LOCK should be on * */ -#if 0 -static -#endif -struct extmsg *cac_alloc_msg(piiu, extsize) +#ifdef __STDC__ +LOCAL struct extmsg *cac_alloc_msg( +struct ioc_in_use *piiu, +unsigned extsize +) +#else +LOCAL struct extmsg *cac_alloc_msg(piiu, extsize) struct ioc_in_use *piiu; unsigned extsize; +#endif { unsigned msgsize; unsigned msglimit; @@ -265,12 +316,9 @@ unsigned extsize; if(piiu->outstanding_ack_count > ((unsigned)0) && !post_msg_active){ unsigned max1; unsigned size; - int rcva; - - rcva = RECV_ACTIVE(piiu); size = piiu->tcp_send_buff_size; - if(rcva){ + if(RECV_ACTIVE(piiu)){ max1=size<<2; } else{ @@ -278,7 +326,7 @@ unsigned extsize; } if(piiu->bytes_pushing_an_ack > max1){ - if(rcva){ + if(RECV_ACTIVE(piiu)){ return NULL; } @@ -316,14 +364,13 @@ unsigned extsize; * * */ -int ca_task_initialize #ifdef __STDC__ -(void) +int ca_task_initialize(void) #else -() +int ca_task_initialize() #endif { - int status; + int status; if (!ca_static) { @@ -332,29 +379,72 @@ int ca_task_initialize if(status != ECA_NORMAL){ return status; } - - if (ca_add_task_variable()<0) - return ECA_ALLOCMEM; #endif if (repeater_installed()==FALSE) { spawn_repeater(); } - ca_static = (struct ca_static *) calloc(1, sizeof(*ca_static)); - if (!ca_static) - abort(); +#ifdef vxWorks + if (ca_add_task_variable()<0) + return ECA_ALLOCMEM; +#endif ca_static->ca_exception_func = ca_default_exception_handler; ca_static->ca_exception_arg = NULL; ca_static->ca_pBucket = bucketCreate(CLIENT_ID_WIDTH); if(!ca_static->ca_pBucket) - abort(); + abort(0); status = broadcast_addr(&ca_static->ca_castaddr); if(status == OK){ - ca_static->ca_cast_available = TRUE; + int pri; + char name[64]; + + status = alloc_ioc( + &ca_static->ca_castaddr, + IPPROTO_UDP, + &ca_static->ca_piiuCast); + if (~status & CA_M_SUCCESS) { + ca_static->ca_piiuCast = NULL; + } + +#ifdef vxWorks + status = taskPriorityGet(VXTASKIDSELF, &pri); + if(status<0) + ca_signal(ECA_INTERNAL,NULL); + + strcpy(name,"RD "); + strncat( + name, + taskName(VXTHISTASKID), + sizeof(name)-strlen(name)-1); + + status = taskSpawn( + name, + pri-1, + VX_FP_TASK, + 4096, + (FUNCPTR)cac_recv_task, + (int)taskIdCurrent, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL); + if(status<0) + ca_signal(ECA_INTERNAL,NULL); + + ca_static->recv_tid = status; +#endif + } + + if(!ca_static->ca_piiuCast){ SEVCHK(ECA_NOCAST, NULL); } @@ -378,12 +468,12 @@ int ca_task_initialize FASTLOCKINIT(&event_lock); io_done_sem = semBCreate(SEM_Q_PRIORITY, SEM_EMPTY); if(!io_done_sem){ - abort(); + abort(0); } evuser = (void *) db_init_events(); if (!evuser) - abort(); + abort(0); strcpy(name, "EV "); strncat( @@ -397,7 +487,7 @@ int ca_task_initialize taskIdSelf(), -1); /* higher priority */ if (status != OK) - abort(); + abort(0); } # else # if defined(UNIX) @@ -418,8 +508,7 @@ int ca_task_initialize * * Spawn the repeater task as needed */ -static void -spawn_repeater() +LOCAL void spawn_repeater() { #ifdef UNIX @@ -450,7 +539,17 @@ spawn_repeater() CA_REPEATER_PRI, CA_REPEATER_OPT, CA_REPEATER_STACK, - ca_repeater_task); + ca_repeater_task, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL); if (status < 0){ SEVCHK(ECA_NOREPEATER, NULL); } @@ -495,14 +594,13 @@ spawn_repeater() * */ #ifdef vxWorks -static int -check_for_fp() +LOCAL int check_for_fp() { { int options; if (taskOptionsGet(taskIdSelf(), &options) == ERROR) - abort(); + abort(0); if (!(options & VX_FP_TASK)) { return ECA_NEEDSFP; } @@ -518,29 +616,46 @@ check_for_fp() * */ #ifdef vxWorks -ca_import(tid) - int tid; +#ifdef __STDC__ +int ca_import(int tid) +#else +int ca_import(tid) +int tid; +#endif { int status; struct ca_static *pcas; + TVIU *ptviu; status = check_for_fp(); if(status != ECA_NORMAL){ return status; } + ptviu = calloc(1, sizeof(*ptviu)); + if(!ptviu){ + return ECA_ALLOCMEM; + } + pcas = (struct ca_static *) - taskVarGet(tid, &ca_static); - - if (pcas == (struct ca_static *) ERROR) + taskVarGet(tid, (int *)&ca_static); + if (pcas == (struct ca_static *) ERROR){ + free(ptviu); return ECA_NOCACTX; + } - status = taskVarAdd(VXTHISTASKID, &ca_static); - if (status == ERROR) - abort(); + ca_static = NULL; + + status = taskVarAdd(VXTHISTASKID, (int *)&ca_static); + if (status == ERROR){ + free(ptviu); + return ECA_ALLOCMEM; + } ca_static = pcas; + ptviu->tid = taskIdSelf(); + ellAdd(&ca_static->ca_taskVarList, &ptviu->node); return ECA_NORMAL; } @@ -555,16 +670,23 @@ ca_import(tid) * */ #ifdef vxWorks -static int -ca_add_task_variable() +LOCAL int ca_add_task_variable() { - static char ca_installed; - int status; + struct ca_static *ca_temp; + static char ca_installed; + TVIU *ptviu; + int status; # if DEBUG ca_printf("CAC: adding task variable\n"); # endif + status = taskVarGet(VXTHISTASKID, (int *)&ca_static); + if(status == OK){ + ca_printf("task variable already installed?\n"); + return ERROR; + } + /* * only one delete hook for all CA tasks */ @@ -588,17 +710,32 @@ ca_add_task_variable() status = taskVarInit(); if (status != OK) return ERROR; - status = taskDeleteHookAdd(ca_task_exit_tcb); + status = taskDeleteHookAdd((FUNCPTR)ca_task_exit_tcb); if (status != OK) { - logMsg("ca_init_task: could not add CA delete routine\n"); + ca_printf("ca_init_task: could not add CA delete routine\n"); return ERROR; } } - status = taskVarAdd(VXTHISTASKID, &ca_static); + ca_temp = (struct ca_static *) calloc(1, sizeof(*ca_static)); + if (!ca_temp) + return ERROR; + + ptviu = calloc(1, sizeof(*ptviu)); + if(!ptviu){ + free(ca_temp); + return ERROR; + } + + ptviu->tid = taskIdSelf(); + ellAdd(&ca_temp->ca_taskVarList, &ptviu->node); + + status = taskVarAdd(VXTHISTASKID, (int *)&ca_static); if (status != OK) return ERROR; + ca_static = ca_temp; + return OK; } #endif @@ -634,9 +771,12 @@ int ca_task_exit * */ #ifdef vxWorks -static void -ca_task_exit_tcb(ptcb) +#ifdef __STDC__ +LOCAL void ca_task_exit_tcb(WIND_TCB *ptcb) +#else +LOCAL void ca_task_exit_tcb(ptcb) WIND_TCB *ptcb; +#endif { # if DEBUG ca_printf("CAC: entering the exit handler %x\n", ptcb); @@ -662,25 +802,27 @@ WIND_TCB *ptcb; * NOTE: on vxWorks if a CA task is deleted or crashes while a * lock is set then a deadlock will occur when this routine is called. * -static */ -void #ifdef vxWorks -ca_task_exit_tid(tid) - int tid; +#ifdef __STDC__ +LOCAL void ca_task_exit_tid(int tid) #else -ca_process_exit() +LOCAL void ca_task_exit_tid(tid) + int tid; +#endif +#else +LOCAL void ca_process_exit() #endif { - int i; chid chix; struct ca_static *ca_temp; evid monix; + IIU *piiu; #ifdef vxWorks int status; #endif -# ifdef DEBUG +# if defined(DEBUG) && defined(vxWorks) ca_printf("CAC: entering the exit handler 2 %x\n", tid); # endif @@ -690,14 +832,15 @@ ca_process_exit() taskVarGetPatch(tid, &ca_static); if (ca_temp == (struct ca_static *) ERROR){ -# if DEBUG +# ifdef DEBUG ca_printf("CAC: task variable lookup failed\n"); # endif return; } -# if DEBUG - ca_printf( "CAC: exit handler with ca_static = %x\n", - ca_static); +# ifdef DEBUG + ca_printf( + "CAC: exit handler with ca_static = %x\n", + ca_temp); # endif # else ca_temp = ca_static; @@ -716,7 +859,7 @@ ca_process_exit() if (ca_temp) { # ifdef vxWorks - logMsg("ca_task_exit: Removing task %x from CA\n", tid); + ca_printf("ca_task_exit: Removing task %x from CA\n", tid); # endif /* @@ -735,20 +878,24 @@ ca_process_exit() * LOCK placed above */ + /* - * stop socket recv tasks + * stop socket recv task */ # ifdef vxWorks - for (i = 0; i < ca_temp->ca_nxtiiu; i++) { + if(taskIdVerify(ca_temp->recv_tid)==OK){ + taskwdRemove(ca_temp->recv_tid); /* * dont do a task delete if the exit handler is * running for this task - it botches vxWorks - */ - if (tid != ca_temp->ca_iiu[i].recv_tid) - taskDelete(ca_temp->ca_iiu[i].recv_tid); + if(ca_temp->recv_tid != tid){ + taskSuspend(ca_temp->recv_tid); + } } # endif + /* * Cancel all local events */ @@ -758,12 +905,46 @@ ca_process_exit() while (monix = (evid) ellGet(&chix->eventq)) { status = db_cancel_event(monix + 1); if (status == ERROR) - abort(); + abort(0); free(monix); } } # endif + /* + * cancel task vars for other tasks so this + * only runs once + * + * This is done only after all oustanding events + * are drained so that the event task still has a CA context + * + * db_close_events() does not require a CA context. + */ +# ifdef vxWorks + { + TVIU *ptviu; + while(ptviu = (TVIU *)ellGet(&ca_temp->ca_taskVarList)){ +#ifdef DEBUG + ca_printf( + "Removing tsk var from %x\n", + ptviu->tid); +#endif + status = taskVarDelete( + ptviu->tid, + (int *)&ca_static); + if(status<0){ + ca_printf( + "tsk var del err %x\n", + ptviu->tid); + } + free(ptviu); + } + if(ca_temp->recv_tid != tid){ + taskDelete(ca_temp->recv_tid); + } + } +# endif + /* * All local events must be canceled prior to closing the * local event facility @@ -787,34 +968,38 @@ ca_process_exit() * close all sockets before clearing chid blocks and remote * event blocks */ - for (i = 0; i < ca_temp->ca_nxtiiu; i++) { - if (ca_temp->ca_iiu[i].conn_up){ - if(fd_register_func){ - (*fd_register_func)( - fd_register_arg, - ca_temp->ca_iiu[i].sock_chan, - FALSE); - } - if (socket_close(ca_temp->ca_iiu[i].sock_chan) < 0){ - ca_signal( - ECA_INTERNAL, - "Corrupt iiu list- at close"); - } + piiu = (struct ioc_in_use *) + ca_temp->ca_iiuList.node.next; + while(piiu){ + if(ca_temp->ca_fd_register_func){ + (*ca_temp->ca_fd_register_func)( + ca_temp->ca_fd_register_arg, + piiu->sock_chan, + FALSE); } - free((char *)ca_temp->ca_iiu[i].send); - free((char *)ca_temp->ca_iiu[i].recv); + if (socket_close(piiu->sock_chan) < 0){ + ca_signal( + ECA_INTERNAL, + "Corrupt iiu list- at close"); + } + free((char *)piiu->send); + free((char *)piiu->recv); + piiu = (struct ioc_in_use *) piiu->node.next; } /* * remove remote chid blocks and event blocks */ - for (i = 0; i < ca_temp->ca_nxtiiu; i++) { - while (chix = (chid) ellGet(&ca_temp->ca_iiu[i].chidlist)) { + piiu = (struct ioc_in_use *) + ca_temp->ca_iiuList.node.next; + while(piiu){ + while (chix = (chid) ellGet(&piiu->chidlist)) { while (monix = (evid) ellGet(&chix->eventq)) { free((char *)monix); } free((char *)chix); } + piiu = (struct ioc_in_use *) piiu->node.next; } /* @@ -851,30 +1036,14 @@ ca_process_exit() } # endif + /* + * remove IOCs in use + */ + ellFree(&ca_temp->ca_iiuList); + free((char *)ca_temp); ca_static = (struct ca_static *) NULL; - /* - * Only remove task variable if user is calling this from - * ca_task_exit and the task is not being deleted - * - * in this case the dest tid will match the current task id - * - * This is because if I delete the task variable from a vxWorks - * exit handler it botches vxWorks task exit - */ -# ifdef vxWorks - if (tid == taskIdSelf()) { - int status; - - status = taskVarDelete(tid, &ca_static); - if (status == ERROR) - ca_signal( - ECA_INTERNAL, - "Unable to remove ca_static from task var list"); - } -# endif - } } @@ -956,7 +1125,7 @@ int ca_build_and_connect *chixptr = chix = (chid) malloc(sizeof(*chix) + strcnt + sizeof(struct db_addr)); if (!chix) - abort(); + abort(0); chix->id.paddr = (struct db_addr *) (strcnt + (char *) (chix + 1)); @@ -965,10 +1134,10 @@ int ca_build_and_connect chix->connection_func = conn_func; chix->type = chix->id.paddr->field_type; chix->count = chix->id.paddr->no_elements; - chix->iocix = LOCAL_IIU; + chix->piiu = NULL; /* none */ chix->state = cs_conn; ellInit(&chix->eventq); - strncpy(chix + 1, name_str, strcnt); + strncpy((char *)(chix + 1), name_str, strcnt); /* check for just a search */ if (get_count && get_type != TYPENOTCONN && pvalue) { @@ -985,7 +1154,7 @@ int ca_build_and_connect } } LOCK; - ellAdd(&local_chidlist, chix); + ellAdd(&local_chidlist, &chix->node); UNLOCK; if (chix->connection_func) { @@ -1001,77 +1170,67 @@ int ca_build_and_connect } #endif - if (!ca_static->ca_cast_available) { - status = ECA_NOCAST; + if (!ca_static->ca_piiuCast) { + return ECA_NOCAST; } - else{ - /* allocate CHIU (channel in use) block */ - /* also allocate enough for the channel name */ - *chixptr = chix = (chid) malloc(sizeof(*chix) + strcnt); - if (!chix) - return ECA_ALLOCMEM; + /* allocate CHIU (channel in use) block */ + /* also allocate enough for the channel name */ + *chixptr = chix = (chid) malloc(sizeof(*chix) + strcnt); + if (!chix){ + return ECA_ALLOCMEM; + } - LOCK; - status = alloc_ioc( - &ca_static->ca_castaddr, - IPPROTO_UDP, - &chix->iocix - ); - if (~status & CA_M_SUCCESS) { - *chixptr = (chid) NULL; - free((char *) chix); - goto exit; - } + LOCK; + chix->cid = CLIENT_ID_ALLOC; + status = bucketAddItem(pBucket, chix->cid, chix); + if(status != BUCKET_SUCCESS){ + *chixptr = (chid) NULL; + free((char *) chix); + status = ECA_ALLOCMEM; + goto exit; + } - chix->cid = CLIENT_ID_ALLOC; - status = bucketAddItem(pBucket, chix->cid, chix); - if(status != BUCKET_SUCCESS){ - *chixptr = (chid) NULL; - free((char *) chix); - status = ECA_ALLOCMEM; - goto exit; - } + chix->puser = puser; + chix->connection_func = conn_func; + chix->type = TYPENOTCONN; /* invalid initial type */ + chix->count = 0; /* invalid initial count */ + chix->id.sid = ~0L; /* invalid initial server id */ - chix->puser = puser; - chix->connection_func = conn_func; - chix->type = TYPENOTCONN; /* invalid initial type */ - chix->count = 0; /* invalid initial count */ - chix->id.sid = ~0L; /* invalid initial server id */ + /* save stuff for build retry if required */ + chix->build_type = get_type; + chix->build_count = get_count; + chix->build_value = (void *) pvalue; + chix->name_length = strcnt; + chix->state = cs_never_conn; + ellInit(&chix->eventq); - /* save stuff for build retry if required */ - chix->build_type = get_type; - chix->build_count = get_count; - chix->build_value = (void *) pvalue; - chix->name_length = strcnt; - chix->state = cs_never_conn; - ellInit(&chix->eventq); + /* Save this channels name for retry if required */ + strncpy((char *)(chix + 1), name_str, strcnt); - /* Save this channels name for retry if required */ - strncpy(chix + 1, name_str, strcnt); + chix->piiu = piiuCast; + ellAdd(&piiuCast->chidlist, &chix->node); - ellAdd(&iiu[BROADCAST_IIU].chidlist, chix); - /* - * set the conn tries back to zero so this channel's location - * can be found - */ - iiu[BROADCAST_IIU].nconn_tries = 0; - iiu[BROADCAST_IIU].next_retry = CA_CURRENT_TIME; - iiu[BROADCAST_IIU].retry_delay = CA_RECAST_DELAY; + /* + * set the conn tries back to zero so this channel's location + * can be found + */ + piiuCast->nconn_tries = 0; + piiuCast->next_retry = CA_CURRENT_TIME; + piiuCast->retry_delay = CA_RECAST_DELAY; - build_msg(chix, DONTREPLY); - if (!chix->connection_func) { + build_msg(chix, DONTREPLY); + if (!chix->connection_func) { + SETPENDRECV; + if (VALID_BUILD(chix)) SETPENDRECV; - if (VALID_BUILD(chix)) - SETPENDRECV; - } - - status = ECA_NORMAL; -exit: - - UNLOCK; } + status = ECA_NORMAL; + +exit: + UNLOCK; + return status; } @@ -1084,16 +1243,23 @@ exit: * NOTE: *** lock must be applied while in this routine *** * */ +#ifdef __STDC__ +void build_msg( +chid chix, +int reply_type +) +#else void build_msg(chix, reply_type) - chid chix; - int reply_type; +chid chix; +int reply_type; +#endif { - register int size; - register int cmd; - register struct extmsg *mptr; + int size; + int cmd; + struct extmsg *mptr; struct ioc_in_use *piiu; - piiu = &iiu[chix->iocix]; + piiu = chix->piiu; if (VALID_BUILD(chix)) { size = chix->name_length + sizeof(struct extmsg); @@ -1123,14 +1289,14 @@ void build_msg(chix, reply_type) mptr->m_type = htons(chix->build_type); mptr->m_count = htons(chix->build_count); mptr->m_available = (int) chix->build_value; - mptr->m_cid = ~0L; + mptr->m_cid = chix->cid; } /* * channel name string - forces a NULL at the end because * strcnt is always >= strlen + 1 */ mptr++; - strncpy(mptr, chix + 1, chix->name_length); + strncpy((char *)mptr, (char *)(chix + 1), chix->name_length); CAC_ADD_MSG(piiu); @@ -1144,7 +1310,7 @@ void build_msg(chix, reply_type) * * */ -ca_array_get +int ca_array_get #ifdef __STDC__ ( chtype type, @@ -1176,7 +1342,7 @@ void *pvalue { int status; - if (chix->iocix == LOCAL_IIU) { + if(!chix->piiu) { status = db_get_field( chix->id.paddr, type, @@ -1192,7 +1358,7 @@ void *pvalue #endif LOCK; - piiu = &iiu[chix->iocix]; + piiu = chix->piiu; mptr = CAC_ALLOC_MSG(piiu, size); if(!mptr){ UNLOCK; @@ -1231,7 +1397,7 @@ void *pvalue * * */ -ca_array_get_callback +int ca_array_get_callback #ifdef __STDC__ ( chtype type, @@ -1262,7 +1428,7 @@ ca_array_get_callback #ifdef vxWorks - if (chix->iocix == LOCAL_IIU) { + if (!chix->piiu) { struct pending_event ev; ev.usr_func = pfunc; @@ -1287,7 +1453,7 @@ ca_array_get_callback monix->type = type; monix->count = count; - ellAdd(&pend_read_list, monix); + ellAdd(&pend_read_list, &monix->node); issue_get_callback(monix); @@ -1306,9 +1472,12 @@ ca_array_get_callback * ISSUE_GET_CALLBACK() * (lock must be on) */ -static void -issue_get_callback(monix) - register evid monix; +#ifdef __STDC__ +LOCAL void issue_get_callback(evid monix) +#else +LOCAL void issue_get_callback(monix) +evid monix; +#endif { register chid chix = monix->chan; unsigned size = 0; @@ -1316,7 +1485,7 @@ issue_get_callback(monix) register struct extmsg *mptr; struct ioc_in_use *piiu; - piiu = &iiu[chix->iocix]; + piiu = chix->piiu; /* * dont send the message if the conn is down @@ -1367,7 +1536,7 @@ issue_get_callback(monix) * * */ -ca_array_put +int ca_array_put #ifdef __STDC__ ( chtype type, @@ -1383,11 +1552,11 @@ chid chix; void *pvalue; #endif { - register struct extmsg *mptr; - register int postcnt; - register void *pdest; - register unsigned size_of_one; - register int i; + struct extmsg *mptr; + int postcnt; + void *pdest; + unsigned size_of_one; + int i; /* * valid channel id test @@ -1410,7 +1579,7 @@ void *pvalue; { int status; - if(chix->iocix == LOCAL_IIU){ + if(!chix->piiu){ status = db_put_field( chix->id.paddr, type, pvalue, @@ -1452,7 +1621,7 @@ void *pvalue; LOCK; - mptr = CAC_ALLOC_MSG(&iiu[chix->iocix], postcnt); + mptr = CAC_ALLOC_MSG(chix->piiu, postcnt); if(!mptr){ UNLOCK; return ECA_TOLARGE; @@ -1513,7 +1682,7 @@ void *pvalue; mptr->m_cid = chix->id.sid; mptr->m_available = ~0L; - CAC_ADD_MSG(&iiu[chix->iocix]); + CAC_ADD_MSG(((IIU *)chix->piiu)); UNLOCK; return ECA_NORMAL; @@ -1524,7 +1693,7 @@ void *pvalue; * Specify an event subroutine to be run for connection events * */ -ca_change_connection_event +int ca_change_connection_event #ifdef __STDC__ ( chid chix, @@ -1567,7 +1736,7 @@ void (*pfunc)(); * Specify an event subroutine to be run for asynch exceptions * */ -ca_add_exception_event +int ca_add_exception_event #ifdef __STDC__ ( void (*pfunc)(struct exception_handler_args), @@ -1605,7 +1774,7 @@ void *arg; * Undocumented entry for the VAX OPI which may vanish in the future. * */ -ca_add_io_event +int ca_add_io_event #ifdef __STDC__ ( void (*ast)(), @@ -1630,7 +1799,7 @@ void *astarg; return ECA_ALLOCMEM; pioe->io_done_arg = astarg; pioe->io_done_sub = ast; - ellAdd(&ioeventlist,pioe); + ellAdd(&ioeventlist, &pioe->node); UNLOCK; } @@ -1645,7 +1814,7 @@ void *astarg; * * */ -ca_add_masked_array_event +int ca_add_masked_array_event #ifdef __STDC__ ( chtype type, @@ -1694,7 +1863,7 @@ long mask; { static int dbevsize; - if(chix->iocix == LOCAL_IIU){ + if(!chix->piiu){ if(!dbevsize) dbevsize = db_sizeof_event_block(); @@ -1733,9 +1902,8 @@ long mask; # ifdef vxWorks { - struct monops mon; - if(chix->iocix == LOCAL_IIU){ + if(!chix->piiu){ status = db_add_event( evuser, chix->id.paddr, ca_event_handler, @@ -1753,7 +1921,7 @@ long mask; is no chance that it will be deleted at exit before it is completely created */ - ellAdd(&chix->eventq, monix); + ellAdd(&chix->eventq, &monix->node); /* force event to be called at least once @@ -1774,7 +1942,7 @@ long mask; /* It can be added to the list any place if it is remote */ /* Place in the channel list */ - ellAdd(&chix->eventq, monix); + ellAdd(&chix->eventq, &monix->node); ca_request_event(monix); @@ -1793,9 +1961,12 @@ unlock_rtn: * * LOCK must be applied while in this routine */ -void -ca_request_event(monix) - evid monix; +#ifdef __STDC__ +void ca_request_event(evid monix) +#else +void ca_request_event(monix) +evid monix; +#endif { register chid chix = monix->chan; unsigned size = sizeof(struct mon_info); @@ -1803,7 +1974,7 @@ ca_request_event(monix) register struct monops *mptr; struct ioc_in_use *piiu; - piiu = &iiu[chix->iocix]; + piiu = chix->piiu; /* * dont send the message if the conn is down @@ -1856,12 +2027,20 @@ ca_request_event(monix) * */ #ifdef vxWorks -static void -ca_event_handler(monix, paddr, hold, pfl) -register evid monix; -register struct db_addr *paddr; -int hold; -void *pfl; +#ifdef __STDC__ +LOCAL void ca_event_handler( +evid monix, +struct db_addr *paddr, +int hold, +void *pfl +) +#else +LOCAL void ca_event_handler(monix, paddr, hold, pfl) +evid monix; +struct db_addr *paddr; +int hold; +void *pfl; +#endif { register int status; register int count; @@ -1911,7 +2090,7 @@ void *pfl; if(pbuf->size >= size){ ellDelete( &lcl_buff_list, - pbuf); + &pbuf->node); }else pbuf = NULL; UNLOCK; @@ -1924,7 +2103,7 @@ void *pfl; pbuf = (struct tmp_buff *) malloc(sizeof(*pbuf)+size); if(!pbuf) - abort(); + abort(0); pbuf->size = size; } @@ -1991,8 +2170,8 @@ void *pfl; ellInsert( &lcl_buff_list, - ptbuf, - pbuf); + &ptbuf->node, + &pbuf->node); UNLOCK; } @@ -2034,23 +2213,23 @@ evid monix; monix->usr_func = NULL; #ifdef vxWorks - if (chix->iocix == LOCAL_IIU) { + if (!chix->piiu) { register int status; /* * dont allow two threads to delete the same moniitor at once */ LOCK; - status = ellFind(&chix->eventq, monix); + status = ellFind(&chix->eventq, &monix->node); if (status != ERROR) { - ellDelete(&chix->eventq, monix); + ellDelete(&chix->eventq, &monix->node); status = db_cancel_event(monix + 1); } UNLOCK; if (status == ERROR) return ECA_BADMONID; - ellAdd(&dbfree_ev_list, monix); + ellAdd(&dbfree_ev_list, &monix->node); return ECA_NORMAL; } @@ -2066,7 +2245,7 @@ evid monix; if(chix->state == cs_conn){ struct ioc_in_use *piiu; - piiu = &iiu[chix->iocix]; + piiu = chix->piiu; mptr = CAC_ALLOC_MSG(piiu, 0); if(!mptr){ @@ -2094,7 +2273,7 @@ evid monix; piiu->outstanding_ack_count++; } else{ - ellDelete(&monix->chan->eventq, monix); + ellDelete(&monix->chan->eventq, &monix->node); } UNLOCK; @@ -2116,7 +2295,7 @@ evid monix; * (from this source) after leaving this routine. * */ -ca_clear_channel +int ca_clear_channel #ifdef __STDC__ (chid chix) #else @@ -2126,7 +2305,7 @@ chid chix; { int status; register evid monix; - struct ioc_in_use *piiu = &iiu[chix->iocix]; + struct ioc_in_use *piiu = chix->piiu; register struct extmsg *mptr; enum channel_state old_chan_state; @@ -2153,7 +2332,7 @@ chid chix; monix->usr_func = NULL; #ifdef vxWorks - if (chix->iocix == LOCAL_IIU) { + if (!chix->piiu) { int status; /* @@ -2162,14 +2341,14 @@ chid chix; while (monix = (evid) ellGet(&chix->eventq)) { status = db_cancel_event(monix + 1); if (status == ERROR) - abort(); - ellAdd(&dbfree_ev_list, monix); + abort(0); + ellAdd(&dbfree_ev_list, &monix->node); } /* * clear out this channel */ - ellDelete(&local_chidlist, chix); + ellDelete(&local_chidlist, &chix->node); free((char *) chix); break; /* to unlock exit */ @@ -2184,11 +2363,7 @@ chid chix; */ if(old_chan_state != cs_conn){ ellConcat(&free_event_list, &chix->eventq); - ellDelete(&piiu->chidlist, chix); - if (chix->iocix != BROADCAST_IIU && - !piiu->chidlist.count){ - close_ioc(piiu); - } + ellDelete(&piiu->chidlist, &chix->node); status = bucketRemoveItem(pBucket, chix->cid, chix); if(status != BUCKET_SUCCESS){ ca_signal( @@ -2265,7 +2440,7 @@ chid chix; /* ca_flush_io() is called by this routine. */ /************************************************************************/ #ifdef __STDC__ -ca_pend(ca_real timeout, int early) +int ca_pend(ca_real timeout, int early) #else ca_pend(timeout, early) ca_real timeout; @@ -2389,35 +2564,36 @@ int early; * * LOCK must be on */ -static void -ca_pend_io_cleanup() +LOCAL void ca_pend_io_cleanup() { struct ioc_in_use *piiu; - for( piiu = &iiu[BROADCAST_IIU+1]; - piiu<&iiu[nxtiiu]; - piiu++){ + for( piiu = (IIU *) iiuList.node.next; + piiu; + piiu = (IIU *) piiu->node.next){ - if(piiu->conn_up){ - struct extmsg *mptr; + struct extmsg *mptr; - piiu->cur_read_seq++; - mptr = CAC_ALLOC_MSG(piiu, 0); - if(!mptr){ - ca_printf("%s: %s\n",__FILE__,ca_message(ECA_TOLARGE)); - return; - } - - *mptr = nullmsg; - mptr->m_cmmd = htons(IOC_READ_SYNC); - CAC_ADD_MSG(piiu); - /* - * keep track of the number of messages - * outstanding on this connection that - * require a response - */ - piiu->outstanding_ack_count++; + if(piiu == piiuCast || !piiu->conn_up){ + continue; } + + piiu->cur_read_seq++; + mptr = CAC_ALLOC_MSG(piiu, 0); + if(!mptr){ + ca_printf("%s: %s\n",__FILE__,ca_message(ECA_TOLARGE)); + return; + } + + *mptr = nullmsg; + mptr->m_cmmd = htons(IOC_READ_SYNC); + CAC_ADD_MSG(piiu); + /* + * keep track of the number of messages + * outstanding on this connection that + * require a response + */ + piiu->outstanding_ack_count++; } pndrecvcnt = 0; } @@ -2550,11 +2726,7 @@ int lineno; # ifdef VMS lib$signal(0); # endif -# ifdef vxWorks - ti(VXTHISTASKID); - tt(VXTHISTASKID); -# endif - abort(); + abort(0); } ca_printf( @@ -2571,16 +2743,23 @@ int lineno; * CA_BUSY_MSG() * */ -void -ca_busy_message(piiu) +#ifdef __STDC__ +void ca_busy_message(struct ioc_in_use *piiu) +#else +void ca_busy_message(piiu) struct ioc_in_use *piiu; +#endif { struct extmsg *mptr; + if(!piiu){ + return; + } + /* - * dont send the message if the conn is down - */ - if(!piiu->conn_up || piiu == &iiu[BROADCAST_IIU]) + * dont broadcast + */ + if(piiu == piiuCast) return; LOCK; @@ -2602,16 +2781,23 @@ struct ioc_in_use *piiu; * CA_READY_MSG() * */ -void -ca_ready_message(piiu) +#ifdef __STDC__ +void ca_ready_message(struct ioc_in_use *piiu) +#else +void ca_ready_message(piiu) struct ioc_in_use *piiu; +#endif { struct extmsg *mptr; + if(!piiu){ + return; + } + /* - * dont send the message if the conn is down - */ - if(!piiu->conn_up || piiu == &iiu[BROADCAST_IIU]) + * dont broadcast + */ + if(piiu == piiuCast) return; LOCK; @@ -2634,9 +2820,12 @@ struct ioc_in_use *piiu; * NOOP_MSG (lock must be on) * */ -void -noop_msg(piiu) - register struct ioc_in_use *piiu; +#ifdef __STDC__ +void noop_msg(struct ioc_in_use *piiu) +#else +void noop_msg(piiu) +struct ioc_in_use *piiu; +#endif { struct extmsg *mptr; @@ -2656,17 +2845,24 @@ noop_msg(piiu) * ISSUE_CLAIM_CHANNEL (lock must be on) * */ -void -issue_claim_channel(piiu, pchan) +#ifdef __STDC__ +void issue_claim_channel(struct ioc_in_use *piiu, chid pchan) +#else +void issue_claim_channel(piiu, pchan) struct ioc_in_use *piiu; chid pchan; +#endif { struct extmsg *mptr; + if(!piiu){ + return; + } + /* - * dont send the message if the conn is down - */ - if(!piiu->conn_up || piiu == &iiu[BROADCAST_IIU]) + * dont broadcast + */ + if(piiu == piiuCast) return; mptr = CAC_ALLOC_MSG(piiu, 0); @@ -2689,15 +2885,18 @@ chid pchan; * * */ -void -ca_default_exception_handler(args) +#ifdef __STDC__ +void ca_default_exception_handler(struct exception_handler_args args) +#else +void ca_default_exception_handler(args) struct exception_handler_args args; +#endif { - /* - NOTE: - I should print additional diagnostic info when time permits...... - */ + /* + * NOTE: + * I should print additional diagnostic info when time permits...... + */ ca_signal(args.stat, args.ctx); } @@ -2707,13 +2906,18 @@ struct exception_handler_args args; /* * CA_ADD_FD_REGISTRATION * - * call their function with their argument whenever a new fd is added or removed + * call their function with their argument whenever + * a new fd is added or removed * (for a manager of the select system call under UNIX) * */ -ca_add_fd_registration(func, arg) -void (*func)(); -void *arg; +#ifdef __STDC__ +int ca_add_fd_registration(CAFDHANDLER *func, void *arg) +#else +int ca_add_fd_registration(func, arg) +CAFDHANDLER *func; +void *arg; +#endif { fd_register_func = func; fd_register_arg = arg; @@ -2729,13 +2933,14 @@ void *arg; * what is called by vacated entries in the VMS share image jump table * */ -ca_defunct() +int ca_defunct() { #ifdef VMS SEVCHK(ECA_DEFUNCT, "you must have a VMS share image mismatch\n"); #else SEVCHK(ECA_DEFUNCT, NULL); #endif + return ECA_DEFUNCT; } @@ -2747,11 +2952,21 @@ ca_defunct() * currently implemented as a function * (may be implemented as a MACRO in the future) */ -char -*ca_host_name_function(chix) +#ifdef __STDC__ +char *ca_host_name_function(chid chix) +#else +char *ca_host_name_function(chix) chid chix; +#endif { - return iiu[chix->iocix].host_name_str; + IIU *piiu; + + piiu = chix->piiu; + + if(!piiu){ + return ""; + } + return piiu->host_name_str; } @@ -2763,31 +2978,36 @@ chid chix; * */ #ifdef vxWorks +#ifdef __STDC__ +int ca_channel_status(int tid) +#else int ca_channel_status(tid) int tid; +#endif { - int i; chid chix; + IIU *piiu; struct ca_static *pcas; pcas = (struct ca_static *) - taskVarGet(tid, &ca_static); + taskVarGet(tid, (int *)&ca_static); if (pcas == (struct ca_static *) ERROR) return ECA_NOCACTX; - for (i = 0; i < pcas->ca_nxtiiu; i++) { -# define ca_static pcas - LOCK -# undef ca_static - chix = (chid) &pcas->ca_iiu[i].chidlist.node; +# define ca_static pcas + LOCK +# undef ca_static + piiu = (struct ioc_in_use *) pcas->ca_iiuList.node.next; + while(piiu){ + chix = (chid) &piiu->chidlist.node; while (chix = (chid) chix->node.next){ printf( "%s native type=%d ", ca_name(chix), ca_field_type(chix)); printf( "N elements=%d IOC=%s state=", ca_element_count(chix), - pcas->ca_iiu[i].host_name_str); + piiu->host_name_str); switch(ca_state(chix)){ case cs_never_conn: printf("never connected to an IOC"); @@ -2805,10 +3025,11 @@ int tid; } printf("\n"); } -# define ca_static pcas - UNLOCK -# undef ca_static + piiu = (struct ioc_in_use *)piiu->node.next; } +# define ca_static pcas + UNLOCK +# undef ca_static return ECA_NORMAL; } #endif vxWorks diff --git a/src/ca/acctst.c b/src/ca/acctst.c index b501e116c..c91d5fb83 100644 --- a/src/ca/acctst.c +++ b/src/ca/acctst.c @@ -5,8 +5,8 @@ static char *sccsId = "@(#)acctst.c 1.8\t2/19/93"; */ #if 1 -#define CA_TEST_CHNL "ca:ai_2000" -#define CA_TEST_CHNL4 "ca:ai_2000" +#define CA_TEST_CHNL "fredy" +#define CA_TEST_CHNL4 "fredy" #else #if 0 #define CA_TEST_CHNL "ts2:ai0" @@ -24,6 +24,7 @@ static char *sccsId = "@(#)acctst.c 1.8\t2/19/93"; # if defined(vxWorks) # include # include +# include # endif #endif @@ -42,17 +43,32 @@ static char *sccsId = "@(#)acctst.c 1.8\t2/19/93"; #ifdef vxWorks -spacctst() +int spacctst() { int acctst(); - return taskSpawn("acctst", 200, VX_FP_TASK, 20000, acctst); + return taskSpawn( + "acctst", + 200, + VX_FP_TASK, + 20000, + acctst, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL); } #endif #ifdef vxWorks -acctst() +int acctst() #else main() #endif @@ -77,7 +93,7 @@ main() SEVCHK(ca_task_initialize(), "Unable to initialize"); - ca_printf("begin\n"); + printf("begin\n"); #ifdef VMS lib$init_timer(); #endif @@ -181,13 +197,13 @@ main() SEVCHK(status, NULL); if (INVALID_DB_REQ(chix1->type)) - ca_printf("Failed to locate %s\n", CA_TEST_CHNL); + printf("Failed to locate %s\n", CA_TEST_CHNL); if (INVALID_DB_REQ(chix2->type)) - ca_printf("Failed to locate %s\n", CA_TEST_CHNL); + printf("Failed to locate %s\n", CA_TEST_CHNL); if (INVALID_DB_REQ(chix3->type)) - ca_printf("Failed to locate %s\n", CA_TEST_CHNL); + printf("Failed to locate %s\n", CA_TEST_CHNL); if (INVALID_DB_REQ(chix4->type)) - ca_printf("Failed to locate %s\n", CA_TEST_CHNL4); + printf("Failed to locate %s\n", CA_TEST_CHNL4); /* * SEVCHK(status,NULL); if(status == ECA_TIMEOUT) exit(); */ @@ -198,7 +214,7 @@ main() pfloat = &ptr->value; for (i = 0; i < NUM; i++) - ca_printf("Value Returned from build %f\n", pfloat[i]); + printf("Value Returned from build %f\n", pfloat[i]); #ifdef VMS lib$init_timer(); @@ -208,7 +224,7 @@ main() * verify we dont jam up on many uninterrupted * solicitations */ - ca_printf("Performing multiple get test..."); + printf("Performing multiple get test..."); #ifdef UNIX fflush(stdout); #endif @@ -220,12 +236,12 @@ main() } SEVCHK(ca_pend_io(200.0), NULL); } - ca_printf("done.\n"); + printf("done.\n"); /* * verify we can add many monitors at once */ - ca_printf("Performing multiple monitor test..."); + printf("Performing multiple monitor test..."); #ifdef UNIX fflush(stdout); #endif @@ -255,24 +271,49 @@ main() SEVCHK(ca_get(DBR_FLOAT,chix4,&temp),NULL); SEVCHK(ca_pend_io(100.0),NULL); } - ca_printf("done.\n"); + printf("done.\n"); if (VALID_DB_REQ(chix4->type)) { - status = ca_add_event(DBR_FLOAT, chix4, EVENT_ROUTINE, 0xaaaaaaaa, &monix); + status = ca_add_event( + DBR_FLOAT, + chix4, + EVENT_ROUTINE, + (void *)0xaaaaaaaa, + &monix); SEVCHK(status, NULL); SEVCHK(ca_clear_event(monix), NULL); - status = ca_add_event(DBR_FLOAT, chix4, EVENT_ROUTINE, 0xaaaaaaaa, &monix); + status = ca_add_event( + DBR_FLOAT, + chix4, + EVENT_ROUTINE, + (void *)0xaaaaaaaa, + &monix); SEVCHK(status, NULL); } if (VALID_DB_REQ(chix4->type)) { - status = ca_add_event(DBR_FLOAT, chix4, EVENT_ROUTINE, 0xaaaaaaaa, &monix); + status = ca_add_event( + DBR_FLOAT, + chix4, + EVENT_ROUTINE, + (void *)0xaaaaaaaa, + &monix); SEVCHK(status, NULL); SEVCHK(ca_clear_event(monix), NULL); } if (VALID_DB_REQ(chix3->type)) { - status = ca_add_event(DBR_FLOAT, chix3, EVENT_ROUTINE, 0xaaaaaaaa, &monix); + status = ca_add_event( + DBR_FLOAT, + chix3, + EVENT_ROUTINE, + (void *)0xaaaaaaaa, + &monix); SEVCHK(status, NULL); - status = ca_add_event(DBR_FLOAT, chix3, write_event, 0xaaaaaaaa, &monix); + status = ca_add_event( + DBR_FLOAT, + chix3, + write_event, + (void *)0xaaaaaaaa, + &monix); SEVCHK(status, NULL); } pfloat = (float *) malloc(sizeof(float) * NUM); @@ -285,13 +326,33 @@ main() for (i = 0; i < NUM; i++) { for (j = 0; j < NUM; j++) sprintf(&pstring[j][0], "%d", j + 100); - SEVCHK(ca_array_put(DBR_STRING, NUM, chix1, pstring), NULL) - SEVCHK(ca_array_get(DBR_FLOAT, NUM, chix1, pfloat), NULL) - SEVCHK(ca_array_get(DBR_DOUBLE, NUM, chix1, pdouble), NULL) - SEVCHK(ca_array_get(DBR_GR_FLOAT, NUM, chix1, pgrfloat), NULL) + SEVCHK(ca_array_put( + DBR_STRING, + NUM, + chix1, + pstring), + NULL) + SEVCHK(ca_array_get( + DBR_FLOAT, + NUM, + chix1, + pfloat), + NULL) + SEVCHK(ca_array_get( + DBR_DOUBLE, + NUM, + chix1, + pdouble), + NULL) + SEVCHK(ca_array_get( + DBR_GR_FLOAT, + NUM, + chix1, + pgrfloat), + NULL) } else - abort(); + abort(0); SEVCHK(ca_pend_io(4.0), NULL); @@ -299,15 +360,15 @@ main() lib$show_timer(); #endif for (i = 0; i < NUM; i++) { - ca_printf("Float value Returned from put/get %f\n", pfloat[i]); - ca_printf("Double value Returned from put/get %f\n", pdouble[i]); - ca_printf("GR Float value Returned from put/get %f\n", pgrfloat[i].value); + printf("Float value Returned from put/get %f\n", pfloat[i]); + printf("Double value Returned from put/get %f\n", pdouble[i]); + printf("GR Float value Returned from put/get %f\n", pgrfloat[i].value); } for (i = 0; i < 10; i++) ca_get_callback(DBR_GR_FLOAT, chix1, ca_test_event, NULL); - ca_printf("-- Put/Gets done- waiting for Events --\n"); + printf("-- Put/Gets done- waiting for Events --\n"); status = ca_pend_event(60.0); if (status == ECA_TIMEOUT) { @@ -315,10 +376,11 @@ main() free(pfloat); free(pgrfloat); - exit(); + exit(0); } else SEVCHK(status, NULL); + return(0); } @@ -331,7 +393,7 @@ null_event() static int i; if (i++ > 1000) { - ca_printf("1000 occured\n"); + printf("1000 occured\n"); i = 0; } } @@ -359,9 +421,9 @@ conn(args) { if (args.op == CA_OP_CONN_UP) - ca_printf("Channel On Line [%s]\n", ca_name(args.chid)); + printf("Channel On Line [%s]\n", ca_name(args.chid)); else if (args.op == CA_OP_CONN_DOWN) - ca_printf("Channel Off Line [%s]\n", ca_name(args.chid)); + printf("Channel Off Line [%s]\n", ca_name(args.chid)); else - ca_printf("Ukn conn ev\n"); + printf("Ukn conn ev\n"); } diff --git a/src/ca/ca_printf.c b/src/ca/ca_printf.c index c75b27caf..ba75c6f64 100644 --- a/src/ca/ca_printf.c +++ b/src/ca/ca_printf.c @@ -1,13 +1,52 @@ -static char *sccsId = "@(#)ca_printf.c 1.2\t7/27/92"; +/************************************************************************/ +/* */ +/* L O S A L A M O S */ +/* Los Alamos National Laboratory */ +/* Los Alamos, New Mexico 87545 */ +/* */ +/* Copyright, 1986, The Regents of the University of California. */ +/* */ +/* Author */ +/* ------ */ +/* Jeff Hill */ +/* */ +/* History */ +/* ------- */ +/* */ +/*_begin */ +/************************************************************************/ +/* */ +/* Title: channel access TCPIP interface include file */ +/* File: ca_printf.c */ +/* Environment: VMS, UNIX, VRTX */ +/* */ +/* */ +/* Purpose */ +/* ------- */ +/* */ +/* */ +/* */ +/* Special comments */ +/* ------- -------- */ +/* */ +/************************************************************************/ +/*_end */ + +static char *sccsId = "$Id$"; #if defined(UNIX) || defined(VMS) # include #else # if defined(vxWorks) # include +# include # endif #endif +#ifdef __STDC__ +#include +#else #include +#endif /* @@ -18,17 +57,26 @@ static char *sccsId = "@(#)ca_printf.c 1.2\t7/27/92"; * Dump error messages to the appropriate place * */ -int -ca_printf(va_alist) +#ifdef __STDC__ +int ca_printf(char *pformat, ...) +#else +int ca_printf(va_alist) va_dcl +#endif { va_list args; - char *pformat; int status; +#ifndef __STDC__ + char *pformat; +#endif +#ifdef __STDC__ + va_start(args, pformat); +#else va_start(args); - pformat = va_arg(args, char *); +#endif + #if defined(UNIX) || defined(VMS) { @@ -54,8 +102,7 @@ va_dcl logMsgArgs[2], logMsgArgs[3], logMsgArgs[4], - logMsgArgs[5], - logMsgArgs[6]); + logMsgArgs[5]); } # else diff --git a/src/ca/conn.c b/src/ca/conn.c index 1934aad10..8846d441e 100644 --- a/src/ca/conn.c +++ b/src/ca/conn.c @@ -22,6 +22,8 @@ /* .08 010493 joh removed `' message */ /* .09 090293 joh removed flush from manage_conn */ /* (now handled by the send needed flag) */ +/* .10 102093 joh improved broadcast schedualing for */ +/* reconnects */ /* */ /*_begin */ /************************************************************************/ @@ -44,7 +46,11 @@ static char *sccsId = "$Id$\t$Date$"; # if defined(VMS) # else # if defined(vxWorks) -#include +#include +#include +#include +#include +#include # else @@@@ dont compile @@@@ # endif @@ -56,6 +62,7 @@ static char *sccsId = "$Id$\t$Date$"; #include #include + /* * @@ -67,79 +74,81 @@ static char *sccsId = "$Id$\t$Date$"; * NOTES: * Lock must be applied while in this routine */ +#ifdef __STDC__ +void manage_conn(int silent) +#else void manage_conn(silent) -char silent; +int silent; +#endif { - register chid chix; - register unsigned int retry_cnt = 0; - register unsigned int keepalive_cnt = 0; + struct ioc_in_use *piiu; + chid chix; + unsigned int retry_cnt = 0; + unsigned int keepalive_cnt = 0; unsigned int retry_cnt_no_handler = 0; ca_time current; - int i; current = time(NULL); - for(i=0; i< nxtiiu; i++){ - int search_type; + /* + * issue connection heartbeat + */ + for( piiu = (struct ioc_in_use *) iiuList.node.next; + piiu; + piiu = (struct ioc_in_use *) piiu->node.next){ - if(iiu[i].next_retry == CA_CURRENT_TIME){ - if(!iiu[i].conn_up || i==BROADCAST_IIU){ - iiu[i].next_retry = - current + iiu[i].retry_delay; - } - else{ - iiu[i].next_retry = - current + CA_RETRY_PERIOD; - } + if(piiu == piiuCast || !piiu->conn_up){ continue; } - if(iiu[i].next_retry > current) + if(piiu->next_retry == CA_CURRENT_TIME){ + piiu->next_retry = current + CA_RETRY_PERIOD; + continue; + } + + if(piiu->next_retry > current) continue; /* * periodic keepalive on unused channels */ - if(i != BROADCAST_IIU && iiu[i].conn_up){ - /* - * reset of delay to the next keepalive - * occurs when the message is sent - */ - noop_msg(&iiu[i]); - keepalive_cnt++; + /* + * reset of delay to the next keepalive + * occurs when the message is sent + */ + noop_msg(piiu); + keepalive_cnt++; + } - /* - * allow execution to continue through - * the connection retry code below - * since we may be connected while - * some channels which have not been - * verified to exist on the recently - * booted IOC. - */ + if(!piiuCast){ + return; + } + + if(piiuCast->next_retry == CA_CURRENT_TIME){ + piiuCast->next_retry = current + piiuCast->retry_delay; + } + + if(piiuCast->next_retry > current) + return; + + if(piiuCast->nconn_tries++ > MAXCONNTRIES) + return; + + piiuCast->retry_delay += piiuCast->retry_delay; + piiuCast->next_retry = current + piiuCast->retry_delay; + + chix = (chid) &piiuCast->chidlist.node.next; + while(chix = (chid) chix->node.next){ + build_msg(chix, DONTREPLY); + retry_cnt++; + + if(!(silent || chix->connection_func)){ + ca_signal(ECA_CHIDNOTFND, (char *)(chix+1)); + retry_cnt_no_handler++; } - - if(iiu[i].nconn_tries++ > MAXCONNTRIES) - continue; - - iiu[i].retry_delay += iiu[i].retry_delay; - iiu[i].next_retry = current + iiu[i].retry_delay; - - search_type = (i==BROADCAST_IIU? DONTREPLY: DOREPLY); - - chix = (chid) &iiu[i].chidlist; - while(chix = (chid) chix->node.next){ - if(chix->type != TYPENOTCONN) - continue; - build_msg(chix,search_type); - retry_cnt++; - - if(!(silent || chix->connection_func)){ - ca_signal(ECA_CHIDNOTFND, (char *)(chix+1)); - retry_cnt_no_handler++; - } - } - } + } + if(retry_cnt){ #ifdef TRYING_MESSAGE @@ -168,12 +177,14 @@ char silent; * Lock must be applied while in this routine * */ -void -mark_server_available(pnet_addr) +#ifdef __STDC__ +void mark_server_available(struct in_addr *pnet_addr) +#else +void mark_server_available(pnet_addr) struct in_addr *pnet_addr; +#endif { unsigned port; - int i; /* * if timers have expired take care of them @@ -188,43 +199,17 @@ struct in_addr *pnet_addr; #endif #endif - for(i=0;is_addr == - iiu[i].sock_addr.sin_addr.s_addr)){ - - if(iiu[i].conn_up){ - /* - * Check if the conn is down but TCP - * has not informed me by sending a NULL msg - */ - noop_msg(&iiu[i]); - cac_send_msg(); - } - else{ - /* - * reset the delay to the next retry - */ - iiu[i].next_retry = CA_CURRENT_TIME; - iiu[i].nconn_tries = 0; - iiu[i].retry_delay = CA_RECAST_DELAY; - manage_conn(TRUE); - } - return; - } + if(!piiuCast){ + return; + } /* * never connected to this IOC before * * We end up here when the client starts before the server * - * It would be best if this used a directed UDP - * reply rather than a broadcast */ - /* - * reset the retry cnt - */ - iiu[BROADCAST_IIU].nconn_tries = 0; /* * This part is very important since many machines @@ -243,11 +228,11 @@ struct in_addr *pnet_addr; int status; status = getsockname( - iiu[BROADCAST_IIU].sock_chan, - &saddr, + piiuCast->sock_chan, + (struct sockaddr *)&saddr, &saddr_length); if(status<0) - abort(); + abort(0); port = saddr.sin_port; } @@ -256,17 +241,25 @@ struct in_addr *pnet_addr; int next; delay = (port&CA_RECAST_PORT_MASK) + CA_RECAST_PERIOD; - iiu[BROADCAST_IIU].retry_delay = - min(iiu[BROADCAST_IIU].retry_delay, delay); - next = time(NULL) + iiu[BROADCAST_IIU].retry_delay; - iiu[BROADCAST_IIU].next_retry = - min(next, iiu[BROADCAST_IIU].next_retry); + next = time(NULL) + delay; + + /* + * next retry time most likely + * invalid in this case + */ + if(piiuCast->nconn_tries >= MAXCONNTRIES || + next < piiuCast->next_retry){ + piiuCast->next_retry = next; + piiuCast->retry_delay = CA_RECAST_DELAY; + } + + piiuCast->nconn_tries = 0; } #ifdef DEBUG ca_printf("CAC: ", - iiu[BROADCAST_IIU].retry_delay); + piiuCast->retry_delay); #ifdef UNIX fflush(stdout); #endif diff --git a/src/ca/convert.c b/src/ca/convert.c index 0130a9818..0b5181f90 100644 --- a/src/ca/convert.c +++ b/src/ca/convert.c @@ -37,6 +37,7 @@ static char *sccsId = "@(#)convert.c 1.5\t7/27/92"; # define memset(D,V,N) bfill(D,N,V) #endif +static void no_cvrt(); /* * Routine we will do later @@ -44,7 +45,7 @@ static char *sccsId = "@(#)convert.c 1.5\t7/27/92"; * * */ -no_cvrt() +static void no_cvrt() { ca_printf("Sorry, conversion for that type currently not implemented\n"); exit(); @@ -83,11 +84,20 @@ cvrt_ctrl_double() {no_cvrt();} * * */ +#ifdef __STDC__ +cvrt_short( +short *s, /* source */ +short *d, /* destination */ +int encode, /* cvrt VAX to IEEE if T */ +int num /* number of values */ +) +#else cvrt_short(s,d,encode,num) -short *s; /* source */ -short *d; /* destination */ -int encode; /* cvrt VAX to IEEE if T */ -int num; /* number of values */ +short *s; /* source */ +short *d; /* destination */ +int encode; /* cvrt VAX to IEEE if T */ +int num; /* number of values */ +#endif { unsigned int i; @@ -105,11 +115,20 @@ int num; /* number of values */ * * */ -cvrt_char(s,d,encode,num) -char *s; /* source */ -char *d; /* destination */ -int encode; /* cvrt VAX to IEEE if T */ -int num; /* number of values */ +#ifdef __STDC__ +int cvrt_char( +char *s; /* source */ +char *d; /* destination */ +int encode; /* cvrt VAX to IEEE if T */ +int num; /* number of values */ +) +#else +int cvrt_char( +char *s, /* source */ +char *d, /* destination */ +int encode, /* cvrt VAX to IEEE if T */ +int num /* number of values */ +#endif { unsigned int i; @@ -127,11 +146,20 @@ int num; /* number of values */ * * */ -cvrt_long(s,d,encode,num) -long *s; /* source */ -long *d; /* destination */ -int encode; /* cvrt VAX to IEEE if T */ -int num; /* number of values */ +#ifdef __STDC__ +int cvrt_long( +long *s, /* source */ +long *d, /* destination */ +int encode, /* cvrt VAX to IEEE if T */ +int num /* number of values */ +) +#else +int cvrt_long(s,d,encode,num) +long *s; /* source */ +long *d; /* destination */ +int encode; /* cvrt VAX to IEEE if T */ +int num; /* number of values */ +#endif { unsigned int i; @@ -149,11 +177,20 @@ int num; /* number of values */ * * */ -cvrt_enum(s,d,encode,num) -short *s; /* source */ -short *d; /* destination */ -int encode; /* cvrt VAX to IEEE if T */ -int num; /* number of values */ +#ifdef __STDC__ +int cvrt_enum( +short *s, /* source */ +short *d, /* destination */ +int encode, /* cvrt VAX to IEEE if T */ +int num /* number of values */ +) +#else +int cvrt_enum(s,d,encode,num) +short *s; /* source */ +short *d; /* destination */ +int encode; /* cvrt VAX to IEEE if T */ +int num; /* number of values */ +#endif { unsigned int i; @@ -173,11 +210,19 @@ int num; /* number of values */ * code but better performance. * */ -cvrt_float(s,d,encode,num) +#ifdef __STDC__ +int cvrt_float( +float *s, /* source */ +float *d, /* destination */ +int encode, /* cvrt VAX to IEEE if T*/ +int num /* number of values */ +#else +int cvrt_float(s,d,encode,num) float *s; /* source */ float *d; /* destination */ int encode; /* cvrt VAX to IEEE if T*/ int num; /* number of values */ +#endif { unsigned int i; @@ -206,11 +251,20 @@ int num; /* number of values */ * * */ -cvrt_double(s,d,encode,num) -double *s; /* source */ -double *d; /* destination */ -int encode; /* cvrt VAX to IEEE if T */ -int num; /* number of values */ +#ifdef __STDC__ +int cvrt_double( +double *s, /* source */ +double *d, /* destination */ +int encode, /* cvrt VAX to IEEE if T */ +int num /* number of values */ +) +#else +int cvrt_double(s,d,encode,num) +double *s; /* source */ +double *d; /* destination */ +int encode; /* cvrt VAX to IEEE if T */ +int num; /* number of values */ +#endif { unsigned int i; @@ -231,11 +285,20 @@ int num; /* number of values */ * * */ -cvrt_string(s,d,encode,num) -char *s; /* source */ -char *d; /* destination */ -int encode; /* cvrt VAX to IEEE if T */ -int num; /* number of values */ +#ifdef __STDC__ +int cvrt_string( +char *s, /* source */ +char *d, /* destination */ +int encode, /* cvrt VAX to IEEE if T */ +int num /* number of values */ +) +#else +int cvrt_string(s,d,encode,num) +char *s; /* source */ +char *d; /* destination */ +int encode; /* cvrt VAX to IEEE if T */ +int num; /* number of values */ +#endif { unsigned int i; @@ -264,11 +327,20 @@ int num; /* number of values */ ** format; ****************************************************************************/ +#ifdef __STDC__ +cvrt_sts_string( +struct dbr_sts_string *s, /* source */ +struct dbr_sts_string *d, /* destination */ +int encode, /* do VAX to IEEE */ +int num /* number of values */ +) +#else cvrt_sts_string(s,d,encode,num) struct dbr_sts_string *s; /* source */ struct dbr_sts_string *d; /* destination */ int encode; /* do VAX to IEEE */ int num; /* number of values */ +#endif { /* convert ieee to vax format or vax to ieee */ @@ -296,11 +368,20 @@ int num; /* number of values */ ** format ****************************************************************************/ +#ifdef __STDC__ +cvrt_sts_short( +struct dbr_sts_int *s, /* source */ +struct dbr_sts_int *d, /* destination */ +int encode, /* if true; vax to ieee */ +int num /* number of values */ +) +#else cvrt_sts_short(s,d,encode,num) struct dbr_sts_int *s; /* source */ struct dbr_sts_int *d; /* destination */ int encode; /* if true, vax to ieee */ int num; /* number of values */ +#endif { register i; short *sval_ptr,*dval_ptr; /* ptrs to source, destination */ @@ -343,11 +424,20 @@ int num; /* number of values */ ** format; ****************************************************************************/ +#ifdef __STDC__ +cvrt_sts_float( +struct dbr_sts_float *s, /* source */ +struct dbr_sts_float *d, /* destination */ +int encode, /* it true, vax to ieee */ +int num /* number of values */ +) +#else cvrt_sts_float(s,d,encode,num) struct dbr_sts_float *s; /* source */ struct dbr_sts_float *d; /* destination */ int encode; /* it true, vax to ieee */ int num; /* number of values */ +#endif { register i; float *sval_ptr,*dval_ptr; @@ -446,11 +536,20 @@ int num; /* number of values */ ** ****************************************************************************/ -cvrt_gr_short(s,d,encode,num) +#ifdef __STDC__ +int cvrt_gr_short( +struct dbr_gr_int *s, /* source */ +struct dbr_gr_int *d, /* destination */ +int encode, /* if true, vax to ieee */ +int num /* number of values */ +) +#else +int cvrt_gr_short(s,d,encode,num) struct dbr_gr_int *s; /* source */ struct dbr_gr_int *d; /* destination */ int encode; /* if true, vax to ieee */ int num; /* number of values */ +#endif { register i; short *sval_ptr,*dval_ptr; @@ -499,11 +598,20 @@ int num; /* number of values */ ** format; ****************************************************************************/ -cvrt_gr_float(s,d,encode,num) +#ifdef __STDC__ +int cvrt_gr_float( +struct dbr_gr_float *s, /* source */ +struct dbr_gr_float *d, /* destination */ +int encode, /* if true, vax to ieee */ +int num /* number of values */ +) +#else +int cvrt_gr_float(s,d,encode,num) struct dbr_gr_float *s; /* source */ struct dbr_gr_float *d; /* destination */ int encode; /* if true, vax to ieee */ int num; /* number of values */ +#endif { register i; float *sval_ptr,*dval_ptr; @@ -577,11 +685,20 @@ int num; /* number of values */ ** ****************************************************************************/ -cvrt_ctrl_short(s,d,encode,num) +#ifdef __STDC__ +int cvrt_ctrl_short( +struct dbr_ctrl_int *s, /* source */ +struct dbr_ctrl_int *d, /* destination */ +int encode, /* if true, vax to ieee */ +int num /* number of values */ +) +#else +int cvrt_ctrl_short(s,d,encode,num) struct dbr_ctrl_int *s; /* source */ struct dbr_ctrl_int *d; /* destination */ int encode; /* if true, vax to ieee */ int num; /* number of values */ +#endif { register i; short *sval_ptr,*dval_ptr; @@ -633,11 +750,20 @@ int num; /* number of values */ ** format; ****************************************************************************/ -cvrt_ctrl_float(s,d,encode,num) +#ifdef __STDC__ +int cvrt_ctrl_float( +struct dbr_ctrl_float *s, /* source */ +struct dbr_ctrl_float *d, /* destination */ +int encode, /* if true, vax to ieee */ +int num /* number of values */ +) +#else +int cvrt_ctrl_float(s,d,encode,num) struct dbr_ctrl_float *s; /* source */ struct dbr_ctrl_float *d; /* destination */ int encode; /* if true, vax to ieee */ int num; /* number of values */ +#endif { register i; float *sval_ptr,*dval_ptr; @@ -712,11 +838,20 @@ int num; /* number of values */ ** format; ****************************************************************************/ +#ifdef __STDC__ +cvrt_ctrl_enum( +struct dbr_ctrl_enum *s, /* source */ +struct dbr_ctrl_enum *d, /* destination */ +int encode, /* if true, vax to ieee */ +int num /* number of values */ +) +#else cvrt_ctrl_enum(s,d,encode,num) struct dbr_ctrl_enum *s; /* source */ struct dbr_ctrl_enum *d; /* destination */ int encode; /* if true, vax to ieee */ int num; /* number of values */ +#endif { register i; short *sval_ptr,*dval_ptr; diff --git a/src/ca/flow_control.c b/src/ca/flow_control.c index bbe9d0218..311ce4dc5 100644 --- a/src/ca/flow_control.c +++ b/src/ca/flow_control.c @@ -33,7 +33,7 @@ /************************************************************************/ /*_end */ -static char *sccsId = "@(#)flow_control.c 1.7\t6/2/93"; +static char *sccsId = "$Id$"; #if defined(vxWorks) # include @@ -75,9 +75,12 @@ static char *sccsId = "@(#)flow_control.c 1.7\t6/2/93"; * suppress monitors if we are behind * (an update is sent when we catch up) */ -void -flow_control(piiu) - struct ioc_in_use *piiu; +#ifdef __STDC__ +void flow_control(struct ioc_in_use *piiu) +#else +void flow_control(piiu) +struct ioc_in_use *piiu; +#endif { unsigned nbytes; register int status; @@ -89,9 +92,11 @@ flow_control(piiu) */ status = socket_ioctl(piiu->sock_chan, FIONREAD, - &nbytes); + (int)&nbytes); if (status < 0) { + LOCK; close_ioc(piiu); + UNLOCK; return; } diff --git a/src/ca/iocinf.c b/src/ca/iocinf.c index e3513fbda..b67086d66 100644 --- a/src/ca/iocinf.c +++ b/src/ca/iocinf.c @@ -90,6 +90,7 @@ static char *sccsId = "$Id$\t$Date$"; # endif #else # if defined(UNIX) +# include # include # include # include @@ -103,14 +104,26 @@ static char *sccsId = "$Id$\t$Date$"; # include # include # include +# include +# include +# include +# include +# include # include -# include +# include # include # include +# include +# include +# include +# include # endif # endif #endif +#ifdef vxWorks +#include +#endif #include #include #include @@ -118,15 +131,39 @@ static char *sccsId = "$Id$\t$Date$"; static struct timeval notimeout = {0,0}; -void close_ioc(); -static void recv_msg(); -static void tcp_recv_msg(); -static void udp_recv_msg(); -static void notify_ca_repeater(); -static void cac_flush_internal(); -static int cac_send_msg_piiu(); +#ifdef __STDC__ +LOCAL void tcp_recv_msg(struct ioc_in_use *piiu); +LOCAL void cac_flush_internal(); +LOCAL int cac_send_msg_piiu(struct ioc_in_use *piiu); +LOCAL void notify_ca_repeater(); +LOCAL void recv_msg(struct ioc_in_use *piiu); +LOCAL void udp_recv_msg(struct ioc_in_use *piiu); +LOCAL void clean_iiu_list(); #ifdef VMS -void vms_recv_msg_ast(); +LOCAL void vms_recv_msg_ast(struct ioc_in_use *piiu); +#endif + +LOCAL int +create_net_chan( +struct ioc_in_use **ppiiu, +struct in_addr *pnet_addr, +int net_proto +); + +#else + +LOCAL void tcp_recv_msg(); +LOCAL void cac_flush_internal(); +LOCAL int cac_send_msg_piiu(); +LOCAL void notify_ca_repeater(); +LOCAL void recv_msg(); +LOCAL void udp_recv_msg(); +#ifdef VMS +void vms_recv_msg_ast(); +#endif +LOCAL int create_net_chan(); +LOCAL void clean_iiu_list(); + #endif @@ -147,49 +184,46 @@ void vms_recv_msg_ast(); * * LOCK should be on while in this routine */ -alloc_ioc(pnet_addr, net_proto, iocix) +#ifdef __STDC__ +int alloc_ioc( +struct in_addr *pnet_addr, +int net_proto, +struct ioc_in_use **ppiiu +) +#else +int alloc_ioc(pnet_addr, net_proto, ppiiu) struct in_addr *pnet_addr; int net_proto; -unsigned short *iocix; +struct ioc_in_use **ppiiu; +#endif { - int i; + struct ioc_in_use *piiu; int status; - /****************************************************************/ - /* IOC allready allocated ? */ - /****************************************************************/ - for(i=0;is_addr == iiu[i].sock_addr.sin_addr.s_addr) - && (net_proto == iiu[i].sock_proto)){ + /* + * look for an existing connection + * + * quite a bottle neck with increasing connection count + * + */ + for( piiu = (struct ioc_in_use *) iiuList.node.next; + piiu; + piiu = (struct ioc_in_use *) piiu->node.next){ - if(!iiu[i].conn_up){ - /* an old connection is resumed */ - status = create_net_chan(&iiu[i]); - if(status != ECA_NORMAL) - return status; - ca_signal( - ECA_NEWCONN, - iiu[i].host_name_str); - } + if( (pnet_addr->s_addr == piiu->sock_addr.sin_addr.s_addr) + && (net_proto == piiu->sock_proto)){ - *iocix = i; - return ECA_NORMAL; + if(!piiu->conn_up){ + continue; + } + + *ppiiu = piiu; + return ECA_NORMAL; + } } - /* is there an IOC In Use block available to allocate */ - if(nxtiiu>=MAXIIU) - return ECA_MAXIOC; - - /* set network address block */ - iiu[nxtiiu].sock_addr.sin_addr = *pnet_addr; - iiu[nxtiiu].sock_proto = net_proto; - status = create_net_chan(&iiu[nxtiiu]); - if(status != ECA_NORMAL) - return status; - - *iocix = nxtiiu++; - - return ECA_NORMAL; + status = create_net_chan(ppiiu, pnet_addr, net_proto); + return status; } @@ -199,16 +233,34 @@ unsigned short *iocix; * * LOCK should be on while in this routine */ -static int -create_net_chan(piiu) -struct ioc_in_use *piiu; +#ifdef __STDC__ +LOCAL int create_net_chan( +struct ioc_in_use **ppiiu, +struct in_addr *pnet_addr, +int net_proto +) +#else +LOCAL int create_net_chan(ppiiu, pnet_addr, net_proto) +struct ioc_in_use **ppiiu; +struct in_addr *pnet_addr; +int net_proto; +#endif { + struct ioc_in_use *piiu; int status; int sock; int true = TRUE; struct sockaddr_in saddr; int i; + piiu = (IIU *) calloc(1, sizeof(*piiu)); + if(!piiu){ + return ECA_ALLOCMEM; + } + + piiu->sock_addr.sin_addr = *pnet_addr; + piiu->sock_proto = net_proto; + /* set socket domain */ piiu->sock_addr.sin_family = AF_INET; @@ -230,8 +282,10 @@ struct ioc_in_use *piiu; sock = socket( AF_INET, /* domain */ SOCK_STREAM, /* type */ 0); /* deflt proto */ - if(sock == ERROR) + if(sock == ERROR){ + free(piiu); return ECA_SOCK; + } piiu->sock_chan = sock; @@ -243,9 +297,10 @@ struct ioc_in_use *piiu; sock, IPPROTO_TCP, TCP_NODELAY, - &true, + (char *)&true, sizeof true); if(status < 0){ + free(piiu); status = socket_close(sock); if(status<0){ SEVCHK(ECA_INTERNAL,NULL); @@ -263,9 +318,10 @@ struct ioc_in_use *piiu; sock, SOL_SOCKET, SO_KEEPALIVE, - &true, + (char *)&true, sizeof true); if(status < 0){ + free(piiu); status = socket_close(sock); if(status<0){ SEVCHK(ECA_INTERNAL,NULL); @@ -284,7 +340,7 @@ struct ioc_in_use *piiu; &linger, &linger_size); if(status < 0){ - abort(); + abort(0); } ca_printf( "CAC: linger was on:%d linger:%d\n", linger.l_onoff, @@ -302,6 +358,7 @@ struct ioc_in_use *piiu; &i, sizeof(i)); if(status < 0){ + free(piiu); status = socket_close(sock); if(status<0){ SEVCHK(ECA_INTERNAL,NULL); @@ -316,6 +373,7 @@ struct ioc_in_use *piiu; &i, sizeof(i)); if(status < 0){ + free(piiu); status = socket_close(sock); if(status<0){ SEVCHK(ECA_INTERNAL,NULL); @@ -330,9 +388,10 @@ struct ioc_in_use *piiu; sock, SOL_SOCKET, SO_SNDBUF, - &piiu->tcp_send_buff_size, + (char *)&piiu->tcp_send_buff_size, &i); if(status < 0 || i != sizeof(piiu->tcp_send_buff_size)){ + free(piiu); status = socket_close(sock); if(status<0){ SEVCHK(ECA_INTERNAL,NULL); @@ -343,7 +402,7 @@ struct ioc_in_use *piiu; /* connect */ status = connect( sock, - &piiu->sock_addr, + (struct sockaddr *)&piiu->sock_addr, sizeof(piiu->sock_addr)); if(status < 0){ ca_printf("CAC: no conn errno %d\n", MYERRNO); @@ -351,6 +410,7 @@ struct ioc_in_use *piiu; if(status<0){ SEVCHK(ECA_INTERNAL,NULL); } + free(piiu); return ECA_CONN; } piiu->max_msg = MAX_TCP; @@ -372,7 +432,6 @@ struct ioc_in_use *piiu; */ { char *ptmpstr; - int len; ptmpstr = host_from_addr(&piiu->sock_addr.sin_addr); strncpy( @@ -388,8 +447,10 @@ struct ioc_in_use *piiu; sock = socket( AF_INET, /* domain */ SOCK_DGRAM, /* type */ 0); /* deflt proto */ - if(sock == ERROR) + if(sock == ERROR){ + free (piiu); return ECA_SOCK; + } piiu->sock_chan = sock; @@ -401,9 +462,10 @@ struct ioc_in_use *piiu; sock, SOL_SOCKET, SO_BROADCAST, - &true, + (char *)&true, sizeof(true)); if(status<0){ + free(piiu); ca_printf("CAC: sso (errno=%d)\n",MYERRNO); status = socket_close(sock); if(status < 0){ @@ -412,7 +474,7 @@ struct ioc_in_use *piiu; return ECA_CONN; } - memset(&saddr,0,sizeof(saddr)); + memset((char *)&saddr,0,sizeof(saddr)); saddr.sin_family = AF_INET; /* * let slib pick lcl addr @@ -435,10 +497,6 @@ struct ioc_in_use *piiu; * future. */ { - char *ptmpstr; - int len; - - ptmpstr = host_from_addr(&piiu->sock_addr.sin_addr); strncpy( piiu->host_name_str, "<>", @@ -448,6 +506,7 @@ struct ioc_in_use *piiu; break; default: + free(piiu); ca_signal(ECA_INTERNAL,"alloc_ioc: ukn protocol\n"); /* * turn off gcc warnings @@ -463,6 +522,7 @@ struct ioc_in_use *piiu; if(status < 0){ SEVCHK(ECA_INTERNAL,NULL); } + free(piiu); return ECA_ALLOCMEM; } } @@ -476,13 +536,13 @@ struct ioc_in_use *piiu; if(status < 0){ SEVCHK(ECA_INTERNAL,NULL); } + free(piiu); return ECA_ALLOCMEM; } } piiu->send_retry_count = SEND_RETRY_COUNT_INIT; piiu->recv->stk = 0; - piiu->conn_up = TRUE; piiu->active = FALSE; if(fd_register_func){ LOCKEVENTS; @@ -515,40 +575,16 @@ struct ioc_in_use *piiu; exit(); } } -#else -# if defined(vxWorks) - { - static void recv_task(); - int pri; - char name[15]; - - status == taskPriorityGet(VXTASKIDSELF, &pri); - if(status<0) - ca_signal(ECA_INTERNAL,NULL); - - strcpy(name,"RD "); - strncat( - name, - taskName(VXTHISTASKID), - sizeof(name)-strlen(name)-1); - - status = taskSpawn( - name, - pri-1, - VX_FP_TASK, - 4096, - recv_task, - piiu, - taskIdSelf()); - if(status<0) - ca_signal(ECA_INTERNAL,NULL); - - piiu->recv_tid = status; - - } -# endif #endif + /* + * add to the list of active IOCs + */ + ellAdd(&iiuList, &piiu->node); + + piiu->conn_up = TRUE; + *ppiiu = piiu; + return ECA_NORMAL; } @@ -565,24 +601,25 @@ struct ioc_in_use *piiu; * LOCK should be on while in this routine * (MULTINET TCP/IP routines are not reentrant) */ -static void -notify_ca_repeater() +LOCAL void notify_ca_repeater() { struct sockaddr_in saddr; int status; - if(!iiu[BROADCAST_IIU].conn_up) + if(!piiuCast) + return; + if(!piiuCast->conn_up) return; - status = local_addr(iiu[BROADCAST_IIU].sock_chan, &saddr); + status = local_addr(piiuCast->sock_chan, &saddr); if(status == OK){ saddr.sin_port = htons(CA_CLIENT_PORT); status = sendto( - iiu[BROADCAST_IIU].sock_chan, + piiuCast->sock_chan, NULL, 0, /* zero length message */ 0, - &saddr, + (struct sockaddr *)&saddr, sizeof saddr); if(status < 0){ if( MYERRNO == EINTR || @@ -593,7 +630,7 @@ notify_ca_repeater() else{ ca_printf( "CAC: notify_ca_repeater: send to lcl addr failed\n"); - abort(); + abort(0); } } } @@ -612,22 +649,16 @@ void cac_send_msg() int done; int status; - for(piiu=iiu; piiu<&iiu[nxtiiu]; piiu++){ + for( piiu=(IIU *)iiuList.node.next; + piiu; + piiu=(IIU *)piiu->node.next){ + piiu->send_retry_count = SEND_RETRY_COUNT_INIT; } if(!ca_static->ca_repeater_contacted) notify_ca_repeater(); -#if 0 - /* - * dont call it recursively - */ - if(send_msg_active){ - return; - } -#endif - send_msg_active++; /* @@ -649,9 +680,11 @@ void cac_send_msg() # endif done = TRUE; - for(piiu=iiu; piiu<&iiu[nxtiiu]; piiu++){ + for( piiu=(IIU *)iiuList.node.next; + piiu; + piiu=(IIU *)piiu->node.next){ - if(!piiu->send->stk) + if(!piiu->send->stk || !piiu->conn_up) continue; status = cac_send_msg_piiu(piiu); @@ -676,8 +709,11 @@ void cac_send_msg() * to a send buffer and a recursive * ca_send_msg() call was refused above */ - for(piiu=iiu;piiu<&iiu[nxtiiu];piiu++){ - if(piiu->send->stk){ + for( piiu=(IIU *)iiuList.node.next; + piiu; + piiu=(IIU *)piiu->node.next){ + + if(piiu->send->stk && piiu->conn_up){ done = FALSE; } } @@ -697,48 +733,28 @@ void cac_send_msg() * * */ -static int -cac_send_msg_piiu(piiu) -register struct ioc_in_use *piiu; +#ifdef __STDC__ +LOCAL int cac_send_msg_piiu(struct ioc_in_use *piiu) +#else +LOCAL int cac_send_msg_piiu(piiu) +struct ioc_in_use *piiu; +#endif { unsigned cnt; void *pmsg; int status; - struct ioc_in_use *piiu_socket; cnt = piiu->send->stk; pmsg = (void *) piiu->send->buf; while(TRUE){ - if(piiu->conn_up){ - /* - * use TCP if connection exists - */ - piiu_socket = piiu; - } - else{ - /* - * use UDP - * - * NOTE: this does not use a broadcast - * if the location of the channel is - * known from a previous connection. - * - * (piiu->sock_addr points to the - * known address) - */ - if(!iiu[BROADCAST_IIU].conn_up) - return ERROR; - - piiu_socket = &iiu[BROADCAST_IIU]; - } status = sendto( - piiu_socket->sock_chan, + piiu->sock_chan, pmsg, cnt, 0, - &piiu->sock_addr, + (struct sockaddr *)&piiu->sock_addr, sizeof(piiu->sock_addr)); /* @@ -758,7 +774,7 @@ register struct ioc_in_use *piiu; pmsg = (void *) (status+(char *)pmsg); } else if(status == 0){ -ca_printf("CAC: sent zero ?\n"); + ca_printf("CAC: sent zero ?\n"); TCPDELAY; } else if(MYERRNO == EWOULDBLOCK || @@ -785,7 +801,7 @@ ca_printf("CAC: sent zero ?\n"); "CAC: error on socket send() %d\n", MYERRNO); } - close_ioc(piiu_socket); + close_ioc(piiu); return OK; } @@ -799,7 +815,7 @@ ca_printf("CAC: sent zero ?\n"); /* * reset the delay to the next keepalive */ - if(piiu != &iiu[BROADCAST_IIU] && piiu->conn_up){ + if(piiu != piiuCast){ piiu->next_retry = time(NULL) + CA_RETRY_PERIOD; } @@ -814,14 +830,16 @@ ca_printf("CAC: sent zero ?\n"); * Flush the output - but dont block * */ -static void cac_flush_internal() +LOCAL void cac_flush_internal() { register struct ioc_in_use *piiu; LOCK - for(piiu=iiu; piiu<&iiu[nxtiiu]; piiu++){ + for( piiu = (IIU *)iiuList.node.next; + piiu; + piiu = (IIU *)piiu->node.next){ - if(piiu->send->stk==0 || !piiu->send_needed) + if(piiu->send->stk==0 || !piiu->send_needed || !piiu->conn_up) continue; cac_send_msg_piiu(piiu); @@ -838,30 +856,40 @@ static void cac_flush_internal() * 2) Return early if nothing outstanding * */ -#ifdef UNIX -void -recv_msg_select(ptimeout) +#if defined(UNIX) || defined(vxWorks) +#ifdef __STDC__ +void recv_msg_select(struct timeval *ptimeout) +#else +void recv_msg_select(ptimeout) struct timeval *ptimeout; +#endif { long status; register struct ioc_in_use *piiu; - struct timeval *ptmptimeout; + struct timeval timeout; - ptmptimeout = ptimeout; while(TRUE){ - for(piiu=iiu;piiu<&iiu[nxtiiu];piiu++) - if(piiu->conn_up){ - FD_SET(piiu->sock_chan,&readch); - FD_SET(piiu->sock_chan,&excepch); - } + LOCK; + for( piiu=(IIU *)iiuList.node.next; + piiu; + piiu=(IIU *)piiu->node.next){ + + if(!piiu->conn_up){ + continue; + } + + FD_SET(piiu->sock_chan,&readch); + FD_SET(piiu->sock_chan,&excepch); + } + UNLOCK; status = select( sizeof(fd_set)*NBBY, &readch, NULL, &excepch, - ptmptimeout); + ptimeout); if(status<=0){ if(status == 0) @@ -886,25 +914,76 @@ struct timeval *ptimeout; } } - for(piiu=iiu;piiu<&iiu[nxtiiu];piiu++){ - if(piiu->conn_up){ - if(FD_ISSET(piiu->sock_chan,&readch) || - FD_ISSET(piiu->sock_chan,&excepch)){ - recv_msg(piiu); - } + /* + * I dont want to lock while traversing + * this list so that we are free to take + * it at a lower level + * + * I know that an item can be added to the + * end of the list while traversing it + * - no lock required here. + * + * I know that an item is only deleted from + * this list in this routine + * - no lock required here. + * + * LOCK is applied when if a block is added + */ + for( piiu=(IIU *)iiuList.node.next; + piiu; + piiu=(IIU *)piiu->node.next){ + + if(!piiu->conn_up){ + continue; + } + + if(FD_ISSET(piiu->sock_chan,&readch) || + FD_ISSET(piiu->sock_chan,&excepch)){ + recv_msg(piiu); } } /* * double check to make sure that nothing is left pending */ - ptmptimeout = ¬imeout; + timeout.tv_sec =0; + timeout.tv_usec = 0; + ptimeout = &timeout; } + LOCK; + clean_iiu_list(); + UNLOCK; + cac_flush_internal(); } #endif + +/* + * clean_iiu_list() + */ +LOCAL void clean_iiu_list() +{ + IIU *piiu; + + piiu=(IIU *)iiuList.node.next; + while(piiu){ + IIU *pnext; + + /* + * iiu block may be deleted here + * so I save the pointer to the next + * block + */ + pnext=(IIU *)piiu->node.next; + if(!piiu->conn_up){ + ellDelete(&iiuList, &piiu->node); + free(piiu); + } + piiu=pnext; + } +} /* @@ -912,10 +991,17 @@ struct timeval *ptimeout; * * */ -static void -recv_msg(piiu) +#ifdef __STDC__ +LOCAL void recv_msg(struct ioc_in_use *piiu) +#else +LOCAL void recv_msg(piiu) struct ioc_in_use *piiu; +#endif { + if(!piiu->conn_up){ + return; + } + piiu->active = TRUE; switch(piiu->sock_proto){ @@ -932,7 +1018,7 @@ struct ioc_in_use *piiu; default: ca_printf("CAC: cac_send_msg: ukn protocol\n"); - abort(); + abort(0); } piiu->active = FALSE; @@ -943,13 +1029,15 @@ struct ioc_in_use *piiu; * TCP_RECV_MSG() * */ -static void -tcp_recv_msg(piiu) +#ifdef __STDC__ +LOCAL void tcp_recv_msg(struct ioc_in_use *piiu) +#else +LOCAL void tcp_recv_msg(piiu) struct ioc_in_use *piiu; +#endif { long byte_cnt; int status; - int timeoutcnt; struct buffer *rcvb = piiu->recv; int sock = piiu->sock_chan; @@ -1005,14 +1093,14 @@ struct ioc_in_use *piiu; /* post message to the user */ byte_cnt = rcvb->stk; status = post_msg( - rcvb->buf, + (struct extmsg *)rcvb->buf, &byte_cnt, &piiu->sock_addr.sin_addr, piiu); if(status != OK){ - LOCK; - close_ioc(piiu); - UNLOCK; + LOCK; + close_ioc(piiu); + UNLOCK; return; } if(byte_cnt>0){ @@ -1032,7 +1120,7 @@ struct ioc_in_use *piiu; /* * reset the delay to the next keepalive */ - if(piiu != &iiu[BROADCAST_IIU] && piiu->conn_up){ + if(piiu != piiuCast){ piiu->next_retry = time(NULL) + CA_RETRY_PERIOD; } @@ -1045,15 +1133,17 @@ struct ioc_in_use *piiu; * UDP_RECV_MSG() * */ -static void -udp_recv_msg(piiu) +#ifdef __STDC__ +LOCAL void udp_recv_msg(struct ioc_in_use *piiu) +#else +LOCAL void udp_recv_msg(piiu) struct ioc_in_use *piiu; +#endif { int status; struct buffer *rcvb = piiu->recv; int sock = piiu->sock_chan; int reply_size; - char *ptr; unsigned nchars; struct msglog{ long nbytes; @@ -1069,13 +1159,13 @@ struct ioc_in_use *piiu; pmsglog = (struct msglog *) &rcvb->buf[rcvb->stk]; rcvb->stk += sizeof(*pmsglog); - reply_size = sizeof(struct sockaddr_in); + reply_size = sizeof(pmsglog->addr); status = recvfrom( sock, &rcvb->buf[rcvb->stk], MAX_UDP, 0, - &pmsglog->addr, + (struct sockaddr *)&pmsglog->addr, &reply_size); if(status < 0){ /* @@ -1098,17 +1188,16 @@ struct ioc_in_use *piiu; #ifdef DEBUG ca_printf("CAC: recieved a udp reply of %d bytes\n",byte_cnt); #endif - if(rcvb->stk + MAX_UDP + sizeof(*pmsglog) > MAX_MSG_SIZE) break; - + /* * More comming ? */ status = socket_ioctl( sock, FIONREAD, - &nchars); + (int) &nchars); if(status<0) ca_signal(ECA_INTERNAL,"unexpected udp ioctl err\n"); @@ -1123,12 +1212,14 @@ struct ioc_in_use *piiu; /* post message to the user */ msgcount = pmsglog->nbytes; status = post_msg( - pmsglog+1, + (struct extmsg *)(pmsglog+1), &msgcount, &pmsglog->addr.sin_addr, piiu); if(status != OK || msgcount != 0){ - ca_printf( "CAC: UDP alignment problem %d\n", + ca_printf("CAC: bad UDP msg from port=%d addr=%x align=%d\n", + pmsglog->addr.sin_port, + pmsglog->addr.sin_addr.s_addr, msgcount); } @@ -1147,46 +1238,30 @@ struct ioc_in_use *piiu; * RECV_TASK() * */ -static void -recv_task(piiu, moms_tid) -struct ioc_in_use *piiu; -int moms_tid; +#ifdef __STDC__ +void cac_recv_task(int tid) +#else +void cac_recv_task(tid) +int tid; +#endif { + struct timeval timeout; int status; taskwdInsert((int) taskIdCurrent, NULL, NULL); - status = taskVarAdd(VXTHISTASKID, &ca_static); - if(status == ERROR) - abort(); - - ca_static = (struct ca_static *) - taskVarGet(moms_tid, &ca_static); - - if(ca_static == (struct ca_static*)ERROR) - abort(); - - while(piiu->conn_up){ - recv_msg(piiu); - cac_flush_internal(); - } + status = ca_import(tid); + SEVCHK(status, NULL); /* - * Exit recv task - * - * NOTE on vxWorks I dont want the global channel access exit handler to - * run for this pod of tasks when the recv task exits so I delete the - * task variable here. The CA exit handler ignores tasks with out the - * ca task var defined. + * detects connection loss and self exits + * in close_ioc() */ - - status = taskVarDelete(VXTHISTASKID, &ca_static); - if(status == ERROR) - abort(); - - taskwdRemove((int) taskIdCurrent, NULL, NULL); - - exit(); + while(TRUE){ + timeout.tv_usec = 0; + timeout.tv_sec = 20; + recv_msg_select(&timeout); + } } #endif @@ -1198,9 +1273,12 @@ int moms_tid; * */ #ifdef VMS -static void -vms_recv_msg_ast(piiu) +#ifdef __STDC__ +LOCAL void vms_recv_msg_ast(struct ioc_in_use *piiu) +#else +LOCAL void vms_recv_msg_ast(piiu) struct ioc_in_use *piiu; +#endif { short io_status; @@ -1217,7 +1295,7 @@ struct ioc_in_use *piiu; notify_ca_repeater(); recv_msg(piiu); - + clean_iiu_list(); cac_flush_internal(); /* @@ -1253,21 +1331,25 @@ struct ioc_in_use *piiu; * NOTES: * Lock must be applied while in this routine */ -void -close_ioc(piiu) +#ifdef __STDC__ +void close_ioc(struct ioc_in_use *piiu) +#else +void close_ioc(piiu) struct ioc_in_use *piiu; +#endif { - register chid chix; + chid chix; struct connection_handler_args args; int status; - if(piiu == &iiu[BROADCAST_IIU]){ - ca_signal(ECA_INTERNAL, - "Unable to perform UDP broadcast\n"); - } - - if(!piiu->conn_up) + if(!piiu->conn_up){ return; + } + piiu->conn_up = FALSE; + + if(piiu == piiuCast){ + piiuCast = NULL; + } /* * reset send stack- discard pending ops when the conn broke (assume @@ -1276,7 +1358,6 @@ struct ioc_in_use *piiu; piiu->send->stk = 0; piiu->recv->stk = 0; piiu->max_msg = MAX_UDP; - piiu->conn_up = FALSE; piiu->active = FALSE; /* @@ -1286,9 +1367,10 @@ struct ioc_in_use *piiu; piiu->nconn_tries = 0; piiu->retry_delay = CA_RECAST_DELAY; -# ifdef UNIX +# if defined(UNIX) || defined(vxWorks) /* clear unused select bit */ FD_CLR(piiu->sock_chan, &readch); + FD_CLR(piiu->sock_chan, &excepch); # endif /* @@ -1305,6 +1387,12 @@ struct ioc_in_use *piiu; chix->id.sid = ~0L; } + if(piiu->chidlist.count){ + ca_signal( + ECA_DISCONN, + piiu->host_name_str); + } + /* * call their connection handler as required */ @@ -1317,8 +1405,16 @@ struct ioc_in_use *piiu; (*chix->connection_func)(args); UNLOCKEVENTS; } + chix->piiu = piiuCast; } + /* + * move all channels to the broadcast IIU + */ + if(piiuCast){ + ellConcat(&piiuCast->chidlist, &piiu->chidlist); + } + if(fd_register_func){ LOCKEVENTS; (*fd_register_func)(fd_register_arg, piiu->sock_chan, FALSE); @@ -1330,10 +1426,9 @@ struct ioc_in_use *piiu; SEVCHK(ECA_INTERNAL,NULL); } piiu->sock_chan = -1; - if(piiu->chidlist.count){ - ca_signal( - ECA_DISCONN, - piiu->host_name_str); + + if(!piiuCast){ + ca_printf("Unable to broadcast- channels will not reconnect\n"); } } @@ -1363,7 +1458,7 @@ struct ioc_in_use *piiu; * * 072392 - problem solved by using SO_REUSEADDR */ -repeater_installed() +int repeater_installed() { int status; int sock; @@ -1376,7 +1471,7 @@ repeater_installed() SOCK_DGRAM, /* type */ 0); /* deflt proto */ if(sock == ERROR){ - abort(); + abort(0); } status = setsockopt( sock, @@ -1388,7 +1483,7 @@ repeater_installed() ca_printf( "CAC: set socket option reuseaddr failed\n"); } - memset(&bd,0,sizeof bd); + memset((char *)&bd,0,sizeof bd); bd.sin_family = AF_INET; bd.sin_addr.s_addr = htonl(INADDR_ANY); bd.sin_port = htons(CA_CLIENT_PORT); @@ -1399,7 +1494,7 @@ repeater_installed() if(MYERRNO == EADDRINUSE) installed = TRUE; else - abort(); + abort(0); status = socket_close(sock); if(status<0){ diff --git a/src/ca/repeater.c b/src/ca/repeater.c index b351881e0..08b80bb7f 100644 --- a/src/ca/repeater.c +++ b/src/ca/repeater.c @@ -79,6 +79,10 @@ static char *sccsId = "$Id$\t$Date$"; # include # include # include +# include +# include +# include +# include # include # else @@@@ dont compile @@@@ @@ -86,8 +90,12 @@ static char *sccsId = "$Id$\t$Date$"; # endif #endif -#include +#ifdef vxWorks +#include +#endif +#include #include +#include #include /* @@ -105,9 +113,13 @@ ELLLIST client_list; static char buf[MAX_UDP]; -static int clean_client(); -static int ca_repeater(); -int local_addr(); +#ifdef __STDC__ +LOCAL int clean_client(struct one_client *pclient); +LOCAL int ca_repeater(); +#else +LOCAL int clean_client(); +LOCAL int ca_repeater(); +#endif #define NTRIES 100 @@ -121,7 +133,7 @@ int local_addr(); #ifdef VMS main() #else -ca_repeater_task() +int ca_repeater_task() #endif { #if REPEATER_RETRY @@ -163,8 +175,7 @@ ca_repeater_task() * * */ -static int -ca_repeater() +LOCAL int ca_repeater() { int status; int size; @@ -195,11 +206,11 @@ ca_repeater() __FILE__); } - memset(&bd,0,sizeof bd); + memset((char *)&bd,0,sizeof bd); bd.sin_family = AF_INET; bd.sin_addr.s_addr = htonl(INADDR_ANY); bd.sin_port = htons(CA_CLIENT_PORT); - status = bind(sock, &bd, sizeof bd); + status = bind(sock, (struct sockaddr *)&bd, sizeof bd); if(status<0){ if(MYERRNO != EADDRINUSE){ ca_printf("CA Repeater: unexpected bind fail %d\n", @@ -230,7 +241,7 @@ ca_repeater() buf, sizeof buf, 0, - &from, + (struct sockaddr *)&from, &from_size); if(size > 0){ @@ -246,7 +257,7 @@ ca_repeater() buf, size, 0, - &pclient->from, + (struct sockaddr *)&pclient->from, sizeof pclient->from); if(status < 0){ ca_printf("CA Repeater: fanout err %d\n", @@ -263,7 +274,7 @@ ca_repeater() /* * If this is a processor local message then add to * the list of clients to repeat to if not there - * allready + * already */ for( pclient = (struct one_client *) client_list.node.next; @@ -278,22 +289,25 @@ ca_repeater() malloc(sizeof *pclient); if(pclient){ pclient->from = from; - ellAdd(&client_list, pclient); + ellAdd( &client_list, + &pclient->node); #ifdef DEBUG - ca_printf("Added %x %d\n", from.sin_port, size); + ca_printf( + "Added %x %d\n", + from.sin_port, size); #endif } } - memset(&confirm, NULL, sizeof confirm); + memset((char *)&confirm, NULL, sizeof confirm); confirm.m_cmmd = htons(REPEATER_CONFIRM); confirm.m_available = local.sin_addr.s_addr; status = sendto( sock, - &confirm, + (char *)&confirm, sizeof confirm, 0, - &from, /* reflect back to sender */ + (struct sockaddr *)&from, /* back to sender */ sizeof from); if(status != sizeof confirm){ ca_printf("CA Repeater: confirm err %d\n", @@ -324,9 +338,12 @@ ca_repeater() * check to see if this client is still around * */ -static int -clean_client(pclient) +#ifdef __STDC__ +LOCAL int clean_client(struct one_client *pclient) +#else +LOCAL int clean_client(pclient) struct one_client *pclient; +#endif { int port = pclient->from.sin_port; int sock; @@ -344,11 +361,11 @@ struct one_client *pclient; return ERROR; } - memset(&bd,0,sizeof bd); + memset((char *)&bd,0,sizeof bd); bd.sin_family = AF_INET; bd.sin_addr.s_addr = htonl(INADDR_ANY); bd.sin_port = port; - status = bind(sock, &bd, sizeof bd); + status = bind(sock, (struct sockaddr *)&bd, sizeof bd); if(status<0){ if(MYERRNO == EADDRINUSE) present = TRUE; @@ -360,7 +377,7 @@ struct one_client *pclient; socket_close(sock); if(!present){ - ellDelete(&client_list, pclient); + ellDelete(&client_list, &pclient->node); free(pclient); #ifdef DEBUG ca_printf("Deleted\n"); diff --git a/src/ca/service.c b/src/ca/service.c index b85c9d3a3..9a8961533 100644 --- a/src/ca/service.c +++ b/src/ca/service.c @@ -68,7 +68,7 @@ /************************************************************************/ /*_end */ -static char *sccsId = "@(#)service.c 1.17\t6/2/93"; +static char *sccsId = "$Id$"; #if defined(VMS) # include @@ -79,6 +79,8 @@ static char *sccsId = "@(#)service.c 1.17\t6/2/93"; # include # else # if defined(vxWorks) +# include +# include # include # else @@@@ dont compile @@@@ @@ -86,17 +88,27 @@ static char *sccsId = "@(#)service.c 1.17\t6/2/93"; # endif #endif -#include #include -#include +#include #include #include +#include #include -static void reconnect_channel(); -void ca_request_event(); +#ifdef __STDC__ -#define BUFSTAT ca_printf("CAC: expected %d left %d\n",msgcnt,*pbufcnt); +LOCAL void reconnect_channel( +struct extmsg *hdrptr, +struct in_addr *pnet_addr +); + +#else + +LOCAL void reconnect_channel(); + +#endif + +#define BUFSTAT ca_printf("CAC: expected %d left %d\n",msgcnt,*pbufcnt); @@ -106,21 +118,29 @@ void ca_request_event(); * * */ -int -post_msg(hdrptr, pbufcnt, pnet_addr, piiu) - register struct extmsg *hdrptr; - register long *pbufcnt; - struct in_addr *pnet_addr; - struct ioc_in_use *piiu; +#ifdef __STDC__ +int post_msg( +struct extmsg *hdrptr, +long *pbufcnt, +struct in_addr *pnet_addr, +struct ioc_in_use *piiu +) +#else +int post_msg(hdrptr, pbufcnt, pnet_addr, piiu) +struct extmsg *hdrptr; +long *pbufcnt; +struct in_addr *pnet_addr; +struct ioc_in_use *piiu; +#endif { evid monix; long msgcnt; - register void *t_available; - register unsigned short t_postsize; - register unsigned short t_cmmd; - register chtype t_type; - register unsigned short t_count; + void *t_available; + unsigned short t_postsize; + unsigned short t_cmmd; + chtype t_type; + unsigned short t_count; int status; @@ -200,8 +220,8 @@ post_msg(hdrptr, pbufcnt, pnet_addr, piiu) UNLOCKEVENTS; } LOCK; - ellDelete(&pend_read_list, monix); - ellAdd(&free_event_list, monix); + ellDelete(&pend_read_list, &monix->node); + ellAdd(&free_event_list, &monix->node); UNLOCK; piiu->outstanding_ack_count--; @@ -225,8 +245,8 @@ post_msg(hdrptr, pbufcnt, pnet_addr, piiu) */ if (!t_postsize) { LOCK; - ellDelete(&monix->chan->eventq, monix); - ellAdd(&free_event_list, monix); + ellDelete(&monix->chan->eventq, &monix->node); + ellAdd(&free_event_list, &monix->node); UNLOCK; piiu->outstanding_ack_count--; @@ -287,8 +307,17 @@ post_msg(hdrptr, pbufcnt, pnet_addr, piiu) chan = bucketLookupItem(pBucket, hdrptr->m_cid); UNLOCK; if(!chan){ - ca_signal(ECA_INTERNAL, - "bad client channel id from server"); + if(t_cmmd == IOC_READ_BUILD){ + printf( + "Stale build reply from %s with id %x ignored", + host_from_addr(pnet_addr), + hdrptr->m_cid); + UNLOCK; + } + else{ + ca_signal(ECA_INTERNAL, + "bad client channel id from server"); + } break; } @@ -323,8 +352,8 @@ post_msg(hdrptr, pbufcnt, pnet_addr, piiu) t_count); #else memcpy( - t_available, - hdrptr + 1, + (char *) t_available, + (char *) (hdrptr + 1), size); #endif @@ -375,33 +404,13 @@ post_msg(hdrptr, pbufcnt, pnet_addr, piiu) break; case IOC_NOT_FOUND: - { - chid chix = (chid) t_available; - struct ioc_in_use *piiu = &iiu[chix->iocix]; - - LOCK; - ellDelete(&piiu->chidlist, chix); - ellAdd(&iiu[BROADCAST_IIU].chidlist, chix); - chix->iocix = BROADCAST_IIU; - if (!piiu->chidlist.count) - close_ioc(piiu); - /* - * reset the delay to the next retry or keepalive - */ - iiu[BROADCAST_IIU].next_retry = CA_CURRENT_TIME; - iiu[BROADCAST_IIU].nconn_tries = 0; - - manage_conn(TRUE); - UNLOCK; - break; - } case IOC_CLEAR_CHANNEL: { - chid chix = (chid) t_available; - struct ioc_in_use *piiu = &iiu[chix->iocix]; - register evid monix; + chid chix = (chid) t_available; + struct ioc_in_use *piiu = chix->piiu; + register evid monix; LOCK; @@ -413,11 +422,15 @@ post_msg(hdrptr, pbufcnt, pnet_addr, piiu) monix; monix = (evid) monix->node.next) if (monix->chan == chix) { - ellDelete(&pend_read_list, monix); - ellAdd(&free_event_list, monix); + ellDelete( + &pend_read_list, + &monix->node); + ellAdd( + &free_event_list, + &monix->node); } ellConcat(&free_event_list, &chix->eventq); - ellDelete(&piiu->chidlist, chix); + ellDelete(&piiu->chidlist, &chix->node); status = bucketRemoveItem(pBucket, chix->cid, chix); if(status != BUCKET_SUCCESS){ ca_signal( @@ -426,8 +439,9 @@ post_msg(hdrptr, pbufcnt, pnet_addr, piiu) } free(chix); piiu->outstanding_ack_count--; - if (!piiu->chidlist.count) + if (!piiu->chidlist.count){ close_ioc(piiu); + } UNLOCK; break; } @@ -457,7 +471,7 @@ post_msg(hdrptr, pbufcnt, pnet_addr, piiu) sprintf(context, "detected by: %s for: %s", name, - hdrptr + 2); + (char *)(hdrptr + 2)); } else{ sprintf(context, "detected by: %s", name); @@ -537,16 +551,23 @@ post_msg(hdrptr, pbufcnt, pnet_addr, piiu) * LOCK must be on * */ -static void reconnect_channel(hdrptr,pnet_addr) -register struct extmsg *hdrptr; -struct in_addr *pnet_addr; +#ifdef __STDC__ +LOCAL void reconnect_channel( +struct extmsg *hdrptr, +struct in_addr *pnet_addr +) +#else +LOCAL void reconnect_channel(hdrptr,pnet_addr) +struct extmsg *hdrptr; +struct in_addr *pnet_addr; +#endif { chid chan; - unsigned short newiocix; evid pevent; int status; enum channel_state prev_cs; - struct ioc_in_use *chpiiu; + IIU *allocpiiu; + IIU *chpiiu; /* * ignore broadcast replies for deleted channels @@ -568,7 +589,13 @@ struct in_addr *pnet_addr; return; } - chpiiu = &iiu[chan->iocix]; + chpiiu = chan->piiu; + + if(!chpiiu){ + ca_printf("cast reply to local channel??\n"); + UNLOCK; + return; + } if (chan->state == cs_conn) { @@ -591,7 +618,7 @@ struct in_addr *pnet_addr; sprintf( sprintf_buf, "Channel: %s Accepted: %s Rejected: %s ", - chan + 1, + (char *)(chan + 1), acc, rej); ca_signal(ECA_DBLCHNL, sprintf_buf); @@ -616,12 +643,13 @@ struct in_addr *pnet_addr; status = alloc_ioc ( pnet_addr, IPPROTO_TCP, - &newiocix - ); + &allocpiiu); if(status != ECA_NORMAL){ - ca_printf("CAC: ... %s ...\n", ca_message(status)); - ca_printf("CAC: for %s on %s\n", chan+1, host_from_addr(pnet_addr)); - ca_printf("CAC: ignored search reply- proceeding\n"); + ca_printf( "CAC: ... %s ...\n", ca_message(status)); + ca_printf( "CAC: for %s on %s\n", + chan+1, + host_from_addr(pnet_addr)); + ca_printf( "CAC: ignored search reply- proceeding\n"); UNLOCK; return; } @@ -631,18 +659,16 @@ struct in_addr *pnet_addr; chan->count = ntohs(hdrptr->m_count); chan->id.sid = hdrptr->m_cid; - if(chan->iocix != newiocix){ - struct ioc_in_use *chpiiu; + if(chpiiu != allocpiiu){ /* * The address changed (or was found for the first time) */ - if(chan->iocix != BROADCAST_IIU) + if(chpiiu != piiuCast) ca_signal(ECA_NEWADDR, (char *)(chan+1)); - chpiiu = &iiu[chan->iocix]; - ellDelete(&chpiiu->chidlist, chan); - chan->iocix = newiocix; - ellAdd(&iiu[newiocix].chidlist, chan); + ellDelete(&chpiiu->chidlist, &chan->node); + chan->piiu = chpiiu = allocpiiu; + ellAdd(&chpiiu->chidlist, &chan->node); } /* @@ -658,7 +684,7 @@ struct in_addr *pnet_addr; * over TCP so problems with duplicate UDP port * after reboot go away */ - issue_claim_channel(&iiu[chan->iocix], chan); + issue_claim_channel(chpiiu, chan); /* * NOTE: monitor and callback reissue must occur prior to calling @@ -710,9 +736,12 @@ struct in_addr *pnet_addr; * * */ -void -cac_io_done(lock) +#ifdef __STDC__ +void cac_io_done(int lock) +#else +void cac_io_done(lock) int lock; +#endif { register struct pending_io_event *pioe; diff --git a/src/ca/test_event.c b/src/ca/test_event.c index d8c442b44..fccdad001 100644 --- a/src/ca/test_event.c +++ b/src/ca/test_event.c @@ -14,17 +14,21 @@ * */ -static char *sccsId = "@(#)test_event.c 1.6\t7/27/92"; +static char *sccsId = "$Id$"; /* System includes */ -#include -#include +#include +#include +#include -void -ca_test_event(args) +#ifdef __STDC__ +void ca_test_event(struct event_handler_args args) +#else +void ca_test_event(args) struct event_handler_args args; +#endif { ca_printf("CAC: ~~~### in test event for [%s] ###~~~\n",args.chid+1); ca_printf("CAC: User argument\t%x\n", args.usr);