Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
79578879
Commit
79578879
authored
Oct 19, 2020
by
Poul-Henning Kamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move the file descriptor up to the vtc_sess
parent
f04d7df6
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
65 additions
and
61 deletions
+65
-61
vtc.h
bin/varnishtest/vtc.h
+1
-4
vtc_http.c
bin/varnishtest/vtc_http.c
+34
-33
vtc_http.h
bin/varnishtest/vtc_http.h
+17
-1
vtc_http2.c
bin/varnishtest/vtc_http2.c
+10
-10
vtc_sess.c
bin/varnishtest/vtc_sess.c
+3
-13
No files found.
bin/varnishtest/vtc.h
View file @
79578879
...
...
@@ -92,7 +92,7 @@ void init_syslog(void);
struct
vtc_sess
*
Sess_New
(
struct
vtclog
*
vl
,
const
char
*
name
);
void
Sess_Destroy
(
struct
vtc_sess
**
spp
);
int
Sess_GetOpt
(
struct
vtc_sess
*
,
char
*
const
**
);
int
sess_process
(
struct
vtclog
*
vl
,
const
struct
vtc_sess
*
,
int
sess_process
(
struct
vtclog
*
vl
,
struct
vtc_sess
*
,
const
char
*
spec
,
int
sock
,
int
*
sfd
,
const
char
*
addr
);
typedef
int
sess_conn_f
(
void
*
priv
,
struct
vtclog
*
);
...
...
@@ -109,9 +109,6 @@ Sess_Start_Thread(
);
int
http_process
(
struct
vtclog
*
vl
,
const
char
*
spec
,
int
sock
,
int
*
sfd
,
const
char
*
addr
,
int
rcvbuf
);
char
*
synth_body
(
const
char
*
len
,
int
rnd
);
void
cmd_server_gen_vcl
(
struct
vsb
*
vsb
);
...
...
bin/varnishtest/vtc_http.c
View file @
79578879
...
...
@@ -217,7 +217,7 @@ http_write(const struct http *hp, int lvl, const char *pfx)
AZ
(
VSB_finish
(
hp
->
vsb
));
vtc_dump
(
hp
->
vl
,
lvl
,
pfx
,
VSB_data
(
hp
->
vsb
),
VSB_len
(
hp
->
vsb
));
if
(
VSB_tofile
(
hp
->
vsb
,
hp
->
fd
))
if
(
VSB_tofile
(
hp
->
vsb
,
hp
->
sess
->
fd
))
vtc_log
(
hp
->
vl
,
hp
->
fatal
,
"Write failed: %s"
,
strerror
(
errno
));
}
...
...
@@ -495,7 +495,7 @@ http_rxchar(struct http *hp, int n, int eof)
struct
pollfd
pfd
[
1
];
while
(
n
>
0
)
{
pfd
[
0
].
fd
=
hp
->
fd
;
pfd
[
0
].
fd
=
hp
->
sess
->
fd
;
pfd
[
0
].
events
=
POLLIN
;
pfd
[
0
].
revents
=
0
;
i
=
poll
(
pfd
,
1
,
hp
->
timeout
);
...
...
@@ -504,34 +504,34 @@ http_rxchar(struct http *hp, int n, int eof)
if
(
i
==
0
)
{
vtc_log
(
hp
->
vl
,
hp
->
fatal
,
"HTTP rx timeout (fd:%d %u ms)"
,
hp
->
fd
,
hp
->
timeout
);
hp
->
sess
->
fd
,
hp
->
timeout
);
continue
;
}
if
(
i
<
0
)
{
vtc_log
(
hp
->
vl
,
hp
->
fatal
,
"HTTP rx failed (fd:%d poll: %s)"
,
hp
->
fd
,
strerror
(
errno
));
hp
->
sess
->
fd
,
strerror
(
errno
));
continue
;
}
assert
(
i
>
0
);
assert
(
hp
->
rx_p
+
n
<
hp
->
rx_e
);
i
=
read
(
hp
->
fd
,
hp
->
rx_p
,
n
);
i
=
read
(
hp
->
sess
->
fd
,
hp
->
rx_p
,
n
);
if
(
!
(
pfd
[
0
].
revents
&
POLLIN
))
vtc_log
(
hp
->
vl
,
4
,
"HTTP rx poll (fd:%d revents: %x n=%d, i=%d)"
,
hp
->
fd
,
pfd
[
0
].
revents
,
n
,
i
);
hp
->
sess
->
fd
,
pfd
[
0
].
revents
,
n
,
i
);
if
(
i
==
0
&&
eof
)
return
(
i
);
if
(
i
==
0
)
{
vtc_log
(
hp
->
vl
,
hp
->
fatal
,
"HTTP rx EOF (fd:%d read: %s) %d"
,
hp
->
fd
,
strerror
(
errno
),
n
);
hp
->
sess
->
fd
,
strerror
(
errno
),
n
);
return
(
-
1
);
}
if
(
i
<
0
)
{
vtc_log
(
hp
->
vl
,
hp
->
fatal
,
"HTTP rx failed (fd:%d read: %s)"
,
hp
->
fd
,
strerror
(
errno
));
hp
->
sess
->
fd
,
strerror
(
errno
));
return
(
-
1
);
}
hp
->
rx_p
+=
i
;
...
...
@@ -1271,7 +1271,7 @@ cmd_http_recv(CMD_ARGS)
AZ
(
av
[
2
]);
n
=
strtoul
(
av
[
1
],
NULL
,
0
);
while
(
n
>
0
)
{
i
=
read
(
hp
->
fd
,
u
,
n
>
32
?
32
:
n
);
i
=
read
(
hp
->
sess
->
fd
,
u
,
n
>
32
?
32
:
n
);
if
(
i
>
0
)
vtc_dump
(
hp
->
vl
,
4
,
"recv"
,
u
,
i
);
else
...
...
@@ -1299,7 +1299,7 @@ cmd_http_send(CMD_ARGS)
AN
(
av
[
1
]);
AZ
(
av
[
2
]);
vtc_dump
(
hp
->
vl
,
4
,
"send"
,
av
[
1
],
-
1
);
i
=
write
(
hp
->
fd
,
av
[
1
],
strlen
(
av
[
1
]));
i
=
write
(
hp
->
sess
->
fd
,
av
[
1
],
strlen
(
av
[
1
]));
if
(
i
!=
strlen
(
av
[
1
]))
vtc_log
(
hp
->
vl
,
hp
->
fatal
,
"Write error in http_send(): %s"
,
strerror
(
errno
));
...
...
@@ -1327,7 +1327,7 @@ cmd_http_send_n(CMD_ARGS)
vtc_dump
(
hp
->
vl
,
4
,
"send_n"
,
av
[
2
],
-
1
);
l
=
strlen
(
av
[
2
]);
while
(
n
--
)
{
i
=
write
(
hp
->
fd
,
av
[
2
],
l
);
i
=
write
(
hp
->
sess
->
fd
,
av
[
2
],
l
);
if
(
i
!=
l
)
vtc_log
(
hp
->
vl
,
hp
->
fatal
,
"Write error in http_send(): %s"
,
...
...
@@ -1353,7 +1353,7 @@ cmd_http_send_urgent(CMD_ARGS)
AN
(
av
[
1
]);
AZ
(
av
[
2
]);
vtc_dump
(
hp
->
vl
,
4
,
"send_urgent"
,
av
[
1
],
-
1
);
i
=
send
(
hp
->
fd
,
av
[
1
],
strlen
(
av
[
1
]),
MSG_OOB
);
i
=
send
(
hp
->
sess
->
fd
,
av
[
1
],
strlen
(
av
[
1
]),
MSG_OOB
);
if
(
i
!=
strlen
(
av
[
1
]))
vtc_log
(
hp
->
vl
,
hp
->
fatal
,
"Write error in http_send_urgent(): %s"
,
strerror
(
errno
));
...
...
@@ -1381,7 +1381,7 @@ cmd_http_sendhex(CMD_ARGS)
vsb
=
vtc_hex_to_bin
(
hp
->
vl
,
av
[
1
]);
assert
(
VSB_len
(
vsb
)
>=
0
);
vtc_hexdump
(
hp
->
vl
,
4
,
"sendhex"
,
VSB_data
(
vsb
),
VSB_len
(
vsb
));
if
(
VSB_tofile
(
vsb
,
hp
->
fd
))
if
(
VSB_tofile
(
vsb
,
hp
->
sess
->
fd
))
vtc_log
(
hp
->
vl
,
hp
->
fatal
,
"Write failed: %s"
,
strerror
(
errno
));
VSB_destroy
(
&
vsb
);
...
...
@@ -1493,11 +1493,11 @@ cmd_http_expect_close(CMD_ARGS)
CAST_OBJ_NOTNULL
(
hp
,
priv
,
HTTP_MAGIC
);
AZ
(
av
[
1
]);
vtc_log
(
vl
,
4
,
"Expecting close (fd = %d)"
,
hp
->
fd
);
vtc_log
(
vl
,
4
,
"Expecting close (fd = %d)"
,
hp
->
sess
->
fd
);
if
(
hp
->
h2
)
stop_h2
(
hp
);
while
(
1
)
{
fds
[
0
].
fd
=
hp
->
fd
;
fds
[
0
].
fd
=
hp
->
sess
->
fd
;
fds
[
0
].
events
=
POLLIN
;
fds
[
0
].
revents
=
0
;
i
=
poll
(
fds
,
1
,
hp
->
timeout
);
...
...
@@ -1509,7 +1509,7 @@ cmd_http_expect_close(CMD_ARGS)
vtc_log
(
vl
,
hp
->
fatal
,
"Expected close: poll = %d, revents = 0x%x"
,
i
,
fds
[
0
].
revents
);
i
=
read
(
hp
->
fd
,
&
c
,
1
);
i
=
read
(
hp
->
sess
->
fd
,
&
c
,
1
);
if
(
VTCP_Check
(
i
))
break
;
if
(
i
==
1
&&
vct_islws
(
c
))
...
...
@@ -1517,7 +1517,7 @@ cmd_http_expect_close(CMD_ARGS)
vtc_log
(
vl
,
hp
->
fatal
,
"Expecting close: read = %d, c = 0x%02x"
,
i
,
c
);
}
vtc_log
(
vl
,
4
,
"fd=%d EOF, as expected"
,
hp
->
fd
);
vtc_log
(
vl
,
4
,
"fd=%d EOF, as expected"
,
hp
->
sess
->
fd
);
}
/* SECTION: client-server.spec.close
...
...
@@ -1540,7 +1540,7 @@ cmd_http_close(CMD_ARGS)
assert
(
*
hp
->
sfd
>=
0
);
if
(
hp
->
h2
)
stop_h2
(
hp
);
VTCP_close
(
&
hp
->
fd
);
VTCP_close
(
&
hp
->
sess
->
fd
);
vtc_log
(
vl
,
4
,
"Closed"
);
}
...
...
@@ -1564,13 +1564,13 @@ cmd_http_accept(CMD_ARGS)
assert
(
*
hp
->
sfd
>=
0
);
if
(
hp
->
h2
)
stop_h2
(
hp
);
if
(
hp
->
fd
>=
0
)
VTCP_close
(
&
hp
->
fd
);
if
(
hp
->
sess
->
fd
>=
0
)
VTCP_close
(
&
hp
->
sess
->
fd
);
vtc_log
(
vl
,
4
,
"Accepting"
);
hp
->
fd
=
accept
(
*
hp
->
sfd
,
NULL
,
NULL
);
if
(
hp
->
fd
<
0
)
hp
->
sess
->
fd
=
accept
(
*
hp
->
sfd
,
NULL
,
NULL
);
if
(
hp
->
sess
->
fd
<
0
)
vtc_log
(
vl
,
hp
->
fatal
,
"Accepted failed: %s"
,
strerror
(
errno
));
vtc_log
(
vl
,
3
,
"Accepted socket fd is %d"
,
hp
->
fd
);
vtc_log
(
vl
,
3
,
"Accepted socket fd is %d"
,
hp
->
sess
->
fd
);
}
/* SECTION: client-server.spec.fatal
...
...
@@ -1619,12 +1619,12 @@ cmd_http_txpri(CMD_ARGS)
vtc_dump
(
hp
->
vl
,
4
,
"txpri"
,
PREFACE
,
sizeof
(
PREFACE
));
/* Dribble out the preface */
l
=
write
(
hp
->
fd
,
PREFACE
,
18
);
l
=
write
(
hp
->
sess
->
fd
,
PREFACE
,
18
);
if
(
l
!=
18
)
vtc_log
(
vl
,
hp
->
fatal
,
"Write failed: (%zd vs %zd) %s"
,
l
,
sizeof
(
PREFACE
),
strerror
(
errno
));
usleep
(
10000
);
l
=
write
(
hp
->
fd
,
PREFACE
+
18
,
sizeof
(
PREFACE
)
-
18
);
l
=
write
(
hp
->
sess
->
fd
,
PREFACE
+
18
,
sizeof
(
PREFACE
)
-
18
);
if
(
l
!=
sizeof
(
PREFACE
)
-
18
)
vtc_log
(
vl
,
hp
->
fatal
,
"Write failed: (%zd vs %zd) %s"
,
l
,
sizeof
(
PREFACE
),
strerror
(
errno
));
...
...
@@ -1808,8 +1808,8 @@ http_process_cleanup(void *arg)
}
int
http_process
(
struct
vtclog
*
vl
,
const
char
*
spec
,
int
sock
,
int
*
sfd
,
const
char
*
addr
,
int
rcvbuf
)
http_process
(
struct
vtclog
*
vl
,
struct
vtc_sess
*
vsp
,
const
char
*
spec
,
int
sock
,
int
*
sfd
,
const
char
*
addr
,
int
rcvbuf
)
{
struct
http
*
hp
;
int
retval
,
oldbuf
;
...
...
@@ -1818,7 +1818,8 @@ http_process(struct vtclog *vl, const char *spec, int sock, int *sfd,
(
void
)
sfd
;
ALLOC_OBJ
(
hp
,
HTTP_MAGIC
);
AN
(
hp
);
hp
->
fd
=
sock
;
hp
->
sess
=
vsp
;
hp
->
sess
->
fd
=
sock
;
hp
->
timeout
=
vtc_maxdur
*
1000
/
2
;
if
(
rcvbuf
)
{
...
...
@@ -1827,12 +1828,12 @@ http_process(struct vtclog *vl, const char *spec, int sock, int *sfd,
hp
->
rcvbuf
=
rcvbuf
;
oldbuf
=
0
;
AZ
(
getsockopt
(
hp
->
fd
,
SOL_SOCKET
,
SO_RCVBUF
,
&
oldbuf
,
&
intlen
));
AZ
(
setsockopt
(
hp
->
fd
,
SOL_SOCKET
,
SO_RCVBUF
,
&
rcvbuf
,
intlen
));
AZ
(
getsockopt
(
hp
->
fd
,
SOL_SOCKET
,
SO_RCVBUF
,
&
rcvbuf
,
&
intlen
));
AZ
(
getsockopt
(
hp
->
sess
->
fd
,
SOL_SOCKET
,
SO_RCVBUF
,
&
oldbuf
,
&
intlen
));
AZ
(
setsockopt
(
hp
->
sess
->
fd
,
SOL_SOCKET
,
SO_RCVBUF
,
&
rcvbuf
,
intlen
));
AZ
(
getsockopt
(
hp
->
sess
->
fd
,
SOL_SOCKET
,
SO_RCVBUF
,
&
rcvbuf
,
&
intlen
));
vtc_log
(
vl
,
3
,
"-rcvbuf fd=%d old=%d new=%d actual=%d"
,
hp
->
fd
,
oldbuf
,
hp
->
rcvbuf
,
rcvbuf
);
hp
->
sess
->
fd
,
oldbuf
,
hp
->
rcvbuf
,
rcvbuf
);
}
hp
->
nrxbuf
=
2048
*
1024
;
...
...
@@ -1868,7 +1869,7 @@ http_process(struct vtclog *vl, const char *spec, int sock, int *sfd,
}
pthread_cleanup_push
(
http_process_cleanup
,
hp
);
parse_string
(
spec
,
http_cmds
,
hp
,
vl
);
retval
=
hp
->
fd
;
retval
=
hp
->
sess
->
fd
;
pthread_cleanup_pop
(
0
);
http_process_cleanup
(
hp
);
return
(
retval
);
...
...
bin/varnishtest/vtc_http.h
View file @
79578879
...
...
@@ -30,11 +30,23 @@
#define MAX_HDR 50
struct
vtc_sess
{
unsigned
magic
;
#define VTC_SESS_MAGIC 0x932bd565
struct
vtclog
*
vl
;
char
*
name
;
int
repeat
;
int
keepalive
;
int
fd
;
ssize_t
rcvbuf
;
};
struct
http
{
unsigned
magic
;
#define HTTP_MAGIC 0x2f02169c
int
fd
;
int
*
sfd
;
struct
vtc_sess
*
sess
;
int
timeout
;
struct
vtclog
*
vl
;
...
...
@@ -76,3 +88,7 @@ struct http {
uint64_t
iws
;
int64_t
ws
;
};
int
http_process
(
struct
vtclog
*
vl
,
struct
vtc_sess
*
vsp
,
const
char
*
spec
,
int
sock
,
int
*
sfd
,
const
char
*
addr
,
int
rcvbuf
);
bin/varnishtest/vtc_http2.c
View file @
79578879
...
...
@@ -156,7 +156,7 @@ http_write(const struct http *hp, int lvl,
AN
(
pfx
);
vtc_dump
(
hp
->
vl
,
lvl
,
pfx
,
buf
,
s
);
l
=
write
(
hp
->
fd
,
buf
,
s
);
l
=
write
(
hp
->
sess
->
fd
,
buf
,
s
);
if
(
l
!=
s
)
vtc_log
(
hp
->
vl
,
hp
->
fatal
,
"Write failed: (%zd vs %d) %s"
,
l
,
s
,
strerror
(
errno
));
...
...
@@ -172,7 +172,7 @@ get_bytes(const struct http *hp, char *buf, int n)
AN
(
buf
);
while
(
n
>
0
)
{
pfd
[
0
].
fd
=
hp
->
fd
;
pfd
[
0
].
fd
=
hp
->
sess
->
fd
;
pfd
[
0
].
events
=
POLLIN
;
pfd
[
0
].
revents
=
0
;
i
=
poll
(
pfd
,
1
,
hp
->
timeout
);
...
...
@@ -181,26 +181,26 @@ get_bytes(const struct http *hp, char *buf, int n)
if
(
i
==
0
)
vtc_log
(
hp
->
vl
,
3
,
"HTTP2 rx timeout (fd:%d %u ms)"
,
hp
->
fd
,
hp
->
timeout
);
hp
->
sess
->
fd
,
hp
->
timeout
);
if
(
i
<
0
)
vtc_log
(
hp
->
vl
,
3
,
"HTTP2 rx failed (fd:%d poll: %s)"
,
hp
->
fd
,
strerror
(
errno
));
hp
->
sess
->
fd
,
strerror
(
errno
));
if
(
i
<=
0
)
return
(
i
);
i
=
read
(
hp
->
fd
,
buf
,
n
);
i
=
read
(
hp
->
sess
->
fd
,
buf
,
n
);
if
(
!
(
pfd
[
0
].
revents
&
POLLIN
))
vtc_log
(
hp
->
vl
,
4
,
"HTTP2 rx poll (fd:%d revents: %x n=%d, i=%d)"
,
hp
->
fd
,
pfd
[
0
].
revents
,
n
,
i
);
hp
->
sess
->
fd
,
pfd
[
0
].
revents
,
n
,
i
);
if
(
i
==
0
)
vtc_log
(
hp
->
vl
,
3
,
"HTTP2 rx EOF (fd:%d read: %s)"
,
hp
->
fd
,
strerror
(
errno
));
hp
->
sess
->
fd
,
strerror
(
errno
));
if
(
i
<
0
)
vtc_log
(
hp
->
vl
,
3
,
"HTTP2 rx failed (fd:%d read: %s)"
,
hp
->
fd
,
strerror
(
errno
));
hp
->
sess
->
fd
,
strerror
(
errno
));
if
(
i
<=
0
)
return
(
i
);
n
-=
i
;
...
...
@@ -334,14 +334,14 @@ write_frame(struct http *hp, const struct frame *f, const unsigned lock)
if
(
lock
)
AZ
(
pthread_mutex_lock
(
&
hp
->
mtx
));
l
=
write
(
hp
->
fd
,
hdr
,
sizeof
(
hdr
));
l
=
write
(
hp
->
sess
->
fd
,
hdr
,
sizeof
(
hdr
));
if
(
l
!=
sizeof
(
hdr
))
vtc_log
(
hp
->
vl
,
hp
->
fatal
,
"Write failed: (%zd vs %zd) %s"
,
l
,
sizeof
(
hdr
),
strerror
(
errno
));
if
(
f
->
size
)
{
AN
(
f
->
data
);
l
=
write
(
hp
->
fd
,
f
->
data
,
f
->
size
);
l
=
write
(
hp
->
sess
->
fd
,
f
->
data
,
f
->
size
);
if
(
l
!=
f
->
size
)
vtc_log
(
hp
->
vl
,
hp
->
fatal
,
"Write failed: (%zd vs %d) %s"
,
...
...
bin/varnishtest/vtc_sess.c
View file @
79578879
...
...
@@ -37,17 +37,7 @@
#include <string.h>
#include "vtc.h"
struct
vtc_sess
{
unsigned
magic
;
#define VTC_SESS_MAGIC 0x932bd565
struct
vtclog
*
vl
;
char
*
name
;
int
repeat
;
int
keepalive
;
ssize_t
rcvbuf
;
};
#include "vtc_http.h"
struct
thread_arg
{
unsigned
magic
;
...
...
@@ -113,14 +103,14 @@ Sess_GetOpt(struct vtc_sess *vsp, char * const **avp)
}
int
sess_process
(
struct
vtclog
*
vl
,
const
struct
vtc_sess
*
vsp
,
sess_process
(
struct
vtclog
*
vl
,
struct
vtc_sess
*
vsp
,
const
char
*
spec
,
int
sock
,
int
*
sfd
,
const
char
*
addr
)
{
int
rv
;
CHECK_OBJ_NOTNULL
(
vsp
,
VTC_SESS_MAGIC
);
rv
=
http_process
(
vl
,
spec
,
sock
,
sfd
,
addr
,
vsp
->
rcvbuf
);
rv
=
http_process
(
vl
,
vsp
,
spec
,
sock
,
sfd
,
addr
,
vsp
->
rcvbuf
);
return
(
rv
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment