for calling sendto() and messages may still be queued.
Previously we forgot to call icpLogIcp() from the other
place so now all logging and stats are in a single function
which gets called after a successful send.
/*
- * $Id: client_side.cc,v 1.254 1998/04/04 00:23:13 wessels Exp $
+ * $Id: client_side.cc,v 1.255 1998/04/04 05:17:38 wessels Exp $
*
* DEBUG: section 33 Client-side Routines
* AUTHOR: Duane Wessels
if (0 != i->stop.tv_sec && 0 != i->start.tv_sec)
statHistCount(&Counter.icp.query_svc_time, tvSubUsec(i->start, i->stop));
#if CACHE_DIGEST
- assert(http->request->hier.used_icp + http->request->hier.used_cd < 2);
- if (http->request->hier.used_icp) {
- statHistCount(&Counter.icp.client_svc_time, svc_time);
- Counter.icp.times_used++;
- }
- if (http->request->hier.used_cd) {
- statHistCount(&Counter.cd.client_svc_time, svc_time);
- Counter.cd.times_used++;
- }
- t = httpHeaderGetLastStr(, HDR_X_CACHE);
- if (NULL != t && 0 == strncmp(t, "HIT", 3)) {
- if (http->request->hier.cd_hit)
- Counter.cd.true_hits++;
- else
- Counter.cd.false_miss++;
- } else {
- if (http->request->hier.cd_hit)
- Counter.cd.false_hit++;
- else
- Counter.cd.true_miss++;
- }
+ assert(http->request->hier.used_icp + http->request->hier.used_cd < 2);
+ if (http->request->hier.used_icp) {
+ statHistCount(&Counter.icp.client_svc_time, svc_time);
+ Counter.icp.times_used++;
+ }
+ if (http->request->hier.used_cd) {
+ statHistCount(&Counter.cd.client_svc_time, svc_time);
+ Counter.cd.times_used++;
+ }
+ t = httpHeaderGetLastStr(, HDR_X_CACHE);
+ if (NULL != t && 0 == strncmp(t, "HIT", 3)) {
+ if (http->request->hier.cd_hit)
+ Counter.cd.true_hits++;
+ else
+ Counter.cd.false_miss++;
+ } else {
+ if (http->request->hier.cd_hit)
+ Counter.cd.false_hit++;
+ else
+ Counter.cd.true_miss++;
+ }
#endif
}
* so we can use std processing routines for IMS and such */
if (EBIT_TEST(r->flags, REQ_IMS) && e->lastmod <= r->ims)
return LOG_TCP_IMS_HIT;
- else
- if (e->mem_status == IN_MEMORY)
+ else if (e->mem_status == IN_MEMORY)
return LOG_TCP_MEM_HIT;
else
return LOG_TCP_HIT;
commSetDefer(fd, clientReadDefer, connState);
}
-void
-AppendUdp(icpUdpData * item)
-{
- item->next = NULL;
- if (UdpQueueHead == NULL) {
- UdpQueueHead = item;
- UdpQueueTail = item;
- } else if (UdpQueueTail == UdpQueueHead) {
- UdpQueueTail = item;
- UdpQueueHead->next = item;
- } else {
- UdpQueueTail->next = item;
- UdpQueueTail = item;
- }
-}
-
/* return 1 if the request should be aborted */
static int
CheckQuickAbort2(const clientHttpRequest * http)
/*
- * $Id: comm.cc,v 1.242 1998/03/31 05:37:38 wessels Exp $
+ * $Id: comm.cc,v 1.243 1998/04/04 05:17:40 wessels Exp $
*
* DEBUG: section 5 Socket Functions
* AUTHOR: Harvest Derived
comm_udp_sendto(int fd,
const struct sockaddr_in *to_addr,
int addr_len,
- const char *buf,
+ const void *buf,
int len)
{
int x;
/*
- * $Id: globals.h,v 1.49 1998/04/02 17:11:23 rousskov Exp $
+ * $Id: globals.h,v 1.50 1998/04/04 05:17:42 wessels Exp $
*/
extern FILE *debug_log; /* NULL */
extern int store_rebuilding; /* 1 */
extern int store_swap_size; /* 0 */
extern unsigned long store_mem_size; /* 0 */
-extern icpUdpData *UdpQueueHead; /* NULL */
-extern icpUdpData *UdpQueueTail; /* NULL */
extern time_t hit_only_mode_until; /* 0 */
extern StatCounters Counter;
extern char *err_type_str[];
extern const String StringNull; /* { 0, 0, NULL } */
extern int hot_obj_count; /* 0 */
extern int _db_level;
-extern CacheDigest *store_digest; /* NULL */
+extern CacheDigest *store_digest; /* NULL */
#include "squid.h"
-static void icpLogIcp(icpUdpData *);
+static void icpLogIcp(struct in_addr, log_type, int, const char *, int);
static void icpHandleIcpV2(int, struct sockaddr_in, char *, int);
+static PF icpUdpSendQueue;
+
+static icpUdpData *UdpQueueHead = NULL;
+static icpUdpData *UdpQueueTail = NULL;
static void
-icpLogIcp(icpUdpData * queue)
+icpLogIcp(struct in_addr caddr, log_type logcode, int len, const char *url, int delay)
{
- icp_common_t *header = (icp_common_t *) (void *) queue->msg;
- char *url = (char *) header + sizeof(icp_common_t);
AccessLogEntry al;
- clientdbUpdate(queue->address.sin_addr, queue->logcode, PROTO_ICP, queue->len);
+ clientdbUpdate(caddr, logcode, PROTO_ICP, len);
+ Counter.icp.pkts_sent++;
+ if (logcode == LOG_UDP_HIT)
+ Counter.icp.hits_sent++;
+ kb_incr(&Counter.icp.kbytes_sent, (size_t) len);
+ statHistCount(&Counter.icp.reply_svc_time, delay);
if (!Config.onoff.log_udp)
return;
- memset(&al, '\0', sizeof(AccessLogEntry));
+ memset(&al, '\0', sizeof(al));
al.icp.opcode = ICP_QUERY;
al.url = url;
- al.cache.caddr = queue->address.sin_addr;
- al.cache.size = queue->len;
- al.cache.code = queue->logcode;
- al.cache.msec = tvSubMsec(queue->start, current_time);
+ al.cache.caddr = caddr;
+ al.cache.size = len;
+ al.cache.code = logcode;
+ al.cache.msec = delay;
accessLogLog(&al);
}
-void
-icpUdpReply(int fd, void *data)
+static void
+icpUdpSendQueue(int fd, void *unused)
{
- icpUdpData *queue = data;
+ icpUdpData *q;
int x;
- /* Disable handler, in case of errors. */
- commSetSelect(fd, COMM_SELECT_WRITE, NULL, NULL, 0);
- while ((queue = UdpQueueHead) != NULL) {
- debug(12, 5) ("icpUdpReply: FD %d sending %d bytes to %s port %d\n",
- fd,
- queue->len,
- inet_ntoa(queue->address.sin_addr),
- ntohs(queue->address.sin_port));
- x = comm_udp_sendto(fd,
- &queue->address,
- sizeof(struct sockaddr_in),
- queue->msg,
- queue->len);
- if (x < 0) {
- if (ignoreErrno(errno))
- break; /* don't de-queue */
- } else {
- Counter.icp.pkts_sent++;
- if (queue->logcode == LOG_UDP_HIT)
- Counter.icp.hits_sent++;
- kb_incr(&Counter.icp.kbytes_sent, (size_t) x);
- }
- UdpQueueHead = queue->next;
- if (queue->logcode) {
- icpLogIcp(queue);
- statHistCount(&Counter.icp.reply_svc_time,
- tvSubUsec(queue->start, current_time));
- }
- safe_free(queue->msg);
- safe_free(queue);
- }
- /* Reinstate handler if needed */
- if (UdpQueueHead) {
- commSetSelect(fd, COMM_SELECT_WRITE, icpUdpReply, UdpQueueHead, 0);
+ int delay;
+ while ((q = UdpQueueHead) != NULL) {
+ delay = tvSubUsec(q->queue_time, current_time);
+ /* increment delay to prevent looping */
+ x = icpUdpSend(fd, &q->address, q->msg, q->logcode, ++delay);
+ UdpQueueHead = q->next;
+ safe_free(q);
+ if (x < 0)
+ break;
}
}
return buf;
}
-void
+int
icpUdpSend(int fd,
const struct sockaddr_in *to,
icp_common_t * msg,
log_type logcode,
- protocol_t proto)
+ int delay)
{
- icpUdpData *data = xcalloc(1, sizeof(icpUdpData));
+ icpUdpData *queue;
int x;
- debug(12, 4) ("icpUdpSend: Queueing %s for %s\n",
- icp_opcode_str[msg->opcode],
- inet_ntoa(to->sin_addr));
- data->address = *to;
- data->msg = msg;
- data->len = (int) ntohs(msg->length);
- data->start = current_time;
- data->logcode = logcode;
- data->proto = proto;
- debug(12, 5) ("icpUdpSend: FD %d sending %d bytes to %s port %d\n",
+ int len;
+ len = (int) ntohs(msg->length);
+ debug(12, 5) ("icpUdpSend: FD %d sending %s, %d bytes to %s:%d\n",
fd,
- data->len,
- inet_ntoa(data->address.sin_addr),
- ntohs(data->address.sin_port));
- x = comm_udp_sendto(fd,
- &data->address,
- sizeof(struct sockaddr_in),
- data->msg,
- data->len);
- if (x < 0) {
- /* queue it */
- AppendUdp(data);
- commSetSelect(fd, COMM_SELECT_WRITE, icpUdpReply, UdpQueueHead, 0);
+ icp_opcode_str[msg->opcode],
+ len,
+ inet_ntoa(to->sin_addr),
+ ntohs(to->sin_port));
+ x = comm_udp_sendto(fd, to, sizeof(*to), msg, len);
+ if (0 == x) {
+ /* successfully written */
+ icpLogIcp(to->sin_addr, logcode, len, (char *) (msg + 1), delay);
+ safe_free(msg);
+ } else if (0 == delay) {
+ /* send failed, but queue it */
+ queue = xcalloc(1, sizeof(icpUdpData));
+ queue->address = *to;
+ queue->msg = msg;
+ queue->len = (int) ntohs(msg->length);
+ queue->queue_time = current_time;
+ queue->logcode = logcode;
+ if (UdpQueueHead == NULL) {
+ UdpQueueHead = queue;
+ UdpQueueTail = queue;
+ } else if (UdpQueueTail == UdpQueueHead) {
+ UdpQueueTail = queue;
+ UdpQueueHead->next = queue;
+ } else {
+ UdpQueueTail->next = queue;
+ UdpQueueTail = queue;
+ }
+ commSetSelect(fd, COMM_SELECT_WRITE, icpUdpSendQueue, NULL, 0);
Counter.icp.replies_queued++;
} else {
- Counter.icp.pkts_sent++;
- if (data->logcode == LOG_UDP_HIT)
- Counter.icp.hits_sent++;
- kb_incr(&Counter.icp.kbytes_sent, (size_t) x);
- safe_free(data->msg);
- safe_free(data);
+ /* don't queue it */
+ Counter.icp.replies_dropped++;
}
+ return x;
}
int
url = buf + sizeof(icp_common_t) + sizeof(u_num32);
if ((icp_request = urlParse(method, url)) == NULL) {
reply = icpCreateMessage(ICP_ERR, 0, url, header.reqnum, 0);
- icpUdpSend(fd, &from, reply, LOG_UDP_INVALID, PROTO_NONE);
+ icpUdpSend(fd, &from, reply, LOG_UDP_INVALID, 0);
break;
}
checklist.src_addr = from.sin_addr;
clientdbUpdate(from.sin_addr, LOG_UDP_DENIED, Config.Port.icp, 0);
} else {
reply = icpCreateMessage(ICP_DENIED, 0, url, header.reqnum, 0);
- icpUdpSend(fd, &from, reply, LOG_UDP_DENIED, icp_request->protocol);
+ icpUdpSend(fd, &from, reply, LOG_UDP_DENIED, 0);
}
break;
}
debug(12, 5) ("icpHandleIcpV2: OPCODE %s\n", icp_opcode_str[header.opcode]);
if (icpCheckUdpHit(entry, icp_request)) {
reply = icpCreateMessage(ICP_HIT, flags, url, header.reqnum, src_rtt);
- icpUdpSend(fd, &from, reply, LOG_UDP_HIT, icp_request->protocol);
+ icpUdpSend(fd, &from, reply, LOG_UDP_HIT, 0);
break;
}
if (Config.onoff.test_reachability && rtt == 0) {
/* if store is rebuilding, return a UDP_HIT, but not a MISS */
if (store_rebuilding && opt_reload_hit_only) {
reply = icpCreateMessage(ICP_MISS_NOFETCH, flags, url, header.reqnum, src_rtt);
- icpUdpSend(fd, &from, reply, LOG_UDP_MISS_NOFETCH, icp_request->protocol);
+ icpUdpSend(fd, &from, reply, LOG_UDP_MISS_NOFETCH, 0);
} else if (hit_only_mode_until > squid_curtime) {
reply = icpCreateMessage(ICP_MISS_NOFETCH, flags, url, header.reqnum, src_rtt);
- icpUdpSend(fd, &from, reply, LOG_UDP_MISS_NOFETCH, icp_request->protocol);
+ icpUdpSend(fd, &from, reply, LOG_UDP_MISS_NOFETCH, 0);
} else if (Config.onoff.test_reachability && rtt == 0) {
reply = icpCreateMessage(ICP_MISS_NOFETCH, flags, url, header.reqnum, src_rtt);
- icpUdpSend(fd, &from, reply, LOG_UDP_MISS_NOFETCH, icp_request->protocol);
+ icpUdpSend(fd, &from, reply, LOG_UDP_MISS_NOFETCH, 0);
} else {
reply = icpCreateMessage(ICP_MISS, flags, url, header.reqnum, src_rtt);
- icpUdpSend(fd, &from, reply, LOG_UDP_MISS, icp_request->protocol);
+ icpUdpSend(fd, &from, reply, LOG_UDP_MISS, 0);
}
break;
url = buf + sizeof(icp_common_t) + sizeof(u_num32);
if ((icp_request = urlParse(method, url)) == NULL) {
reply = icpCreateMessage(ICP_ERR, 0, url, header.reqnum, 0);
- icpUdpSend(fd, &from, reply, LOG_UDP_INVALID, PROTO_NONE);
+ icpUdpSend(fd, &from, reply, LOG_UDP_INVALID, 0);
break;
}
checklist.src_addr = from.sin_addr;
clientdbUpdate(from.sin_addr, LOG_UDP_DENIED, Config.Port.icp, 0);
} else {
reply = icpCreateMessage(ICP_DENIED, 0, url, header.reqnum, 0);
- icpUdpSend(fd, &from, reply, LOG_UDP_DENIED, icp_request->protocol);
+ icpUdpSend(fd, &from, reply, LOG_UDP_DENIED, 0);
}
break;
}
icp_opcode_str[header.opcode]);
if (icpCheckUdpHit(entry, icp_request)) {
reply = icpCreateMessage(ICP_HIT, 0, url, header.reqnum, 0);
- icpUdpSend(fd, &from, reply, LOG_UDP_HIT, icp_request->protocol);
+ icpUdpSend(fd, &from, reply, LOG_UDP_HIT, 0);
break;
}
/* if store is rebuilding, return a UDP_HIT, but not a MISS */
if (opt_reload_hit_only && store_rebuilding) {
reply = icpCreateMessage(ICP_MISS_NOFETCH, 0, url, header.reqnum, 0);
- icpUdpSend(fd, &from, reply, LOG_UDP_MISS_NOFETCH, icp_request->protocol);
+ icpUdpSend(fd, &from, reply, LOG_UDP_MISS_NOFETCH, 0);
} else if (hit_only_mode_until > squid_curtime) {
reply = icpCreateMessage(ICP_MISS_NOFETCH, 0, url, header.reqnum, 0);
- icpUdpSend(fd, &from, reply, LOG_UDP_MISS_NOFETCH, icp_request->protocol);
+ icpUdpSend(fd, &from, reply, LOG_UDP_MISS_NOFETCH, 0);
} else {
reply = icpCreateMessage(ICP_MISS, 0, url, header.reqnum, 0);
- icpUdpSend(fd, &from, reply, LOG_UDP_MISS, icp_request->protocol);
+ icpUdpSend(fd, &from, reply, LOG_UDP_MISS, 0);
}
break;
extern void commSetSelect(int, unsigned int, PF *, void *, time_t);
extern void comm_add_close_handler(int fd, PF *, void *);
extern void comm_remove_close_handler(int fd, PF *, void *);
-extern int comm_udp_sendto(int fd, const struct sockaddr_in *, int size, const char *buf, int len);
+extern int comm_udp_sendto(int, const struct sockaddr_in *, int, const void *, int);
extern void comm_write(int fd,
char *buf,
int size,
const char *url,
int reqnum,
int pad);
-extern void icpUdpSend(int fd,
- const struct sockaddr_in *,
- icp_common_t * msg,
- log_type,
- protocol_t);
+extern int icpUdpSend(int, const struct sockaddr_in *, icp_common_t *, log_type, int);
extern PF icpHandleUdp;
extern PF httpAccept;
extern DEFER httpAcceptDefer;
extern int snmpCompare(oid * name1, int len1, oid * name2, int len2);
#endif /* SQUID_SNMP */
-extern void AppendUdp(icpUdpData *);
-extern PF icpUdpReply;
extern void icpHandleIcpV3(int, struct sockaddr_in, char *, int);
extern int icpCheckUdpHit(StoreEntry *, request_t * request);
extern void icpConnectionsOpen(void);
/*
- * $Id: send-announce.cc,v 1.48 1998/03/27 18:41:14 wessels Exp $
+ * $Id: send-announce.cc,v 1.49 1998/04/04 05:17:47 wessels Exp $
*
* DEBUG: section 27 Cache Announcer
* AUTHOR: Duane Wessels
void *junk;
if (0 == Config.onoff.announce)
return;
+ if (theOutIcpConnection < 0)
+ return;
cbdataAdd(junk = xmalloc(1), MEM_NONE);
ipcache_nbgethostbyname(Config.Announce.host, send_announce, junk);
eventAdd("send_announce", start_announce, NULL, Config.Announce.period);
{
LOCAL_ARRAY(char, tbuf, 256);
LOCAL_ARRAY(char, sndbuf, BUFSIZ);
- icpUdpData *qdata = NULL;
+ struct sockaddr_in S;
char *host = Config.Announce.host;
char *file = NULL;
u_short port = Config.Announce.port;
int l;
int n;
int fd;
+ int x;
cbdataFree(junk);
if (ia == NULL) {
debug(27, 1) ("send_announce: Unknown host '%s'\n", host);
debug(50, 1) ("send_announce: %s: %s\n", file, xstrerror());
}
}
- qdata = xcalloc(1, sizeof(icpUdpData));
- qdata->msg = xstrdup(sndbuf);
- qdata->len = strlen(sndbuf) + 1;
- qdata->address.sin_family = AF_INET;
- qdata->address.sin_port = htons(port);
- qdata->address.sin_addr = ia->in_addrs[0];
- AppendUdp(qdata);
- commSetSelect(theOutIcpConnection,
- COMM_SELECT_WRITE,
- icpUdpReply,
- qdata, 0);
+ memset(&S, '\0', sizeof(S));
+ S.sin_family = AF_INET;
+ S.sin_port = htons(port);
+ S.sin_addr = ia->in_addrs[0];
+ assert(theOutIcpConnection > 0);
+ x = comm_udp_sendto(theOutIcpConnection,
+ &S, sizeof(S),
+ sndbuf, strlen(sndbuf) + 1);
+ if (x < 0)
+ debug(27, 1) ("send_announce: FD %d: %s\n", theOutIcpConnection,
+ xstrerror());
}
struct timeval start;
#endif
log_type logcode;
- protocol_t proto;
+ struct timeval queue_time;
};
struct _icp_ping_data {
int hits_sent;
int hits_recv;
int replies_queued;
+ int replies_dropped;
kb_t kbytes_sent;
kb_t kbytes_recv;
StatHist query_svc_time;