treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / tools / testing / selftests / bpf / tcp_client.py
bloba53ed58528d6166b55ae5160fae02ceac39ced9f
1 #!/usr/bin/env python3
3 # SPDX-License-Identifier: GPL-2.0
6 import sys, os, os.path, getopt
7 import socket, time
8 import subprocess
9 import select
11 def read(sock, n):
12 buf = b''
13 while len(buf) < n:
14 rem = n - len(buf)
15 try: s = sock.recv(rem)
16 except (socket.error) as e: return b''
17 buf += s
18 return buf
20 def send(sock, s):
21 total = len(s)
22 count = 0
23 while count < total:
24 try: n = sock.send(s)
25 except (socket.error) as e: n = 0
26 if n == 0:
27 return count;
28 count += n
29 return count
32 serverPort = int(sys.argv[1])
34 # create active socket
35 sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
36 try:
37 sock.connect(('localhost', serverPort))
38 except socket.error as e:
39 sys.exit(1)
41 buf = b''
42 n = 0
43 while n < 1000:
44 buf += b'+'
45 n += 1
47 sock.settimeout(1);
48 n = send(sock, buf)
49 n = read(sock, 500)
50 sys.exit(0)