From adeeeba322857f4f4632b1f212f3cc8cf4a73f79 Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Tue, 26 Nov 1991 10:44:01 +0000 Subject: [PATCH] flush before changing cast client's addr --- src/rsrv/cast_server.c | 70 +++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 31 deletions(-) diff --git a/src/rsrv/cast_server.c b/src/rsrv/cast_server.c index 749bd07c9..3bcc0ba77 100644 --- a/src/rsrv/cast_server.c +++ b/src/rsrv/cast_server.c @@ -36,14 +36,24 @@ * client uses the same port number * .04 joh 080591 changed printf() to a logMsg() * .05 joh 082091 tick stamp init in create_udp_client() + * .06 joh 112291 dont change the address until after the flush + * .07 joh 112291 fixed the comments * * Improvements * ------------ + * .01 * Dont send channel found message unless there is memory, a task slot, * and a TCP socket available. Send a diagnostic instead. * Or ... make the timeout shorter? This is only a problem if * they persist in trying to make a connection after getting no * response. + * + * Notes: + * ------ + * .01 + * Replies to broadcasts are not returned over + * an existing TCP connection to avoid a TCP + * pend which could lock up the cast server. */ #include @@ -74,12 +84,11 @@ cast_server() struct sockaddr_in sin; FAST int status; int count; - FAST struct client *client = NULL; - struct sockaddr_in last_recv_addr; + struct sockaddr_in new_recv_addr; int recv_addr_size; unsigned nchars; - recv_addr_size = sizeof(prsrv_cast_client->addr); + recv_addr_size = sizeof(new_recv_addr); if( IOC_cast_sock!=0 && IOC_cast_sock!=ERROR ) if( (status = close(IOC_cast_sock)) == ERROR ) @@ -142,14 +151,12 @@ cast_server() while(TRUE){ - last_recv_addr = prsrv_cast_client->addr; - status = recvfrom( IOC_cast_sock, prsrv_cast_client->recv.buf, sizeof(prsrv_cast_client->recv.buf), NULL, - &prsrv_cast_client->addr, + &new_recv_addr, &recv_addr_size); if(status<0){ logMsg("Cast_server: UDP recv error\n"); @@ -159,6 +166,32 @@ cast_server() prsrv_cast_client->recv.cnt = status; prsrv_cast_client->recv.stk = 0; + prsrv_cast_client->ticks_at_last_io = tickGet(); +/* + * + * keeping an eye on the socket library + * + */ +if(sizeof(prsrv_cast_client->addr) != recv_addr_size){ + printf("cast server: addr size has changed?\n"); +} + + /* + * If we are talking to a new client flush the old one + * in case it is holding UDP messages waiting to + * see if the next message is for this same client. + */ + status = bcmp( + &prsrv_cast_client->addr, + &new_recv_addr, + recv_addr_size); + if(status){ + /* + * if the address is different + */ + cas_send_msg(prsrv_cast_client, TRUE); + prsrv_cast_client->addr = new_recv_addr; + } if(CASDEBUG>1){ logMsg( "cast_server(): msg of %d bytes\n", @@ -168,34 +201,9 @@ cast_server() prsrv_cast_client->addr.sin_port); } - prsrv_cast_client->ticks_at_last_io = tickGet(); - - /* - * If we are talking to a new client flush the old one - * in case it is holding UDP messages for a - * TCP connected client - waiting to see if the - * next message is for this same client. - * (replies to broadcasts are not returned over - * an existing TCP connection to avoid a TCP - * pend which could lock up the cast server). - */ - status = bcmp( - &prsrv_cast_client->addr, - &last_recv_addr, - recv_addr_size); - if(status){ - cas_send_msg(prsrv_cast_client, TRUE); - } - - if(CASDEBUG>2) count = prsrv_cast_client->addrq.count; - /* - * check for existing client occurs after - * message process so that this thread never - * blocks sending TCP - */ status = camessage( prsrv_cast_client, &prsrv_cast_client->recv);