diff --git a/src/rsrv/camessage.c b/src/rsrv/camessage.c index 97e59df2e..4ad949b19 100644 --- a/src/rsrv/camessage.c +++ b/src/rsrv/camessage.c @@ -274,12 +274,6 @@ struct message_buffer *recv read_sync_reply(mp, client); break; case IOC_CLAIM_CIU: - /* - * remove channel in use block from - * the UDP client where it could time - * out and place it on the client - * who is claiming it - */ /* * clients which dont claim their @@ -287,27 +281,50 @@ struct message_buffer *recv * timeout must reconnect */ pciu = MPTOPCIU(mp); - if(pciu?pciu->client!=prsrv_cast_client:TRUE){ - free_client(client); - logMsg("CAS: client timeout disconnect\n", - NULL, + if(!pciu){ + logMsg("CAS: client timeout disconnect id=%d\n", + mp->m_cid, NULL, NULL, NULL, NULL, NULL); + free_client(client); + exit(0); + } + + /* + * remove channel in use block from + * the UDP client where it could time + * out and place it on the client + * who is claiming it + */ + if(pciu->client==prsrv_cast_client){ + LOCK_CLIENT(prsrv_cast_client); + ellDelete( + &prsrv_cast_client->addrq, + &pciu->node); + UNLOCK_CLIENT(prsrv_cast_client); + pciu->client = client; + LOCK_CLIENT(client); + ellAdd(&client->addrq, &pciu->node); + UNLOCK_CLIENT(client); + } + /* + * Any other client attachment is a severe error + */ + else if(pciu->client!=client){ + logMsg("CAS: bad channel claim disconnect %d %x %x\n", + mp->m_cid, + (int)pciu, + (int)pciu->client, + NULL, + NULL, + NULL); + free_client(client); exit(0); } - LOCK_CLIENT(prsrv_cast_client); - ellDelete( - &prsrv_cast_client->addrq, - &pciu->node); - UNLOCK_CLIENT(prsrv_cast_client); - pciu->client = client; - LOCK_CLIENT(client); - ellAdd(&client->addrq, &pciu->node); - UNLOCK_CLIENT(client); break; default: diff --git a/src/rsrv/cast_server.c b/src/rsrv/cast_server.c index d8ed260c1..f0eb3cf81 100644 --- a/src/rsrv/cast_server.c +++ b/src/rsrv/cast_server.c @@ -313,7 +313,7 @@ clean_addrq(struct client *pclient) { struct channel_in_use *pciu; struct channel_in_use *pnextciu; - FAST unsigned long current = tickGet(); + unsigned long current; unsigned long delay; unsigned long maxdelay = 0; unsigned ndelete=0; @@ -322,6 +322,7 @@ clean_addrq(struct client *pclient) current = tickGet(); + LOCK_CLIENT(prsrv_cast_client); pnextciu = (struct channel_in_use *) pclient->addrq.node.next; @@ -355,9 +356,10 @@ clean_addrq(struct client *pclient) maxdelay = max(delay, maxdelay); } } + UNLOCK_CLIENT(prsrv_cast_client); +# ifdef DEBUG if(ndelete){ -#ifdef DEBUG logMsg( "CAS: %d CA channels have expired after %d sec\n", ndelete, maxdelay / sysClkRateGet(), @@ -365,8 +367,9 @@ clean_addrq(struct client *pclient) NULL, NULL, NULL); -#endif } +# endif + }