diff --git a/src/ca/access.c b/src/ca/access.c index a9fd148c6..686d12a7c 100644 --- a/src/ca/access.c +++ b/src/ca/access.c @@ -99,6 +99,9 @@ /************************************************************************/ /* * $Log$ + * Revision 1.81 1995/12/19 19:28:11 jhill + * Dont check the array element count when they add the event (just clip it) + * * Revision 1.80 1995/10/18 16:49:23 jhill * recv task is now running at a lower priority than the send task under vxWorks * @@ -183,7 +186,7 @@ static char *sccsId = "@(#) $Id$"; /* Macros for syncing message insertion into send buffer */ /****************************************************************/ #define EXTMSGPTR(PIIU)\ - ((struct extmsg *) &(PIIU)->send.buf[(PIIU)->send.wtix]) + ((caHdr *) &(PIIU)->send.buf[(PIIU)->send.wtix]) @@ -214,7 +217,7 @@ static char *sccsId = "@(#) $Id$"; } \ } -static struct extmsg nullmsg; +static caHdr nullmsg; /* * local functions @@ -223,14 +226,14 @@ static struct extmsg nullmsg; LOCAL int cac_alloc_msg( struct ioc_in_use *piiu, unsigned extsize, -struct extmsg **ppMsg +caHdr **ppMsg ); #endif LOCAL int cac_alloc_msg_no_flush( struct ioc_in_use *piiu, unsigned extsize, -struct extmsg **ppMsg +caHdr **ppMsg ); LOCAL int issue_get_callback( evid monix, @@ -258,7 +261,7 @@ LOCAL void ca_default_exception_handler(struct exception_handler_args args); LOCAL int cac_push_msg( struct ioc_in_use *piiu, -struct extmsg *pmsg, +caHdr *pmsg, void *pext ); @@ -282,11 +285,11 @@ LOCAL evid caIOBlockCreate(void); */ LOCAL int cac_push_msg( struct ioc_in_use *piiu, -struct extmsg *pmsg, +caHdr *pmsg, void *pext ) { - struct extmsg msg; + caHdr msg; unsigned bytesAvailable; unsigned actualextsize; unsigned extsize; @@ -431,14 +434,14 @@ void *pext LOCAL int cac_alloc_msg_no_flush( struct ioc_in_use *piiu, unsigned extsize, -struct extmsg **ppMsg +caHdr **ppMsg ) { unsigned msgsize; unsigned long bytesAvailable; - struct extmsg *pmsg; + caHdr *pmsg; - msgsize = sizeof(struct extmsg)+extsize; + msgsize = sizeof(caHdr)+extsize; /* * fail if max message size exceeded @@ -452,7 +455,7 @@ struct extmsg **ppMsg return ECA_TOLARGE; } - pmsg = (struct extmsg *) &piiu->send.buf[piiu->send.wtix]; + pmsg = (caHdr *) &piiu->send.buf[piiu->send.wtix]; pmsg->m_postsize = extsize; *ppMsg = pmsg; @@ -466,7 +469,7 @@ struct extmsg **ppMsg LOCAL void cac_add_msg (IIU *piiu) { unsigned long size; - struct extmsg *mp = EXTMSGPTR(piiu); + caHdr *mp = EXTMSGPTR(piiu); /* * Performs worst case message alignment @@ -477,7 +480,7 @@ LOCAL void cac_add_msg (IIU *piiu) mp->m_postsize = htons(mp->m_postsize); CAC_RING_BUFFER_WRITE_ADVANCE( &piiu->send, - sizeof(struct extmsg) + size); + sizeof(caHdr) + size); } @@ -1077,6 +1080,8 @@ int epicsShareAPI ca_search_and_connect chix->type = TYPENOTCONN; /* invalid initial type */ chix->count = 0; /* invalid initial count */ chix->id.sid = ~0U; /* invalid initial server id */ + chix->ar.read_access = FALSE; + chix->ar.write_access = FALSE; chix->state = cs_never_conn; ellInit(&chix->eventq); @@ -1128,13 +1133,13 @@ int reply_type int status; int size; int cmd; - struct extmsg *mptr; + caHdr *mptr; struct ioc_in_use *piiu; piiu = chix->piiu; size = strlen((char *)(chix+1))+1; - cmd = IOC_SEARCH; + cmd = CA_PROTO_SEARCH; LOCK; status = cac_alloc_msg_no_flush (piiu, size, &mptr); @@ -1242,7 +1247,7 @@ void *pvalue UNLOCK; if (monix) { - status = issue_get_callback(monix, IOC_READ); + status = issue_get_callback(monix, CA_PROTO_READ); if (status == ECA_NORMAL) { SETPENDRECV; } @@ -1325,7 +1330,7 @@ void *arg UNLOCK; if (monix) { - status = issue_get_callback (monix, IOC_READ_NOTIFY); + status = issue_get_callback (monix, CA_PROTO_READ_NOTIFY); if (status != ECA_NORMAL) { LOCK; if (ca_state(chix)==cs_conn) { @@ -1450,7 +1455,7 @@ LOCAL int issue_get_callback(evid monix, unsigned cmmd) int status; chid chix = monix->chan; unsigned count; - struct extmsg hdr; + caHdr hdr; struct ioc_in_use *piiu; piiu = chix->piiu; @@ -1629,7 +1634,7 @@ void *usrarg monix->count = count; status = issue_ca_array_put( - IOC_WRITE_NOTIFY, + CA_PROTO_WRITE_NOTIFY, monix->id, type, count, @@ -1752,7 +1757,7 @@ void *pvalue } #endif /*vxWorks*/ - return issue_ca_array_put(IOC_WRITE, ~0U, type, count, chix, pvalue); + return issue_ca_array_put(CA_PROTO_WRITE, ~0U, type, count, chix, pvalue); } @@ -1771,7 +1776,7 @@ void *pvalue { int status; struct ioc_in_use *piiu; - struct extmsg hdr; + caHdr hdr; int postcnt; unsigned size_of_one; unsigned i; @@ -2037,6 +2042,7 @@ void *arg * Undocumented entry for the VAX OPI which may vanish in the future. * */ +#if 0 int epicsShareAPI ca_add_io_event ( void (*ast)(), @@ -2063,7 +2069,7 @@ void *astarg return ECA_NORMAL; } - +#endif @@ -2256,7 +2262,7 @@ int ca_request_event(evid monix) } /* msg header */ - msg.m_header.m_cmmd = htons(IOC_EVENT_ADD); + msg.m_header.m_cmmd = htons(CA_PROTO_EVENT_ADD); msg.m_header.m_available = monix->id; msg.m_header.m_type = htons(monix->type); msg.m_header.m_count = htons(count); @@ -2445,7 +2451,7 @@ int epicsShareAPI ca_clear_event (evid monix) { int status; chid chix = monix->chan; - struct extmsg hdr; + caHdr hdr; evid lkup; /* @@ -2499,7 +2505,7 @@ int epicsShareAPI ca_clear_event (evid monix) piiu = chix->piiu; /* msg header */ - hdr.m_cmmd = htons(IOC_EVENT_CANCEL); + hdr.m_cmmd = htons(CA_PROTO_EVENT_CANCEL); hdr.m_available = monix->id; hdr.m_type = htons(chix->type); hdr.m_count = htons(chix->count); @@ -2545,7 +2551,7 @@ int epicsShareAPI ca_clear_channel (chid chix) int status; evid monix; struct ioc_in_use *piiu = chix->piiu; - struct extmsg hdr; + caHdr hdr; enum channel_state old_chan_state; LOOSECHIXCHK(chix); @@ -2631,7 +2637,7 @@ int epicsShareAPI ca_clear_channel (chid chix) */ /* msg header */ - hdr.m_cmmd = htons(IOC_CLEAR_CHANNEL); + hdr.m_cmmd = htons(CA_PROTO_CLEAR_CHANNEL); hdr.m_available = chix->cid; hdr.m_cid = chix->id.sid; hdr.m_type = htons(0); @@ -2771,18 +2777,12 @@ int epicsShareAPI ca_pend (ca_real timeout, int early) /* - * If we are no longer waiting any significant - * delay then return - * (dont wait forever for an itsy bitsy - * delay which will no be updated if - * select is called with no delay) - * - * current time is only updated by - * cac_select_io() if we specify - * at least 1 usec to wait - * + * If we are not waiting for any significant delay + * then force the delay to zero so that we avoid + * scheduling delays (which can be substantial + * on some os) */ - if (remaining <= (1.0/USEC_PER_SEC)) { + if (remaining <= (1.0/CLOCKS_PER_SEC)) { if(early){ ca_pend_io_cleanup(); ca_static->ca_flush_pending = TRUE; @@ -2881,7 +2881,7 @@ LOCAL void ca_pend_io_cleanup() piiu; piiu = (IIU *) piiu->node.next){ - struct extmsg hdr; + caHdr hdr; if(piiu == piiuCast || !piiu->conn_up){ continue; @@ -2890,7 +2890,7 @@ LOCAL void ca_pend_io_cleanup() piiu->cur_read_seq++; hdr = nullmsg; - hdr.m_cmmd = htons(IOC_READ_SYNC); + hdr.m_cmmd = htons(CA_PROTO_READ_SYNC); cac_push_msg(piiu, &hdr, NULL); } UNLOCK; @@ -2953,6 +2953,31 @@ void epicsShareAPI ca_signal(long ca_status,char *message) ca_signal_with_file_and_lineno(ca_status, message, NULL, 0); } + +/* + * ca_message (long ca_status) + * + * - if it is an unknown error code then it possible + * that the error string generated below + * will be overwritten before (or while) the caller + * of this routine is calling this routine + * (if they call this routine again). + */ +const char *ca_message(long ca_status) +{ + unsigned msgNo = CA_EXTRACT_MSG_NO(ca_status); + + if( msgNo < NELEMENTS(ca_message_text) ){ + return ca_message_text[msgNo]; + } + else { + sprintf(ca_static->ca_new_err_code_msg_buf, + "new CA message number %u known only by server - see caerr.h", + msgNo); + return ca_static->ca_new_err_code_msg_buf; + } +} + /* * ca_signal_with_file_and_lineno() @@ -2975,16 +3000,11 @@ int lineno) "Fatal" }; - if( CA_EXTRACT_MSG_NO(ca_status) >= NELEMENTS(ca_message_text) ){ - message = "corrupt status"; - ca_status = ECA_INTERNAL; - } - ca_printf( "CA.Client.Diagnostic..............................................\n"); ca_printf( -" Message: \"%s\"\n", ca_message_text[CA_EXTRACT_MSG_NO(ca_status)]); +" Message: \"%s\"\n", ca_message(ca_status)); if(message) ca_printf( @@ -3030,7 +3050,7 @@ int lineno) */ void ca_busy_message(struct ioc_in_use *piiu) { - struct extmsg hdr; + caHdr hdr; if(!piiu){ return; @@ -3043,7 +3063,7 @@ void ca_busy_message(struct ioc_in_use *piiu) return; hdr = nullmsg; - hdr.m_cmmd = htons(IOC_EVENTS_OFF); + hdr.m_cmmd = htons(CA_PROTO_EVENTS_OFF); cac_push_msg(piiu, &hdr, NULL); @@ -3057,7 +3077,7 @@ void ca_busy_message(struct ioc_in_use *piiu) */ void ca_ready_message(struct ioc_in_use *piiu) { - struct extmsg hdr; + caHdr hdr; if(!piiu){ return; @@ -3071,7 +3091,7 @@ void ca_ready_message(struct ioc_in_use *piiu) } hdr = nullmsg; - hdr.m_cmmd = htons(IOC_EVENTS_ON); + hdr.m_cmmd = htons(CA_PROTO_EVENTS_ON); cac_push_msg(piiu, &hdr, NULL); @@ -3087,14 +3107,14 @@ void ca_ready_message(struct ioc_in_use *piiu) int echo_request(struct ioc_in_use *piiu, ca_time *pCurrentTime) { int status; - struct extmsg *phdr; + caHdr *phdr; status = cac_alloc_msg_no_flush (piiu, sizeof(*phdr), &phdr); if (status != ECA_NORMAL) { return status; } - phdr->m_cmmd = htons(IOC_ECHO); + phdr->m_cmmd = htons(CA_PROTO_ECHO); phdr->m_type = htons(0); phdr->m_count = htons(0); phdr->m_cid = htons(0); @@ -3118,9 +3138,9 @@ int echo_request(struct ioc_in_use *piiu, ca_time *pCurrentTime) */ void noop_msg(struct ioc_in_use *piiu) { - struct extmsg hdr; + caHdr hdr; - hdr.m_cmmd = htons(IOC_NOOP); + hdr.m_cmmd = htons(CA_PROTO_NOOP); hdr.m_type = htons(0); hdr.m_count = htons(0); hdr.m_cid = htons(0); @@ -3141,7 +3161,7 @@ void noop_msg(struct ioc_in_use *piiu) void issue_client_host_name(struct ioc_in_use *piiu) { unsigned size; - struct extmsg hdr; + caHdr hdr; char *pName; if(!piiu){ @@ -3170,7 +3190,7 @@ void issue_client_host_name(struct ioc_in_use *piiu) pName = ca_static->ca_pHostName, size = strlen(pName)+1; hdr = nullmsg; - hdr.m_cmmd = htons(IOC_HOST_NAME); + hdr.m_cmmd = htons(CA_PROTO_HOST_NAME); hdr.m_postsize = size; cac_push_msg(piiu, &hdr, pName); @@ -3188,7 +3208,7 @@ void issue_client_host_name(struct ioc_in_use *piiu) void issue_identify_client(struct ioc_in_use *piiu) { unsigned size; - struct extmsg hdr; + caHdr hdr; char *pName; if(!piiu){ @@ -3217,7 +3237,7 @@ void issue_identify_client(struct ioc_in_use *piiu) pName = ca_static->ca_pUserName, size = strlen(pName)+1; hdr = nullmsg; - hdr.m_cmmd = htons(IOC_CLIENT_NAME); + hdr.m_cmmd = htons(CA_PROTO_CLIENT_NAME); hdr.m_postsize = size; cac_push_msg(piiu, &hdr, pName); @@ -3234,7 +3254,7 @@ void issue_identify_client(struct ioc_in_use *piiu) */ void issue_claim_channel(struct ioc_in_use *piiu, chid pchan) { - struct extmsg hdr; + caHdr hdr; unsigned size; char *pName; @@ -3249,7 +3269,7 @@ void issue_claim_channel(struct ioc_in_use *piiu, chid pchan) return; hdr = nullmsg; - hdr.m_cmmd = htons(IOC_CLAIM_CIU); + hdr.m_cmmd = htons(CA_PROTO_CLAIM_CIU); if(CA_V44(CA_PROTOCOL_VERSION, piiu->minor_version_number)){ hdr.m_cid = pchan->cid; diff --git a/src/ca/acctst.c b/src/ca/acctst.c index d01d3a100..9ac03a5a1 100644 --- a/src/ca/acctst.c +++ b/src/ca/acctst.c @@ -7,6 +7,9 @@ static char *sccsId = "@(#) $Id$"; /* * $Log$ + * Revision 1.33 1995/12/19 19:29:04 jhill + * changed put test + * * Revision 1.32 1995/11/29 19:17:25 jhill * more tests * @@ -155,6 +158,8 @@ int doacctst(char *pname) size = dbr_size_n(DBR_GR_FLOAT, NUM); ptr = (struct dbr_gr_float *) malloc(size); + printf("Connect/disconnect test"); + fflush(stdout); for (i = 0; i < 10; i++) { status = ca_search( @@ -197,6 +202,9 @@ int doacctst(char *pname) status = ca_pend_io(1000.0); SEVCHK(status, NULL); + printf("."); + fflush(stdout); + assert(ca_test_io() == ECA_IODONE); assert(ca_state(chix1) == cs_conn); @@ -209,6 +217,7 @@ int doacctst(char *pname) SEVCHK(ca_clear_channel(chix2), NULL); SEVCHK(ca_clear_channel(chix1), NULL); } + printf("\n"); status = ca_search(pname,& chix3); SEVCHK(status, NULL); @@ -335,6 +344,33 @@ int doacctst(char *pname) } #endif + /* + * ca_pend_io() must block + */ + if(ca_read_access(chix4)){ + dbr_float_t req = 3.3; + dbr_float_t resp = 0.0; + + printf ("get TMO test ..."); + fflush(stdout); + SEVCHK(ca_put(DBR_FLOAT, chix4, &req),NULL); + SEVCHK(ca_get(DBR_FLOAT, chix4, &resp),NULL); + status = ca_pend_io(1.0e-12); + if (status==ECA_NORMAL) { + assert (resp == req); + } + else { + assert (resp == 0.0); + } + + resp = 0.0; + SEVCHK (ca_put(DBR_FLOAT, chix4, &req),NULL); + SEVCHK (ca_get(DBR_FLOAT, chix4, &resp),NULL); + SEVCHK (ca_pend_io(2000.0),NULL); + assert (resp == req); + printf ("done\n"); + } + /* * verify we dont jam up on many uninterrupted * solicitations @@ -377,6 +413,7 @@ int doacctst(char *pname) * solicitations */ if(ca_read_access(chix1)){ + unsigned count=0u; printf("Performing multiple get callback test..."); fflush(stdout); for(i=0; i<10000; i++){ @@ -385,26 +422,28 @@ int doacctst(char *pname) 1, chix1, null_event, - NULL); + &count); SEVCHK(status, NULL); } SEVCHK(ca_flush_io(), NULL); + while (count<10000u) { + ca_pend_event(1.0); + printf("waiting..."); + fflush(stdout); + } printf("done.\n"); } else{ printf("Skipped multiple get cb test - no read access\n"); } - if(ca_v42_ok(chix1)){ - test_sync_groups(chix1); - } - /* * verify we dont jam up on many uninterrupted * solicitations */ if(ca_write_access(chix1) && ca_v42_ok(chix1)){ + unsigned count=0u; printf("Performing multiple put callback test..."); fflush(stdout); for(i=0; i<10000; i++){ @@ -415,17 +454,26 @@ int doacctst(char *pname) chix1, &fval, null_event, - NULL); + &count); SEVCHK(status, NULL); } SEVCHK(ca_flush_io(), NULL); + while (count<10000u) { + ca_pend_event(1.0); + printf("waiting..."); + fflush(stdout); + } printf("done.\n"); } else{ printf("Skipped multiple put cb test - no write access\n"); } + if(ca_v42_ok(chix1)){ + test_sync_groups(chix1); + } + /* * verify we can add many monitors at once */ @@ -437,7 +485,7 @@ int doacctst(char *pname) for(i=0; isock_chan>=FD_SETSIZE) { + ca_printf( + "%s.%d: file number > FD_SETSIZE=%d ignored\n", + __FILE__, __LINE__, FD_SETSIZE); + continue; + } + /* * Dont bother receiving if we have insufficient * space for the maximum UDP message diff --git a/src/ca/conn.c b/src/ca/conn.c index 1ea048b7a..702d18b73 100644 --- a/src/ca/conn.c +++ b/src/ca/conn.c @@ -29,7 +29,10 @@ /* .12 110194 joh improved search scheduling */ /* (dont send all chans in a block) */ /* */ -/* $Log$ */ +/* $Log$ + * Revision 1.34 1995/08/22 00:19:21 jhill + * use current time var to init time stamp in a beacon hash entry + * */ /*_begin */ /************************************************************************/ /* */ @@ -208,7 +211,7 @@ void manage_conn(int silent) /* * set the retry interval */ - assert(ca_static->ca_search_retry < NBBY*sizeof(idelay)); + assert(ca_static->ca_search_retry < CHAR_BIT*sizeof(idelay)); idelay = 1; idelay = idelay << ca_static->ca_search_retry; delay = idelay * CA_RECAST_DELAY; /* sec */ diff --git a/src/ca/iocinf.c b/src/ca/iocinf.c index d4b938529..13ccde674 100644 --- a/src/ca/iocinf.c +++ b/src/ca/iocinf.c @@ -47,6 +47,9 @@ /* address in use so that test works on UNIX */ /* kernels that support multicast */ /* $Log$ + * Revision 1.61 1995/12/19 19:33:02 jhill + * function prototype changes + * * Revision 1.60 1995/11/29 19:26:01 jhill * cleaned up interface to recv() and send() * */ @@ -548,7 +551,7 @@ void caSetupBCastAddrList (ELLLIST *pList, SOCKET sock, unsigned port) */ void notify_ca_repeater() { - struct extmsg msg; + caHdr msg; struct sockaddr_in saddr; int status; static int once = FALSE; @@ -1241,7 +1244,7 @@ LOCAL void close_ioc (IIU *piiu) chix = (chid) ellFirst(&piiu->chidlist); while (chix) { pNext = (chid) ellNext(&chix->node); - cacDisconnectChannel(chix, TRUE); + cacDisconnectChannel(chix, cs_conn); chix = pNext; } } @@ -1278,8 +1281,9 @@ LOCAL void close_ioc (IIU *piiu) /* * cacDisconnectChannel() + * (LOCK must be applied when calling this routine) */ -void cacDisconnectChannel(chid chix, int fullDisconnect) +void cacDisconnectChannel(chid chix, enum channel_state state) { struct ioc_in_use *piiu; @@ -1297,7 +1301,7 @@ void cacDisconnectChannel(chid chix, int fullDisconnect) /* * call their connection handler as required */ - if (fullDisconnect) { + if (state==cs_conn) { chix->state = cs_prev_conn; /* diff --git a/src/ca/iocinf.h b/src/ca/iocinf.h index 08e7569c2..d473f979f 100644 --- a/src/ca/iocinf.h +++ b/src/ca/iocinf.h @@ -32,6 +32,9 @@ /************************************************************************/ /* $Log$ + * Revision 1.51 1995/12/19 19:33:07 jhill + * function prototype changes + * * Revision 1.50 1995/10/18 16:45:40 jhill * Use recast delay greater than one vxWorks tick * @@ -102,6 +105,7 @@ HDRVERSIONID(iocinfh, "$Id$") #include #include #include +#include #include @@ -124,7 +128,7 @@ HDRVERSIONID(iocinfh, "$Id$") * CA private includes */ #include "addrList.h" -#include "iocmsg.h" +#include "caProto.h" #ifndef min #define min(A,B) ((A)>(B)?(B):(A)) @@ -134,10 +138,6 @@ HDRVERSIONID(iocinfh, "$Id$") #define max(A,B) ((A)<(B)?(B):(A)) #endif -#ifndef NBBY -# define NBBY 8 /* number of bits per byte */ -#endif - #define MSEC_PER_SEC 1000L #define USEC_PER_SEC 1000000L @@ -159,7 +159,7 @@ if(!ca_static){ \ #define VALID_MSG(PIIU) (piiu->read_seq == piiu->cur_read_seq) #define SETPENDRECV {pndrecvcnt++;} -#define CLRPENDRECV(LOCK) {if(--pndrecvcnt<1){cac_io_done(LOCK); POST_IO_EV;}} +#define CLRPENDRECV(LOCK) {if(--pndrecvcnt<1){POST_IO_EV;}} struct udpmsglog{ long nbytes; @@ -179,12 +179,6 @@ struct putCvrtBuf{ #define CA_DO_SENDS (1<<0) #define CA_DO_RECVS (1<<1) -struct pending_io_event{ - ELLNODE node; - void (*io_done_sub)(); - void *io_done_arg; -}; - typedef struct timeval ca_time; #define LD_CA_TIME(FLOAT_TIME,PCATIME) \ @@ -287,7 +281,6 @@ typedef struct caclient_put_notify{ #define nextFastBucketId (ca_static->ca_nextFastBucketId) #if defined(vxWorks) -# define io_done_sem (ca_static->ca_io_done_sem) # define evuser (ca_static->ca_evuser) # define client_lock (ca_static->ca_client_lock) # define event_lock (ca_static->ca_event_lock) @@ -358,7 +351,7 @@ typedef struct ioc_in_use{ unsigned long curDataBytes; struct ca_buffer send; struct ca_buffer recv; - struct extmsg curMsg; + caHdr curMsg; struct ca_static *pcas; void *pCurData; void (*sendBytes)(struct ioc_in_use *); @@ -451,12 +444,12 @@ struct ca_static{ unsigned short ca_server_port; unsigned short ca_repeater_port; char ca_sprintf_buf[256]; + char ca_new_err_code_msg_buf[128u]; unsigned ca_post_msg_active:1; unsigned ca_manage_conn_active:1; unsigned ca_repeater_contacted:1; unsigned ca_flush_pending:1; #if defined(vxWorks) - SEM_ID ca_io_done_sem; SEM_ID ca_blockSem; SEM_ID ca_client_lock; SEM_ID ca_event_lock; /* dont allow events to preempt */ @@ -541,7 +534,6 @@ void flow_control(struct ioc_in_use *piiu); int broadcast_addr(struct in_addr *pcastaddr); void ca_repeater(void); void cac_recv_task(int tid); -void cac_io_done(int lock); void ca_sg_init(void); void ca_sg_shutdown(struct ca_static *ca_temp); int cac_select_io(struct timeval *ptimeout, int flags); @@ -629,7 +621,7 @@ ca_time cac_time_sum(ca_time *pTVA, ca_time *pTVB); void caIOBlockFree(evid pIOBlock); void clearChannelResources(unsigned id); void caSetDefaultPrintfHandler (void); -void cacDisconnectChannel(chid chix, int fullDisconnect); +void cacDisconnectChannel(chid chix, enum channel_state state); int caSendMsgPending(void); /* diff --git a/src/ca/os_depen.h b/src/ca/os_depen.h index 90e659b9f..99d817ffc 100644 --- a/src/ca/os_depen.h +++ b/src/ca/os_depen.h @@ -44,6 +44,7 @@ static char *os_depenhSccsId = "$Id$"; #ifdef UNIX # include # include +# include # include # include # include diff --git a/src/ca/repeater.c b/src/ca/repeater.c index 329757c4a..554cbc202 100644 --- a/src/ca/repeater.c +++ b/src/ca/repeater.c @@ -63,6 +63,9 @@ * datagram socket (and watching for ECONNREFUSED) * * $Log$ + * Revision 1.33 1995/11/29 19:19:05 jhill + * Added $log$ + * */ static char *sccsId = "@(#)$Id$"; @@ -142,7 +145,7 @@ void ca_repeater() #endif while(TRUE){ - struct extmsg *pMsg; + caHdr *pMsg; size = recvfrom( sock, @@ -167,7 +170,7 @@ void ca_repeater() continue; } - pMsg = (struct extmsg *) buf; + pMsg = (caHdr *) buf; /* * both zero length message and a registration message @@ -268,24 +271,29 @@ LOCAL SOCKET makeSocket(unsigned short port) return sock; } - status = setsockopt( sock, - SOL_SOCKET, - SO_REUSEADDR, - (char *)&true, - sizeof(true)); - if(status<0){ - ca_printf( "%s: set socket option failed\n", - __FILE__); - } + /* + * no need to bind if unconstrained + */ + if (port != PORT_ANY) { + status = setsockopt( sock, + SOL_SOCKET, + SO_REUSEADDR, + (char *)&true, + sizeof(true)); + if (status<0) { + ca_printf("%s: set socket option failed because \"%s\"\n", + __FILE__, strerror(MYERRNO)); + } - memset((char *)&bd, 0, sizeof(bd)); - bd.sin_family = AF_INET; - bd.sin_addr.s_addr = INADDR_ANY; - bd.sin_port = htons(port); - status = bind(sock, (struct sockaddr *)&bd, sizeof(bd)); - if(status<0){ - socket_close(sock); - return INVALID_SOCKET; + memset((char *)&bd, 0, sizeof(bd)); + bd.sin_family = AF_INET; + bd.sin_addr.s_addr = INADDR_ANY; + bd.sin_port = htons(port); + status = bind(sock, (struct sockaddr *)&bd, sizeof(bd)); + if(status<0){ + socket_close(sock); + return INVALID_SOCKET; + } } return sock; @@ -301,16 +309,22 @@ struct sockaddr_in *pFrom) { int status; struct one_client *pclient; - struct extmsg confirm; - struct extmsg noop; + caHdr confirm; + caHdr noop; + + if (pFrom->sin_family != AF_INET) { + return; + } for( pclient = (struct one_client *) ellFirst(&client_list); pclient; pclient = (struct one_client *) ellNext(&pclient->node)){ if( pFrom->sin_port == pclient->from.sin_port && - pFrom->sin_addr.s_addr == pclient->from.sin_addr.s_addr) + pFrom->sin_addr.s_addr == + pclient->from.sin_addr.s_addr) { break; + } } if(!pclient){ @@ -322,7 +336,7 @@ struct sockaddr_in *pFrom) } pclient->sock = makeSocket(PORT_ANY); - if (!pclient->sock) { + if (pclient->sock==INVALID_SOCKET) { free(pclient); ca_printf("%s: no client sock because \"%s\"\n", __FILE__, @@ -336,8 +350,9 @@ struct sockaddr_in *pFrom) if (status<0) { socket_close(pclient->sock); free(pclient); - ca_printf("%s: unable to connect client sock\n", - __FILE__); + ca_printf( + "%s: unable to connect client sock because \"%s\"\n", + __FILE__, strerror(errno)); return; } @@ -381,7 +396,7 @@ struct sockaddr_in *pFrom) * accumulate sockets when there are no beacons */ memset((char *)&noop, '\0', sizeof(noop)); - confirm.m_cmmd = htons(IOC_NOOP); + confirm.m_cmmd = htons(CA_PROTO_NOOP); fanOut(pFrom, (char *)&noop, sizeof(noop)); } diff --git a/src/ca/service.c b/src/ca/service.c index d2963eb18..521c077db 100644 --- a/src/ca/service.c +++ b/src/ca/service.c @@ -89,6 +89,8 @@ IIU *piiu, const struct in_addr *pnet_addr ); +LOCAL void verifyChanAndDisconnect(IIU *piiu, enum channel_state state); + #ifdef CONVERSION_REQUIRED extern CACVRTFUNC *cac_dbr_cvrt[]; #endif /*CONVERSION_REQUIRED*/ @@ -243,14 +245,14 @@ const struct in_addr *pnet_addr switch (piiu->curMsg.m_cmmd) { - case IOC_NOOP: + case CA_PROTO_NOOP: break; - case IOC_ECHO: + case CA_PROTO_ECHO: piiu->echoPending = FALSE; break; - case IOC_WRITE_NOTIFY: + case CA_PROTO_WRITE_NOTIFY: { struct event_handler_args args; @@ -297,7 +299,7 @@ const struct in_addr *pnet_addr break; } - case IOC_READ_NOTIFY: + case CA_PROTO_READ_NOTIFY: { struct event_handler_args args; @@ -366,7 +368,7 @@ const struct in_addr *pnet_addr break; } - case IOC_EVENT_ADD: + case CA_PROTO_EVENT_ADD: { int v41; struct event_handler_args args; @@ -446,7 +448,7 @@ const struct in_addr *pnet_addr break; } - case IOC_READ: + case CA_PROTO_READ: { evid pIOBlock; @@ -505,15 +507,15 @@ const struct in_addr *pnet_addr UNLOCK; break; } - case IOC_SEARCH: + case CA_PROTO_SEARCH: perform_claim_channel(piiu, pnet_addr); break; - case IOC_READ_SYNC: + case CA_PROTO_READ_SYNC: piiu->read_seq++; break; - case IOC_RSRV_IS_UP: + case CA_PROTO_RSRV_IS_UP: LOCK; { struct in_addr ina; @@ -531,20 +533,20 @@ const struct in_addr *pnet_addr #endif break; - case IOC_NOT_FOUND: + case CA_PROTO_NOT_FOUND: break; - case IOC_CLEAR_CHANNEL: + case CA_PROTO_CLEAR_CHANNEL: clearChannelResources (piiu->curMsg.m_available); break; - case IOC_ERROR: + case CA_PROTO_ERROR: { ELLLIST *pList = NULL; evid monix; char nameBuf[64]; char context[255]; - struct extmsg *req = piiu->pCurData; + caHdr *req = piiu->pCurData; int op; struct exception_handler_args args; @@ -559,7 +561,7 @@ const struct in_addr *pnet_addr caHostFromInetAddr(pnet_addr, nameBuf, sizeof(nameBuf)); - if (piiu->curMsg.m_postsize > sizeof(struct extmsg)){ + if (piiu->curMsg.m_postsize > sizeof(caHdr)){ sprintf(context, "detected by: %s for: %s", nameBuf, @@ -579,14 +581,14 @@ const struct in_addr *pnet_addr args.addr = NULL; LOCK; switch (ntohs(req->m_cmmd)) { - case IOC_READ_NOTIFY: + case CA_PROTO_READ_NOTIFY: monix = (evid) bucketLookupItemUnsignedId( pFastBucket, &req->m_available); pList = &pend_read_list; op = CA_OP_GET; break; - case IOC_READ: + case CA_PROTO_READ: monix = (evid) bucketLookupItemUnsignedId( pFastBucket, &req->m_available); @@ -596,20 +598,20 @@ const struct in_addr *pnet_addr pList = &pend_read_list; op = CA_OP_GET; break; - case IOC_WRITE_NOTIFY: + case CA_PROTO_WRITE_NOTIFY: monix = (evid) bucketLookupItemUnsignedId( pFastBucket, &req->m_available); pList = &pend_write_list; op = CA_OP_PUT; break; - case IOC_WRITE: + case CA_PROTO_WRITE: op = CA_OP_PUT; break; - case IOC_SEARCH: + case CA_PROTO_SEARCH: op = CA_OP_SEARCH; break; - case IOC_EVENT_ADD: + case CA_PROTO_EVENT_ADD: monix = (evid) bucketLookupItemUnsignedId( pFastBucket, &req->m_available); @@ -618,7 +620,7 @@ const struct in_addr *pnet_addr pList = &monix->chan->eventq; } break; - case IOC_EVENT_CANCEL: + case CA_PROTO_EVENT_CANCEL: monix = (evid) bucketLookupItemUnsignedId( pFastBucket, &req->m_available); @@ -651,7 +653,7 @@ const struct in_addr *pnet_addr UNLOCKEVENTS; break; } - case IOC_ACCESS_RIGHTS: + case CA_PROTO_ACCESS_RIGHTS: { int ar; chid chan; @@ -668,8 +670,8 @@ const struct in_addr *pnet_addr } ar = ntohl (piiu->curMsg.m_available); - chan->ar.read_access = (ar&CA_ACCESS_RIGHT_READ)?1:0; - chan->ar.write_access = (ar&CA_ACCESS_RIGHT_WRITE)?1:0; + chan->ar.read_access = (ar&CA_PROTO_ACCESS_RIGHT_READ)?1:0; + chan->ar.write_access = (ar&CA_PROTO_ACCESS_RIGHT_WRITE)?1:0; if (chan->pAccessRightsFunc) { struct access_rights_handler_args args; @@ -680,7 +682,7 @@ const struct in_addr *pnet_addr } break; } - case IOC_CLAIM_CIU: + case CA_PROTO_CLAIM_CIU: { chid chan; @@ -702,31 +704,10 @@ const struct in_addr *pnet_addr reconnect_channel(piiu, chan); break; } - case IOC_CLAIM_CIU_FAILED: - { - chid chan; - - LOCK; - chan = bucketLookupItemUnsignedId( - pSlowBucket, &piiu->curMsg.m_cid); - UNLOCK; - if(!chan){ - /* - * end up here if they delete the channel - * prior to this response - */ - break; - } - - /* - * need to move the channel back to the cast IIU - * (so we will be able to reconnect) - */ - LOCK; - cacDisconnectChannel(chan, FALSE); - UNLOCK; + case CA_PROTO_CLAIM_CIU_FAILED: + case CA_PROTO_SERVER_DISCONN: + verifyChanAndDisconnect(piiu, cs_conn); break; - } default: ca_printf("CAC: post_msg(): Corrupt cmd in msg %x\n", piiu->curMsg.m_cmmd); @@ -737,6 +718,33 @@ const struct in_addr *pnet_addr return OK; } +/* + * verifyChanAndDisconnect() + */ +LOCAL void verifyChanAndDisconnect(IIU *piiu, enum channel_state state) +{ + chid chan; + + LOCK; + chan = bucketLookupItemUnsignedId( + pSlowBucket, &piiu->curMsg.m_cid); + if (!chan) { + /* + * end up here if they delete the channel + * prior to this response + */ + UNLOCK; + return; + } + + /* + * need to move the channel back to the cast IIU + * (so we will be able to reconnect) + */ + cacDisconnectChannel(chan, chan->state); + UNLOCK; +} + /* * @@ -903,7 +911,7 @@ const struct in_addr *pnet_addr v42 = CA_V42( CA_PROTOCOL_VERSION, allocpiiu->minor_version_number); - if(!v42){ + if (!v42) { reconnect_channel(piiu, chan); } } @@ -921,13 +929,19 @@ chid chan enum channel_state prev_cs; int v41; + prev_cs = chan->state; + if (prev_cs == cs_conn) { + ca_printf("Ignored connect response to connected channel\n"); + return; + } + LOCK; v41 = CA_V41( CA_PROTOCOL_VERSION, ((IIU *)chan->piiu)->minor_version_number); - /* Update rmt chid fields from extmsg fields */ + /* Update rmt chid fields from caHdr fields */ chan->type = piiu->curMsg.m_type; chan->count = piiu->curMsg.m_count; @@ -937,7 +951,6 @@ chid chan * ca_request_event() so their channel * connect tests wont fail */ - prev_cs = chan->state; chan->state = cs_conn; /* @@ -996,30 +1009,3 @@ chid chan } } - -/* - * - * cas_io_done() - * - * - */ -void cac_io_done(int lock) -{ - struct pending_io_event *pioe; - - if(ioeventlist.count==0) - return; - - if(lock){ - LOCK; - } - - while(pioe = (struct pending_io_event *) ellGet(&ioeventlist)){ - (*pioe->io_done_sub)(pioe->io_done_arg); - free(pioe); - } - - if(lock){ - UNLOCK; - } -} diff --git a/src/ca/syncgrp.c b/src/ca/syncgrp.c index e54baf401..38854c774 100644 --- a/src/ca/syncgrp.c +++ b/src/ca/syncgrp.c @@ -29,6 +29,9 @@ * Modification Log: * ----------------- * $Log$ + * Revision 1.18 1995/10/12 01:36:39 jhill + * New ca_flush_io() mechanism + * * Revision 1.17 1995/09/29 22:13:59 jhill * check for nill dbr pointer * @@ -330,6 +333,42 @@ int epicsShareAPI ca_sg_reset(CA_SYNC_GID gid) return ECA_NORMAL; } + +/* + * ca_sg_stat + */ +int epicsShareAPI ca_sg_stat(CA_SYNC_GID gid) +{ + CASG *pcasg; + CASGOP *pcasgop; + + LOCK; + pcasg = bucketLookupItemUnsignedId(pSlowBucket, &gid); + if(!pcasg || pcasg->magic != CASG_MAGIC){ + UNLOCK; + printf("Bad Sync Group Id\n"); + return ECA_BADSYNCGRP; + } + UNLOCK; + + printf("Sync Group: id=%u, magic=%lu, opPend=%u, seqNo=%u\n", + pcasg->id, pcasg->magic, pcasg->opPendCount, + pcasg->seqNo); + + LOCK; + pcasgop = (CASGOP *) ellFirst(&ca_static->activeCASGOP); + while (pcasgop) { + if (pcasg->id == pcasgop->id) { + printf( + "pending op: id=%u pVal=%x, magic=%lu seqNo=%u\n", + pcasgop->id, (unsigned)pcasgop->pValue, pcasgop->magic, + pcasgop->seqNo); + } + pcasgop = (CASGOP *) ellNext(&pcasgop->node); + } + return ECA_NORMAL; +} + /* * ca_sg_test @@ -354,8 +393,6 @@ int epicsShareAPI ca_sg_test(CA_SYNC_GID gid) } } - - /* * ca_sg_array_put() @@ -410,6 +447,7 @@ void *pvalue) if(status != ECA_NORMAL){ LOCK; + assert(pcasg->opPendCount>=1u); pcasg->opPendCount--; ellDelete(&ca_static->activeCASGOP, &pcasgop->node); ellAdd(&ca_static->freeCASGOP, &pcasgop->node); @@ -475,6 +513,7 @@ void *pvalue) if(status != ECA_NORMAL){ LOCK; + assert(pcasg->opPendCount>=1u); pcasg->opPendCount--; ellDelete(&ca_static->activeCASGOP, &pcasgop->node); ellAdd(&ca_static->freeCASGOP, &pcasgop->node); @@ -511,7 +550,7 @@ LOCAL void io_complete(struct event_handler_args args) } assert(pcasg->magic == CASG_MAGIC); - + assert(pcasg->id == pcasgop->id); if(!(args.status&CA_M_SUCCESS)){ ca_printf( @@ -534,9 +573,8 @@ LOCAL void io_complete(struct event_handler_args args) /* * decrement the outstanding IO ops count */ - if(pcasg->opPendCount!=0){ - pcasg->opPendCount--; - } + assert(pcasg->opPendCount>=1u); + pcasg->opPendCount--; UNLOCK; diff --git a/src/ca/vxWorks_depen.c b/src/ca/vxWorks_depen.c index e31d0f1d0..f3f5ffc79 100644 --- a/src/ca/vxWorks_depen.c +++ b/src/ca/vxWorks_depen.c @@ -29,6 +29,9 @@ * Modification Log: * ----------------- * $Log$ + * Revision 1.21 1995/10/18 16:44:36 jhill + * select time out must be greater than a vxWorks tick + * * Revision 1.20 1995/10/12 01:35:31 jhill * Moved cac_mux_io() to iocinf.c * @@ -672,14 +675,16 @@ int ca_import_cancel(int tid) TVIU *ptviu; LOCK; - ptviu = (TVIU *) ca_static->ca_taskVarList.node.next; - while(ptviu){ + ptviu = (TVIU *) ellFirst(&ca_static->ca_taskVarList); + while (ptviu) { if(ptviu->tid == tid){ break; } + ptviu = (TVIU *) ellNext(&ptviu->node); } if(!ptviu){ + UNLOCK; return ECA_NOCACTX; }