Merge branch 'locking-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[cris-mirror.git] / tools / testing / selftests / bpf / tcp_client.py
blob481dccdf140ceb9240667c4fd987d71195a450e8
1 #!/usr/bin/env python2
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 = ''
13 while len(buf) < n:
14 rem = n - len(buf)
15 try: s = sock.recv(rem)
16 except (socket.error), e: return ''
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), e: n = 0
26 if n == 0:
27 return count;
28 count += n
29 return count
32 serverPort = int(sys.argv[1])
33 HostName = socket.gethostname()
35 # create active socket
36 sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
37 try:
38 sock.connect((HostName, serverPort))
39 except socket.error as e:
40 sys.exit(1)
42 buf = ''
43 n = 0
44 while n < 1000:
45 buf += '+'
46 n += 1
48 sock.settimeout(1);
49 n = send(sock, buf)
50 n = read(sock, 500)
51 sys.exit(0)