]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Try sendto() for ICP replies instead of always queueing
authorwessels <>
Wed, 25 Mar 1998 12:44:48 +0000 (12:44 +0000)
committerwessels <>
Wed, 25 Mar 1998 12:44:48 +0000 (12:44 +0000)
src/icp_v2.cc

index baa6c46a4eadefcce17bb164ba7e38c193be4dbd..55cf57420464fbda68d0ab5a62fafeea404ec53a 100644 (file)
@@ -36,9 +36,6 @@ icpUdpReply(int fd, void *data)
            queue->len,
            inet_ntoa(queue->address.sin_addr),
            ntohs(queue->address.sin_port));
-       Counter.icp.pkts_sent++;
-       if (queue->logcode == LOG_UDP_HIT)
-           Counter.icp.hits_sent++;
        x = comm_udp_sendto(fd,
            &queue->address,
            sizeof(struct sockaddr_in),
@@ -48,6 +45,9 @@ icpUdpReply(int fd, void *data)
            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;
@@ -104,6 +104,7 @@ icpUdpSend(int fd,
     protocol_t proto)
 {
     icpUdpData *data = xcalloc(1, sizeof(icpUdpData));
+    int x;
     debug(12, 4) ("icpUdpSend: Queueing %s for %s\n",
        icp_opcode_str[msg->opcode],
        inet_ntoa(to->sin_addr));
@@ -113,8 +114,29 @@ icpUdpSend(int fd,
     data->start = current_time;
     data->logcode = logcode;
     data->proto = proto;
-    AppendUdp(data);
-    commSetSelect(fd, COMM_SELECT_WRITE, icpUdpReply, UdpQueueHead, 0);
+    debug(12, 5) ("icpUdpSend: FD %d sending %d bytes to %s port %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);
+       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);
+    }
 }
 
 int