"Fossies" - the Fresh Open Source Software Archive

Member "haproxy-2.0.0/tests/test-sockpair.py" (16 Jun 2019, 577 Bytes) of package /linux/misc/haproxy-2.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/usr/bin/python
    2 """
    3 Python wrapper example to test socketpair protocol
    4 ./test-socketpair.py test.cfg
    5 
    6 use sockpair@${FD1} and sockpair@${FD2} in your configuration file
    7 
    8 """
    9 
   10 import socket, os, sys
   11 
   12 s = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM)
   13 os.set_inheritable(s[0].fileno(), 1)
   14 os.set_inheritable(s[1].fileno(), 1)
   15 
   16 FD1 = s[0].fileno()
   17 FD2 = s[1].fileno()
   18 
   19 print("FD1={} FD2={}".format(FD1, FD2))
   20 
   21 os.environ["FD1"] = str(FD1)
   22 os.environ["FD2"] = str(FD2)
   23 
   24 cmd = ["./haproxy",
   25        "-f",
   26        "{}".format(sys.argv[1])
   27 ]
   28 os.execve(cmd[0], cmd, os.environ)