From 97451d9aaec92613e9eb5f22c61eae050342ee2c Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Mon, 4 Nov 1991 17:20:53 +0000 Subject: [PATCH] *** empty log message *** --- src/ca/access.c | 15 ++-- src/ca/acctst.c | 13 ++-- src/ca/conn.c | 13 ++-- src/ca/flow_control.c | 28 +++++-- src/ca/iocinf.c | 160 +++++++++++++++++++++++----------------- src/ca/iocinf.h | 37 ++++++---- src/ca/os_depen.h | 3 + src/ca/repeater.c | 33 ++++++--- src/ca/service.c | 100 +++++++++++++++---------- src/rsrv/camessage.c | 110 ++++++++++++++++----------- src/rsrv/camsgtask.c | 6 +- src/rsrv/caserverio.c | 26 ++++--- src/rsrv/caservertask.c | 19 +++-- src/rsrv/cast_server.c | 4 +- src/rsrv/server.h | 11 +-- 15 files changed, 351 insertions(+), 227 deletions(-) diff --git a/src/ca/access.c b/src/ca/access.c index 14f5565ac..7646cafcd 100644 --- a/src/ca/access.c +++ b/src/ca/access.c @@ -62,24 +62,27 @@ /************************************************************************/ /*_end */ +/* + * allocate error message string array + * here so I can use sizeof + */ +#define CA_ERROR_GLBLSOURCE + #if defined(VMS) # include stsdef.h # include ssdef.h # include psldef.h # include prcdef.h # include descrip.h +#elif defined(UNIX) #elif defined(vxWorks) # include # include # include +#else + @@@@ dont compile @@@@ #endif -/* - * allocate error message string array - * here so I can use sizeof - */ -#define CA_ERROR_GLBLSOURCE - /* * allocate db_access message strings here */ diff --git a/src/ca/acctst.c b/src/ca/acctst.c index 47812cf67..a5776efce 100644 --- a/src/ca/acctst.c +++ b/src/ca/acctst.c @@ -7,17 +7,16 @@ /* System includes */ -#ifdef UNIX -#include -#endif - -#include -#ifdef vxWorks -#include +#if defined(UNIX) +# include +#elif defined(vxWorks) +# include +# include #endif #include #include +#include /* diff --git a/src/ca/conn.c b/src/ca/conn.c index e602e3b0e..8d0f9c606 100644 --- a/src/ca/conn.c +++ b/src/ca/conn.c @@ -24,11 +24,14 @@ /* */ /************************************************************************/ /*_end */ -#ifdef UNIX -#include +#if defined(UNIX) +# include +#elif defined(VMS) +#elif defined(vxWorks) +#else + @@@@ dont compile @@@@ #endif -#include #include #include #include @@ -108,8 +111,8 @@ char silent; #endif if(!silent && retry_cnt_no_handler){ - sprintf(string, "%d channels outstanding", retry_cnt); - ca_signal(ECA_CHIDRETRY, string); + sprintf(sprintf_buf, "%d channels outstanding", retry_cnt); + ca_signal(ECA_CHIDRETRY, sprintf_buf); } } diff --git a/src/ca/flow_control.c b/src/ca/flow_control.c index 0ce015d55..d58d0af6f 100644 --- a/src/ca/flow_control.c +++ b/src/ca/flow_control.c @@ -34,13 +34,29 @@ /*_end */ -#include -#include -#include -#include -#ifdef vxWorks -#include +#if defined(vxWorks) +# include +# include +# include +# include +# ifdef V5_vxWorks +# include +# else +# include +# endif +#elif defined(VMS) +# include +# include +# include +#elif defined(UNIX) +# include +# include +# include +#else + @@@@ dont compile @@@@ #endif + +#include #include #include #include diff --git a/src/ca/iocinf.c b/src/ca/iocinf.c index 50e797b93..88ba66dd1 100644 --- a/src/ca/iocinf.c +++ b/src/ca/iocinf.c @@ -18,6 +18,12 @@ /* each message */ /* 071291 joh no longer sends id at TCP connect */ /* 082791 joh split send_msg() into two subroutines */ +/* 110491 joh call recv_msg to free up deadlock only if */ +/* client blocks on send as before */ +/* 110491 joh mark all channels disconnected prior to */ +/* calling the first connection handler on */ +/* disconnect */ +/* 110491 joh allow cac_send_msg() to be called recursively */ /* */ /*_begin */ /************************************************************************/ @@ -48,21 +54,23 @@ #if defined(VMS) # include -# include # include -# include -# include -# include -# include -# include -# include +# include +# define __TIME /* dont include VMS CC time.h under MULTINET */ +# include +# include +# include +# include +# include +# include +# include #elif defined(UNIX) -# include -# include -# include -# include -# include -# include +# include +# include +# include +# include +# include +# include #elif defined(vxWorks) # include # ifdef V5_vxWorks @@ -464,7 +472,7 @@ struct ioc_in_use *piiu; /* Set up recv thread for VMS */ -#ifdef VMS +# if defined(VMS) { /* * request to be informed of future IO @@ -487,8 +495,7 @@ struct ioc_in_use *piiu; exit(); } } -# endif -# ifdef vxWorks +# elif defined(vxWorks) { void recv_task(); int pri; @@ -518,7 +525,7 @@ struct ioc_in_use *piiu; piiu->recv_tid = status; } -#endif +# endif return ECA_NORMAL; } @@ -582,12 +589,14 @@ void cac_send_msg() if(!ca_static->ca_repeater_contacted) notify_ca_repeater(); +#if 0 /* * dont call it recursively */ if(send_msg_active){ return; } +#endif send_msg_active++; @@ -596,8 +605,10 @@ void cac_send_msg() * */ while(TRUE){ + + done = TRUE; - for(piiu=iiu;piiu<&iiu[nxtiiu];piiu++){ + for(piiu=iiu; piiu<&iiu[nxtiiu]; piiu++){ if(!piiu->send->stk) continue; @@ -615,7 +626,7 @@ void cac_send_msg() if(done){ /* * allways double check that we - * are finished incase somthing was added + * are finished in case somthing was added * to a send buffer and a recursive * ca_send_msg() call was refused above */ @@ -628,17 +639,6 @@ void cac_send_msg() break; } - /* - * Ensure we do not accumulate extra recv - * messages (for TCP) - */ - /* - * free up push pull deadlock only - * if recv not already in progress - */ - if(post_msg_active==0) - recv_msg_select(¬imeout); - if(retry_count-- <= 0){ char *iocname; struct in_addr *inaddr; @@ -647,7 +647,6 @@ void cac_send_msg() inaddr = &piiu->sock_addr.sin_addr; iocname = host_from_addr(inaddr); #ifdef CLOSE_ON_EXPIRED - ca_signal(ECA_DLCKREST, iocname); close_ioc(piiu); #else @@ -685,24 +684,18 @@ register struct ioc_in_use *piiu; pmsg = (void *) piiu->send->buf; while(TRUE){ + int sock; + + if(piiu->conn_up){ - /* - * send UDP or TCP message depending - * on whether this channel has a TCP - * connection yet - * + /* + * use TCP if connection exists */ - status = sendto( - piiu->sock_chan, - pmsg, - cnt, - 0, - &piiu->sock_addr, - sizeof(piiu->sock_addr)); + sock = piiu->sock_chan; } else{ /* - * send UDP message + * use UDP * * NOTE: this does not use a broadcast * if the location of the channel is @@ -711,26 +704,30 @@ register struct ioc_in_use *piiu; * (piiu->sock_addr points to the * known address) */ - status = sendto( - iiu[BROADCAST_IIU].sock_chan, - pmsg, - cnt, - 0, - &piiu->sock_addr, - sizeof(piiu->sock_addr)); + if(!iiu[BROADCAST_IIU].conn_up) + return ERROR; + + sock = iiu[BROADCAST_IIU].sock_chan; } + status = sendto( + sock, + pmsg, + cnt, + 0, + &piiu->sock_addr, + sizeof(piiu->sock_addr)); /* * normal fast exit */ - if(status == cnt) + if(status == cnt){ break; - - if(status>=0){ + } + else if(status>=0){ if(status>cnt){ ca_signal( ECA_INTERNAL, - "more sent than requested"); + "more sent than requested ?"); } cnt = cnt-status; @@ -748,14 +745,25 @@ register struct ioc_in_use *piiu; cnt); piiu->send->stk = cnt; } + /* + * Ensure we do not accumulate extra recv + * messages (for TCP) + * + * frees up push pull deadlock only + * if recv not already in progress + */ + if(post_msg_active==0) + recv_msg_select(¬imeout); + return ERROR; } #endif else{ - if(MYERRNO != EPIPE && MYERRNO != ECONNRESET) - printf( - "CA: error on socket send() %d\n", - MYERRNO); + if(MYERRNO != EPIPE && MYERRNO != ECONNRESET){ + printf( + "CA: error on socket send() %d\n", + MYERRNO); + } close_ioc(piiu); return OK; } @@ -884,8 +892,7 @@ struct ioc_in_use *piiu; void tcp_recv_msg(piiu) struct ioc_in_use *piiu; { - unsigned long byte_cnt; - unsigned long byte_sum; + long byte_cnt; int status; int timeoutcnt; struct buffer *rcvb = piiu->recv; @@ -926,9 +933,9 @@ struct ioc_in_use *piiu; } - byte_cnt = (unsigned long) status; + byte_cnt = (long) status; if(byte_cnt>MAX_MSG_SIZE){ - printf( "recv_msg(): message overflow %u\n", + printf( "recv_msg(): message overflow %l\n", byte_cnt-MAX_MSG_SIZE); LOCK; close_ioc(piiu); @@ -945,7 +952,7 @@ struct ioc_in_use *piiu; &byte_cnt, &piiu->sock_addr.sin_addr, piiu); - if(byte_cnt){ + if(byte_cnt>0){ /* * realign partial message */ @@ -985,8 +992,7 @@ struct ioc_in_use *piiu; char *ptr; unsigned nchars; struct msglog{ - unsigned nbytes; - unsigned RISC_pad; + long nbytes; struct sockaddr_in addr; }; struct msglog *pmsglog; @@ -1024,7 +1030,7 @@ struct ioc_in_use *piiu; * log the msg size */ rcvb->stk += status; - pmsglog->nbytes = (unsigned long) status; + pmsglog->nbytes = (long) status; #ifdef DEBUG printf("recieved a udp reply of %d bytes\n",byte_cnt); #endif @@ -1048,7 +1054,7 @@ struct ioc_in_use *piiu; pmsglog = (struct msglog *) rcvb->buf; while(pmsglog < (struct msglog *)&rcvb->buf[rcvb->stk]){ - unsigned long msgcount; + long msgcount; /* post message to the user */ msgcount = pmsglog->nbytes; @@ -1056,7 +1062,7 @@ struct ioc_in_use *piiu; &msgcount, &pmsglog->addr.sin_addr, piiu); - if(msgcount){ + if(msgcount != 0){ printf( "CA: UDP alignment problem %d\n", msgcount); } @@ -1203,12 +1209,25 @@ struct ioc_in_use *piiu; FD_CLR(piiu->sock_chan, &readch); # endif + /* + * Mark all of their channels disconnected + * prior to calling handlers incase the + * handler tries to use a channel before + * I mark it disconnected. + */ chix = (chid) &piiu->chidlist.node.next; while(chix = (chid) chix->node.next){ chix->type = TYPENOTCONN; chix->count = 0; chix->state = cs_prev_conn; chix->paddr = NULL; + } + + /* + * call their connection handler as required + */ + chix = (chid) &piiu->chidlist.node.next; + while(chix = (chid) chix->node.next){ if(chix->connection_func){ args.chid = chix; args.op = CA_OP_CONN_DOWN; @@ -1234,6 +1253,9 @@ struct ioc_in_use *piiu; ECA_DISCONN, host_from_addr(&piiu->sock_addr.sin_addr)); + if(piiu == &iiu[BROADCAST_IIU]){ + ca_signal(ECA_INTERNAL, "Unable to perform UDP broadcast\n"); + } } diff --git a/src/ca/iocinf.h b/src/ca/iocinf.h index e1d9b3226..87e3db541 100644 --- a/src/ca/iocinf.h +++ b/src/ca/iocinf.h @@ -16,6 +16,7 @@ /* .05 082791 joh declaration of ca_request_event() */ /* .06 082791 joh added send message in progress flag */ /* .07 091691 joh moved channel_state enum to cadef.h for export */ +/* .08 102991 joh added sprintf buffer */ /* */ /*_begin */ /************************************************************************/ @@ -41,30 +42,34 @@ #ifndef INCiocinfh #define INCiocinfh +#define DONT_COMPILE @@@@ dont compile in this case @@@@ + +#if defined(UNIX) +# include +# include +#elif defined(VMS) +# include +# include +# include +#elif defined(vxWorks) +# ifdef V5_vxWorks +# include +# else +# include +# endif +# include +#else + DONT_COMPILE +#endif #ifndef INClstLibh # include #endif -#ifndef _TYPES_ -# include -#endif - -#ifndef __IN_HEADER__ -# include -#endif - -#ifdef VMS -# include -#endif - #ifndef INCos_depenh # include #endif -#define DONT_COMPILE @@@@ dont compile in this case @@@@ - - /* throw out requests prior to last ECA_TIMEOUT from ca_pend */ #define VALID_MSG(PIIU) (piiu->read_seq == piiu->cur_read_seq) @@ -133,6 +138,7 @@ typedef unsigned long ca_time; #define fd_register_arg (ca_static->ca_fd_register_arg) #define post_msg_active (ca_static->ca_post_msg_active) #define send_msg_active (ca_static->ca_send_msg_active) +#define sprintf_buf (ca_static->ca_sprintf_buf) #if defined(UNIX) # define readch (ca_static->ca_readch) @@ -172,6 +178,7 @@ struct ca_static{ unsigned short ca_send_msg_active; short ca_cast_available; struct in_addr ca_castaddr; + char ca_sprintf_buf[128]; #if defined(UNIX) fd_set ca_readch; #elif defined(VMS) diff --git a/src/ca/os_depen.h b/src/ca/os_depen.h index bb582423e..234907cd2 100644 --- a/src/ca/os_depen.h +++ b/src/ca/os_depen.h @@ -25,6 +25,9 @@ # include # endif #elif defined(vxWorks) +# ifndef INCvxWorksh +# include +# endif # ifndef INCfast_lockh # include # endif diff --git a/src/ca/repeater.c b/src/ca/repeater.c index 117098d15..a338cafc9 100644 --- a/src/ca/repeater.c +++ b/src/ca/repeater.c @@ -49,18 +49,31 @@ * */ -#include -#include -#ifdef VMS -#include +#if defined(VMS) +# include +# include +# include +# include +# include +# include +#elif defined(UNIX) +# include +# include +# include +# include +# include +#elif defined(vxWorks) +# include +# include +# include +# include +# include +# include +#else + @@@@ dont compile @@@@ #endif -#include -#include -#include -#include -#include - +#include #include #include diff --git a/src/ca/service.c b/src/ca/service.c index 8327a1ce1..ac3edd541 100644 --- a/src/ca/service.c +++ b/src/ca/service.c @@ -25,6 +25,7 @@ /* problems with duplicate port assigned to */ /* client after reboot go away */ /* 072391 joh added event locking for vxWorks */ +/* 100391 joh added missing ntohs() for the VAX */ /* */ /*_begin */ /************************************************************************/ @@ -47,25 +48,32 @@ /************************************************************************/ /*_end */ -#ifdef VMS -#include +#if defined(VMS) +# include +# include +#elif defined(UNIX) +# include +# include +#elif defined(vxWorks) +# include +# ifdef V5_vxWorks +# include +# else +# include +# endif +#else + @@@@ dont compile @@@@ #endif -#ifdef UNIX -#include -#endif +#include +#include +#include +#include +#include +#include -#include - -#include -#include -#include -#include -#include -#include - -void reconnect_channel(); -void ca_request_event(); +void reconnect_channel(); +void ca_request_event(); #define BUFSTAT printf("expected %d left %d\n",msgcnt,*pbufcnt); @@ -79,10 +87,10 @@ void ca_request_event(); */ void post_msg(hdrptr, pbufcnt, pnet_addr, piiu) - register struct extmsg *hdrptr; - register unsigned long *pbufcnt; - struct in_addr *pnet_addr; - struct ioc_in_use *piiu; + register struct extmsg *hdrptr; + register long *pbufcnt; + struct in_addr *pnet_addr; + struct ioc_in_use *piiu; { evid monix; long msgcnt; @@ -246,6 +254,16 @@ post_msg(hdrptr, pbufcnt, pnet_addr, piiu) chid chan = (chid) hdrptr->m_pciu; unsigned size; + /* + * ignore IOC_READ_BUILDS after + * connection occurs + */ + if(t_cmmd == IOC_READ_BUILD){ + if(chan->state == cs_conn){ + break; + } + } + /* * only count get returns if from the current * read seq @@ -294,21 +312,21 @@ post_msg(hdrptr, pbufcnt, pnet_addr, piiu) /* * ignore broadcast replies for deleted channels * + * lock required for client_channel_exists() + * lock required around use of the sprintf buffer */ LOCK; status = client_channel_exists(chan); - UNLOCK; - if (!status) { - char msg[64]; - sprintf( - msg, - "Search reply from %s", + sprintf_buf, + "Chid %x Search reply from %s", + chan, host_from_addr(pnet_addr)); - ca_signal(ECA_NOCHANMSG,msg); + ca_signal(ECA_NOCHANMSG, sprintf_buf); break; } + UNLOCK; chpiiu = &iiu[chan->iocix]; @@ -317,13 +335,12 @@ post_msg(hdrptr, pbufcnt, pnet_addr, piiu) if (chpiiu->sock_addr.sin_addr.s_addr == pnet_addr->s_addr) { printf(" "); -#ifdef UNIX - fflush(stdout); -#endif +# ifdef UNIX + fflush(stdout); +# endif } else { - char msg[256]; - char acc[64]; - char rej[64]; + char acc[128]; + char rej[128]; sprintf(acc, "%s", @@ -332,26 +349,29 @@ post_msg(hdrptr, pbufcnt, pnet_addr, piiu) sprintf(rej, "%s", host_from_addr(pnet_addr)); + LOCK; sprintf( - msg, + sprintf_buf, "Channel: %s Accepted: %s Rejected: %s ", chan + 1, acc, rej); - ca_signal(ECA_DBLCHNL, msg); + ca_signal(ECA_DBLCHNL, sprintf_buf); + UNLOCK; } - +# ifdef IOC_READ_FOLLOWING_BUILD /* - * IOC_BUILD messages allways have a + * IOC_BUILD messages always have a * IOC_READ msg following. (IOC_BUILD * messages are sometimes followed by * error messages which are ignored * on double replies) */ - if (t_cmmd == IOC_BUILD) + if (t_cmmd == IOC_BUILD){ msgcnt += sizeof(struct extmsg) + - (hdrptr + 1)->m_postsize; - + ntohs((hdrptr + 1)->m_postsize); + } +# endif break; } reconnect_channel(hdrptr, pnet_addr); diff --git a/src/rsrv/camessage.c b/src/rsrv/camessage.c index 5533eab5e..b725e0f87 100644 --- a/src/rsrv/camessage.c +++ b/src/rsrv/camessage.c @@ -37,6 +37,7 @@ * .05 joh 082691 use db_post_single_event() instead of read_reply() * to avoid deadlock condition between the client * and the server. + * .06 joh 110491 lock added for IOC_CLAIM_CIU command */ #include @@ -66,7 +67,7 @@ void search_fail_reply(); /* - * CAMESSSAGE() + * CAMESSAGE() * * */ @@ -119,13 +120,13 @@ camessage(client, recv) pevext = (struct event_ext *) malloc(size); if (!pevext) { - LOCK_SEND(client); + LOCK_CLIENT(client); send_err( mp, ECA_ALLOCMEM, client, RECORD_NAME(MPTOPADDR(mp))); - UNLOCK_SEND(client); + UNLOCK_CLIENT(client); break; } } @@ -148,13 +149,13 @@ camessage(client, recv) (unsigned) ((struct monops *) mp)->m_info.m_mask, pevext + 1); if (status == ERROR) { - LOCK_SEND(client); + LOCK_CLIENT(client); send_err( mp, ECA_ADDFAIL, client, RECORD_NAME(MPTOPADDR(mp))); - UNLOCK_SEND(client); + UNLOCK_CLIENT(client); } /* @@ -235,22 +236,24 @@ camessage(client, recv) mp->m_count ); if (status < 0) { - LOCK_SEND(client); + LOCK_CLIENT(client); send_err( mp, ECA_PUTFAIL, client, RECORD_NAME(MPTOPADDR(mp))); - UNLOCK_SEND(client); + UNLOCK_CLIENT(client); } break; case IOC_EVENTS_ON: { + struct event_ext evext; struct channel_in_use *pciu = (struct channel_in_use *) & client->addrq; client->eventsoff = FALSE; + LOCK_CLIENT(client); while (pciu = (struct channel_in_use *) pciu->node.next) { @@ -260,8 +263,10 @@ camessage(client, recv) pevext->node.next){ if (pevext->modified) { + evext = *pevext; + evext.send_lock = FALSE; read_reply( - pevext, + &evext, MPTOPADDR(&pevext->msg), TRUE, NULL); @@ -269,6 +274,7 @@ camessage(client, recv) } } } + UNLOCK_CLIENT(client); break; } case IOC_EVENTS_OFF: @@ -290,26 +296,31 @@ camessage(client, recv) * channel in use block prior to * timeout must reconnect */ + LOCK_CLIENT(prsrv_cast_client); status = lstFind( &prsrv_cast_client->addrq, mp->m_pciu); - if(status<0){ + if(status >= 0){ + lstDelete( + &prsrv_cast_client->addrq, + mp->m_pciu); + } + UNLOCK_CLIENT(prsrv_cast_client); + if(status < 0){ free_client(client); + logMsg("cas: client timeout disconnect\n"); exit(); } - - lstDelete( - &prsrv_cast_client->addrq, - mp->m_pciu); + LOCK_CLIENT(client); lstAdd(&client->addrq, mp->m_pciu); + UNLOCK_CLIENT(client); break; default: log_header(mp, nmsg); - LOCK_SEND(client); + LOCK_CLIENT(client); send_err(mp, ECA_INTERNAL, client, "Invalid Msg"); - UNLOCK_SEND(client); + UNLOCK_CLIENT(client); return ERROR; - } recv->stk += msgsize; @@ -354,18 +365,18 @@ struct client *client; /* * send delete confirmed message */ - LOCK_SEND(client); + LOCK_CLIENT(client); reply = (struct extmsg *) ALLOC_MSG(client, 0); if (!reply) { - UNLOCK_SEND(client); + UNLOCK_CLIENT(client); taskSuspend(0); } *reply = *mp; END_MSG(client); - UNLOCK_SEND(client); - lstDelete(&client->addrq, pciu); + UNLOCK_CLIENT(client); + FASTLOCK(&rsrv_free_addrq_lck); lstAdd(&rsrv_free_addrq, pciu); FASTUNLOCK(&rsrv_free_addrq_lck); @@ -408,17 +419,17 @@ event_cancel_reply(mp, client) /* * send delete confirmed message */ - LOCK_SEND(client); + LOCK_CLIENT(client); reply = (struct extmsg *) ALLOC_MSG(client, 0); if (!reply) { - UNLOCK_SEND(client); + UNLOCK_CLIENT(client); taskSuspend(0); } *reply = pevext->msg; reply->m_postsize = 0; END_MSG(client); - UNLOCK_SEND(client); + UNLOCK_CLIENT(client); FASTLOCK(&rsrv_free_eventq_lck); lstAdd(&rsrv_free_eventq, pevext); @@ -429,9 +440,9 @@ event_cancel_reply(mp, client) /* * Not Found- return an error message */ - LOCK_SEND(client); + LOCK_CLIENT(client); send_err(mp, ECA_BADMONID, client, NULL); - UNLOCK_SEND(client); + UNLOCK_CLIENT(client); return; } @@ -465,13 +476,13 @@ void *pfl; return; } if (pevext->send_lock) - LOCK_SEND(client); + LOCK_CLIENT(client); reply = (struct extmsg *) ALLOC_MSG(client, pevext->size); if (!reply) { send_err(mp, ECA_TOLARGE, client, RECORD_NAME(paddr)); if (pevext->send_lock) - UNLOCK_SEND(client); + UNLOCK_CLIENT(client); return; } *reply = *mp; @@ -508,7 +519,7 @@ void *pfl; } if (pevext->send_lock) - UNLOCK_SEND(client); + UNLOCK_CLIENT(client); return; } @@ -527,7 +538,7 @@ read_sync_reply(mp, client) { FAST struct extmsg *reply; - LOCK_SEND(client); + LOCK_CLIENT(client); reply = (struct extmsg *) ALLOC_MSG(client, 0); if (!reply) taskSuspend(0); @@ -536,7 +547,7 @@ read_sync_reply(mp, client) END_MSG(client); - UNLOCK_SEND(client); + UNLOCK_CLIENT(client); return; } @@ -582,34 +593,43 @@ build_reply(mp, client) if (!pchannel) { pchannel = (struct channel_in_use *) calloc(1, sizeof(*pchannel)); if (!pchannel) { - LOCK_SEND(client); + LOCK_CLIENT(client); send_err(mp, ECA_ALLOCMEM, client, RECORD_NAME(&tmp_addr)); - UNLOCK_SEND(client); + UNLOCK_CLIENT(client); return; } } pchannel->ticks_at_creation = tickGet(); pchannel->addr = tmp_addr; pchannel->chid = (void *) mp->m_pciu; - /* store the addr block in a Q so it can be deallocated */ - lstAdd(addrq, pchannel); /* - * ALLOC_MSG allways allocs at least the sizeof extmsg Large - * requested size insures both messages sent in one reply NOTE: my * UDP reliability schemes rely on both msgs in same reply Therefore * the send buffer locked while both messages are placed */ - LOCK_SEND(client); + LOCK_CLIENT(client); + + /* store the addr block in a Q so it can be deallocated */ + lstAdd(addrq, pchannel); + if (mp->m_cmmd == IOC_BUILD) { FAST short type = (mp + 1)->m_type; FAST unsigned int count = (mp + 1)->m_count; FAST unsigned int size; - size = (count - 1) * dbr_value_size[type] + dbr_size[type]; + /* + * must be large enough to hold both the search and the build-get + * reply in one UDP message. Hence the extra sizeof(*mp) added + * in below. + */ + size = sizeof(*mp) + /* search reply hdr size */ + sizeof(*mp) + /* build get reply hdr size */ + (count - 1) * /* size of n-1 array elements */ + dbr_value_size[type] + + dbr_size[type]; /* size of the structure fetched */ - get_reply = (struct extmsg *) ALLOC_MSG(client, size + sizeof(*mp)); + get_reply = (struct extmsg *) ALLOC_MSG(client, size); if (!get_reply) { /* tell them that their request is to large */ send_err(mp, ECA_TOLARGE, client, RECORD_NAME(&tmp_addr)); @@ -631,6 +651,12 @@ build_reply(mp, client) * is not flushed once each call. */ read_reply(&evext, &tmp_addr, TRUE, NULL); + + /* + * this allows extra build replies + * to be dicarded + */ + get_reply->m_cmmd = IOC_READ_BUILD; } } search_reply = (struct extmsg *) ALLOC_MSG(client, 0); @@ -646,7 +672,7 @@ build_reply(mp, client) search_reply->m_pciu = (void *) pchannel; END_MSG(client); - UNLOCK_SEND(client); + UNLOCK_CLIENT(client); return; } @@ -666,7 +692,7 @@ search_fail_reply(mp, client) { FAST struct extmsg *reply; - LOCK_SEND(client); + LOCK_CLIENT(client); reply = (struct extmsg *) ALLOC_MSG(client, 0); if (!reply) { taskSuspend(0); @@ -676,7 +702,7 @@ search_fail_reply(mp, client) reply->m_postsize = 0; END_MSG(client); - UNLOCK_SEND(client); + UNLOCK_CLIENT(client); } diff --git a/src/rsrv/camsgtask.c b/src/rsrv/camsgtask.c index 19293a543..d869ca0ea 100644 --- a/src/rsrv/camsgtask.c +++ b/src/rsrv/camsgtask.c @@ -104,12 +104,12 @@ FAST int sock; * historical reasons */ client = (struct client *) create_udp_client(NULL); - udp_to_tcp(client, sock); if (!client) { logMsg("camsgtask: client init failed\n"); close(sock); return; } + udp_to_tcp(client, sock); i = sizeof(client->addr); status = getpeername( @@ -118,7 +118,7 @@ FAST int sock; &i); if(status == ERROR){ logMsg("camsgtask: peer address fetch failed\n"); - close(sock); + free_client(client); return; } @@ -225,7 +225,7 @@ FAST int sock; printErrno(errnoGet(taskIdSelf())); cas_send_msg(client, TRUE); } - if (nchars == 0){ + else if (nchars == 0){ cas_send_msg(client, TRUE); } diff --git a/src/rsrv/caserverio.c b/src/rsrv/caserverio.c index 8ed6e09fb..46b9746e2 100644 --- a/src/rsrv/caserverio.c +++ b/src/rsrv/caserverio.c @@ -30,6 +30,7 @@ * ----------------- * .01 joh 071591 log time of last io in the client structure * .02 joh 091691 use greater than on the DEBUG level test + * .03 joh 110491 improved diagnostics */ #include @@ -54,12 +55,22 @@ int lock_needed; { int status; + if(CASDEBUG>2){ + logMsg( "Sending a message of %d bytes\n", + pclient->send.cnt); + } + if(pclient->disconnect){ + if(CASDEBUG>2){ + logMsg( "msg Discard for sock %d addr %x\n", + pclient->sock, + pclient->addr.sin_addr.s_addr); + } return; } if(lock_needed){ - LOCK_SEND(pclient); + LOCK_CLIENT(pclient); } if(pclient->send.stk){ @@ -72,17 +83,14 @@ int lock_needed; NULL, &pclient->addr, sizeof(pclient->addr)); - if(status>=0){ - if(CASDEBUG>2){ - logMsg( "Sent a message of %d bytes\n", - pclient->send.cnt); - } - } - else{ + if(status < 0){ logMsg("caserver: client unreachable\n"); logMsg("caserver: msg from vxWorks follows\n"); printErrno(errnoGet(taskIdSelf())); pclient->disconnect = TRUE; + if(pclient==prsrv_cast_client){ + taskSuspend(taskIdSelf()); + } } pclient->send.stk = 0; @@ -92,7 +100,7 @@ int lock_needed; if(lock_needed){ - UNLOCK_SEND(pclient); + UNLOCK_CLIENT(pclient); } return; diff --git a/src/rsrv/caservertask.c b/src/rsrv/caservertask.c index d8a5ba7c2..2a8ab6007 100644 --- a/src/rsrv/caservertask.c +++ b/src/rsrv/caservertask.c @@ -33,6 +33,7 @@ * client_stat(). * .03 joh 080991 close the socket if task create fails * .04 joh 090591 updated for v5 vxWorks + * .05 joh 103091 print task id and disconnect state in client_stat() */ #include @@ -272,7 +273,7 @@ struct client *client; char *pproto; unsigned long current; unsigned long delay; - + char *state[] = {"up", "down"}; if(client->proto == IPPROTO_UDP){ pproto = "UDP"; @@ -292,18 +293,20 @@ struct client *client; delay = current + (~0L - client->ticks_at_last_io); } - printf( "Socket %d, Protocol %s, secs since last interaction %d\n", + printf( "Socket=%d, Protocol=%s, tid=%x, secs since last interaction %d\n", client->sock, pproto, + client->tid, delay/sysClkRateGet()); psaddr = &client->addr; - printf("\tRemote address %u.%u.%u.%u Remote port %d\n", - (psaddr->sin_addr.s_addr & 0xff000000) >> 24, - (psaddr->sin_addr.s_addr & 0x00ff0000) >> 16, - (psaddr->sin_addr.s_addr & 0x0000ff00) >> 8, - (psaddr->sin_addr.s_addr & 0x000000ff), - psaddr->sin_port); + printf("\tRemote address %u.%u.%u.%u Remote port %d state=%s\n", + (psaddr->sin_addr.s_addr & 0xff000000) >> 24, + (psaddr->sin_addr.s_addr & 0x00ff0000) >> 16, + (psaddr->sin_addr.s_addr & 0x0000ff00) >> 8, + (psaddr->sin_addr.s_addr & 0x000000ff), + psaddr->sin_port, + state[client->disconnect?1:0]); printf("\tChannel count %d\n", lstCount(&client->addrq)); addr = (NODE *) & client->addrq; while (addr = lstNext(addr)) diff --git a/src/rsrv/cast_server.c b/src/rsrv/cast_server.c index 8ab3e9816..749bd07c9 100644 --- a/src/rsrv/cast_server.c +++ b/src/rsrv/cast_server.c @@ -337,10 +337,10 @@ unsigned sock; client->sock = sock; client->send.maxstk = MAX_UDP-sizeof(client->recv.cnt); - FASTLOCKINIT(&client->send.lock); + + FASTLOCKINIT(&client->lock); client->recv.maxstk = MAX_UDP; - FASTLOCKINIT(&client->recv.lock); return client; } diff --git a/src/rsrv/server.h b/src/rsrv/server.h index b6257ef4e..41055cbc3 100644 --- a/src/rsrv/server.h +++ b/src/rsrv/server.h @@ -34,6 +34,7 @@ * .03 joh 071291 moved time stamp from client to the * channel in use block * .04 joh 071591 added ticks at last io to the client structure + * .05 joh 103191 moved lock from msg buf to client structure * */ #ifndef INCLfast_lockh @@ -56,7 +57,6 @@ struct message_buffer{ unsigned stk; unsigned maxstk; - FAST_LOCK lock; int cnt; char buf[MAX_MSG_SIZE]; }; @@ -65,6 +65,7 @@ struct client{ NODE node; int sock; int proto; + FAST_LOCK lock; LIST addrq; struct message_buffer send; struct message_buffer recv; @@ -127,11 +128,11 @@ GLBLTYPE FAST_LOCK rsrv_free_addrq_lck; GLBLTYPE FAST_LOCK rsrv_free_eventq_lck; GLBLTYPE struct client *prsrv_cast_client; -#define LOCK_SEND(CLIENT)\ -FASTLOCK(&(CLIENT)->send.lock); +#define LOCK_CLIENT(CLIENT)\ +FASTLOCK(&(CLIENT)->lock); -#define UNLOCK_SEND(CLIENT)\ -FASTUNLOCK(&(CLIENT)->send.lock); +#define UNLOCK_CLIENT(CLIENT)\ +FASTUNLOCK(&(CLIENT)->lock); #define EXTMSGPTR(CLIENT)\ ((struct extmsg *) &(CLIENT)->send.buf[(CLIENT)->send.stk])