diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 10:05:51 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 10:05:51 +0000 |
commit | 5d1646d90e1f2cceb9f0828f4b28318cd0ec7744 (patch) | |
tree | a94efe259b9009378be6d90eb30d2b019d95c194 /tools/testing/selftests/bpf/tcp_client.py | |
parent | Initial commit. (diff) | |
download | linux-upstream.tar.xz linux-upstream.zip |
Adding upstream version 5.10.209.upstream/5.10.209upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tools/testing/selftests/bpf/tcp_client.py')
-rwxr-xr-x | tools/testing/selftests/bpf/tcp_client.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/tcp_client.py b/tools/testing/selftests/bpf/tcp_client.py new file mode 100755 index 000000000..bfff82be3 --- /dev/null +++ b/tools/testing/selftests/bpf/tcp_client.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 +# +# SPDX-License-Identifier: GPL-2.0 +# + +import sys, os, os.path, getopt +import socket, time +import subprocess +import select + +def read(sock, n): + buf = b'' + while len(buf) < n: + rem = n - len(buf) + try: s = sock.recv(rem) + except (socket.error) as e: return b'' + buf += s + return buf + +def send(sock, s): + total = len(s) + count = 0 + while count < total: + try: n = sock.send(s) + except (socket.error) as e: n = 0 + if n == 0: + return count; + count += n + return count + + +serverPort = int(sys.argv[1]) + +# create active socket +sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) +try: + sock.connect(('::1', serverPort)) +except socket.error as e: + sys.exit(1) + +buf = b'' +n = 0 +while n < 1000: + buf += b'+' + n += 1 + +sock.settimeout(1); +n = send(sock, buf) +n = read(sock, 500) +sys.exit(0) |