--------------------- PatchSet 5277 Date: 2002/10/07 14:35:34 Author: rbcollins Branch: rbcollins_cxxtest Tag: (none) Log: extract common sending logic from icp Members: src/icp_v2.cc:1.1.2.1->1.1.2.2 src/icp_v3.cc:1.1.2.3->1.1.2.4 src/protos.h:1.63.2.8->1.63.2.9 Index: squid/src/icp_v2.cc =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/icp_v2.cc,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- squid/src/icp_v2.cc 7 Oct 2002 09:21:04 -0000 1.1.2.1 +++ squid/src/icp_v2.cc 7 Oct 2002 14:35:34 -0000 1.1.2.2 @@ -1,6 +1,6 @@ /* - * $Id: icp_v2.cc,v 1.1.2.1 2002/10/07 09:21:04 rbcollins Exp $ + * $Id: icp_v2.cc,v 1.1.2.2 2002/10/07 14:35:34 rbcollins Exp $ * * DEBUG: section 12 Internet Cache Protocol * AUTHOR: Duane Wessels @@ -179,6 +179,27 @@ return 1; } +/* if true, reply sent */ +int +icpCreateAndSend (int fd, const struct sockaddr_in *from, int flags, + const char *url, + int reqnum, + int pad) +{ + /* if store is rebuilding, return a UDP_HIT, but not a MISS */ + if (store_dirs_rebuilding && opt_reload_hit_only) { + icp_common_t * reply = (icp_common_t *)icpCreateMessage(ICP_MISS_NOFETCH, flags, url, reqnum, pad); + icpUdpSend(fd, from, reply, LOG_UDP_MISS_NOFETCH, 0); + return 1; + } else if (hit_only_mode_until > squid_curtime) { + icp_common_t * reply = (icp_common_t *)icpCreateMessage(ICP_MISS_NOFETCH, flags, url, reqnum, pad); + icpUdpSend(fd, from, reply, LOG_UDP_MISS_NOFETCH, 0); + return 1; + } + + return 0; +} + static void icpHandleIcpV2(int fd, struct sockaddr_in from, char *buf, int len) { @@ -263,19 +284,14 @@ if ((rtt = netdbHostRtt(icp_request->host)) == 0) netdbPingSite(icp_request->host); } - /* if store is rebuilding, return a UDP_HIT, but not a MISS */ - if (store_dirs_rebuilding && opt_reload_hit_only) { - reply = (icp_common_t *)icpCreateMessage(ICP_MISS_NOFETCH, flags, url, header.reqnum, src_rtt); - icpUdpSend(fd, &from, reply, LOG_UDP_MISS_NOFETCH, 0); - } else if (hit_only_mode_until > squid_curtime) { - reply = (icp_common_t *)icpCreateMessage(ICP_MISS_NOFETCH, flags, url, header.reqnum, src_rtt); - icpUdpSend(fd, &from, reply, LOG_UDP_MISS_NOFETCH, 0); - } else if (Config.onoff.test_reachability && rtt == 0) { - reply = (icp_common_t *)icpCreateMessage(ICP_MISS_NOFETCH, flags, url, header.reqnum, src_rtt); - icpUdpSend(fd, &from, reply, LOG_UDP_MISS_NOFETCH, 0); - } else { - reply = (icp_common_t *)icpCreateMessage(ICP_MISS, flags, url, header.reqnum, src_rtt); - icpUdpSend(fd, &from, reply, LOG_UDP_MISS, 0); + if (!icpCreateAndSend(fd, &from, flags, url, header.reqnum, src_rtt)) { + if (Config.onoff.test_reachability && rtt == 0) { + reply = (icp_common_t *)icpCreateMessage(ICP_MISS_NOFETCH, flags, url, header.reqnum, src_rtt); + icpUdpSend(fd, &from, reply, LOG_UDP_MISS_NOFETCH, 0); + } else { + reply = (icp_common_t *)icpCreateMessage(ICP_MISS, flags, url, header.reqnum, src_rtt); + icpUdpSend(fd, &from, reply, LOG_UDP_MISS, 0); + } } break; Index: squid/src/icp_v3.cc =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/icp_v3.cc,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- squid/src/icp_v3.cc 7 Oct 2002 09:42:48 -0000 1.1.2.3 +++ squid/src/icp_v3.cc 7 Oct 2002 14:35:36 -0000 1.1.2.4 @@ -1,6 +1,6 @@ /* - * $Id: icp_v3.cc,v 1.1.2.3 2002/10/07 09:42:48 rbcollins Exp $ + * $Id: icp_v3.cc,v 1.1.2.4 2002/10/07 14:35:36 rbcollins Exp $ * * DEBUG: section 12 Internet Cache Protocol * AUTHOR: Duane Wessels @@ -117,15 +117,7 @@ if (icpCheckUdpHit(entry, request)) { icp_common_t *reply = (icp_common_t *) icpCreateMessage(ICP_HIT, 0, url, header.reqnum, 0); icpUdpSend(fd, &from, reply, LOG_UDP_HIT, 0); - } else - /* if store is rebuilding, return a UDP_HIT, but not a MISS */ - if (opt_reload_hit_only && store_dirs_rebuilding) { - icp_common_t *reply = (icp_common_t *) icpCreateMessage(ICP_MISS_NOFETCH, 0, url, header.reqnum, 0); - icpUdpSend(fd, &from, reply, LOG_UDP_MISS_NOFETCH, 0); - } else if (hit_only_mode_until > squid_curtime) { - icp_common_t *reply = (icp_common_t *) icpCreateMessage(ICP_MISS_NOFETCH, 0, url, header.reqnum, 0); - icpUdpSend(fd, &from, reply, LOG_UDP_MISS_NOFETCH, 0); - } else { + } else if (!icpCreateAndSend(fd, &from, 0, url, header.reqnum,0)) { icp_common_t *reply = (icp_common_t *) icpCreateMessage(ICP_MISS, 0, url, header.reqnum, 0); icpUdpSend(fd, &from, reply, LOG_UDP_MISS, 0); } Index: squid/src/protos.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/protos.h,v retrieving revision 1.63.2.8 retrieving revision 1.63.2.9 diff -u -r1.63.2.8 -r1.63.2.9 --- squid/src/protos.h 7 Oct 2002 07:19:14 -0000 1.63.2.8 +++ squid/src/protos.h 7 Oct 2002 14:35:36 -0000 1.63.2.9 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.63.2.8 2002/10/07 07:19:14 rbcollins Exp $ + * $Id: protos.h,v 1.63.2.9 2002/10/07 14:35:36 rbcollins Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -536,6 +536,8 @@ const char *url, int reqnum, int pad); +SQUIDCEXTERN int icpCreateAndSend(int fd, const struct sockaddr_in *from, int flags, const char *url, int reqnum, int pad); + SQUIDCEXTERN int icpUdpSend(int, const struct sockaddr_in *, icp_common_t *, log_type, int); SQUIDCEXTERN PF icpHandleUdp; SQUIDCEXTERN PF icpUdpSendQueue;