[master] 13db39049 Add VTCP_Assert() in various places that call read() and write()
Martin Blix Grydeland
martin at varnish-software.com
Mon Nov 9 15:13:09 UTC 2020
commit 13db390498511366de5c5f4f4bae2a02a519e333
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date: Wed Oct 7 16:17:44 2020 +0200
Add VTCP_Assert() in various places that call read() and write()
This adds VTCP_Assert() on the result of read and write calls that deals
with TCP sockets.
diff --git a/bin/varnishd/cache/cache_backend_probe.c b/bin/varnishd/cache/cache_backend_probe.c
index bf41b952a..8432c8582 100644
--- a/bin/varnishd/cache/cache_backend_probe.c
+++ b/bin/varnishd/cache/cache_backend_probe.c
@@ -229,6 +229,7 @@ vbp_write(struct vbp_target *vt, int *sock, const void *buf, size_t len)
int i;
i = write(*sock, buf, len);
+ VTCP_Assert(i);
if (i != len) {
if (i < 0) {
vt->err_xmit |= 1;
@@ -371,6 +372,7 @@ vbp_poke(struct vbp_target *vt)
sizeof vt->resp_buf - rlen);
else
i = read(s, buf, sizeof buf);
+ VTCP_Assert(i);
if (i <= 0) {
if (i < 0)
bprintf(vt->resp_buf, "Read error %d (%s)",
diff --git a/bin/varnishd/http1/cache_http1_deliver.c b/bin/varnishd/http1/cache_http1_deliver.c
index 77ef66f3f..b051499ee 100644
--- a/bin/varnishd/http1/cache_http1_deliver.c
+++ b/bin/varnishd/http1/cache_http1_deliver.c
@@ -35,6 +35,8 @@
#include "cache/cache_filter.h"
#include "cache_http1.h"
+#include "vtcp.h"
+
/*--------------------------------------------------------------------*/
static int v_matchproto_(vdp_bytes_f)
@@ -76,7 +78,7 @@ v1d_error(struct req *req, const char *msg)
VSLb(req->vsl, SLT_RespReason, "Internal Server Error");
req->wrk->stats->client_resp_500++;
- (void)write(req->sp->fd, r_500, sizeof r_500 - 1);
+ VTCP_Assert(write(req->sp->fd, r_500, sizeof r_500 - 1));
req->doclose = SC_TX_EOF;
}
diff --git a/bin/varnishd/http1/cache_http1_pipe.c b/bin/varnishd/http1/cache_http1_pipe.c
index 2ddaf7f44..d273ae4f4 100644
--- a/bin/varnishd/http1/cache_http1_pipe.c
+++ b/bin/varnishd/http1/cache_http1_pipe.c
@@ -39,6 +39,7 @@
#include <stdio.h>
#include "cache_http1.h"
+#include "vtcp.h"
#include "VSC_vbe.h"
@@ -51,10 +52,12 @@ rdf(int fd0, int fd1, uint64_t *pcnt)
char buf[BUFSIZ], *p;
i = read(fd0, buf, sizeof buf);
+ VTCP_Assert(i);
if (i <= 0)
return (1);
for (p = buf; i > 0; i -= j, p += j) {
j = write(fd1, p, i);
+ VTCP_Assert(j);
if (j <= 0)
return (1);
*pcnt += j;
@@ -123,6 +126,7 @@ V1P_Process(const struct req *req, int fd, struct v1p_acct *v1a)
if (req->htc->pipeline_b != NULL) {
j = write(fd, req->htc->pipeline_b,
req->htc->pipeline_e - req->htc->pipeline_b);
+ VTCP_Assert(j);
if (j < 0)
return;
req->htc->pipeline_b = NULL;
diff --git a/bin/varnishd/http2/cache_http2_session.c b/bin/varnishd/http2/cache_http2_session.c
index 0637984b8..cc1816f54 100644
--- a/bin/varnishd/http2/cache_http2_session.c
+++ b/bin/varnishd/http2/cache_http2_session.c
@@ -40,6 +40,7 @@
#include "vend.h"
#include "vtim.h"
+#include "vtcp.h"
static const char h2_resp_101[] =
"HTTP/1.1 101 Switching Protocols\r\n"
@@ -255,6 +256,7 @@ h2_ou_session(struct worker *wrk, struct h2_sess *h2,
}
sz = write(h2->sess->fd, h2_resp_101, strlen(h2_resp_101));
+ VTCP_Assert(sz);
if (sz != strlen(h2_resp_101)) {
VSLb(h2->vsl, SLT_Debug, "H2: Upgrade: Error writing 101"
" response: %s\n", vstrerror(errno));
diff --git a/bin/varnishd/proxy/cache_proxy_proto.c b/bin/varnishd/proxy/cache_proxy_proto.c
index 36ffabff2..e9a2ce164 100644
--- a/bin/varnishd/proxy/cache_proxy_proto.c
+++ b/bin/varnishd/proxy/cache_proxy_proto.c
@@ -744,6 +744,7 @@ VPX_Send_Proxy(int fd, int version, const struct sess *sp)
WRONG("Wrong proxy version");
r = write(fd, VSB_data(vsb), VSB_len(vsb));
+ VTCP_Assert(r);
if (!DO_DEBUG(DBG_PROTOCOL))
return (r);
More information about the varnish-commit
mailing list