File: test-sockpair.py

package info (click to toggle)
haproxy 3.2.8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 23,880 kB
  • sloc: ansic: 267,692; sh: 3,277; xml: 1,756; python: 1,345; makefile: 1,155; perl: 168; cpp: 21
file content (28 lines) | stat: -rw-r--r-- 577 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/python
"""
Python wrapper example to test socketpair protocol
./test-socketpair.py test.cfg

use sockpair@${FD1} and sockpair@${FD2} in your configuration file

"""

import socket, os, sys

s = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM)
os.set_inheritable(s[0].fileno(), 1)
os.set_inheritable(s[1].fileno(), 1)

FD1 = s[0].fileno()
FD2 = s[1].fileno()

print("FD1={} FD2={}".format(FD1, FD2))

os.environ["FD1"] = str(FD1)
os.environ["FD2"] = str(FD2)

cmd = ["./haproxy",
       "-f",
       "{}".format(sys.argv[1])
]
os.execve(cmd[0], cmd, os.environ)