]> git.proxmox.com Git - ovs.git/blob - tests/test-unix-socket.py
5a3f3c0e3cfe3993d0dd8b03cf927f0fd398180f
[ovs.git] / tests / test-unix-socket.py
1 #
2 # Copyright (c) 2010, 2012, 2013 Nicira, Inc.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 import os
17 import signal
18 import socket
19 import sys
20
21 import ovs.socket_util
22
23 def main(argv):
24 if len(argv) not in (2, 3):
25 sys.stderr.write("usage: %s SOCKETNAME1 [SOCKETNAME2]", argv[0])
26 sys.exit(1)
27
28 sockname1 = argv[1]
29 if len(argv) > 2:
30 sockname2 = argv[2]
31 else:
32 sockname2 = sockname1
33
34 signal.signal(signal.SIGALRM, signal.SIG_DFL)
35 signal.alarm(5)
36
37 # Create a listening socket under name 'sockname1'.
38 error, sock1 = ovs.socket_util.make_unix_socket(socket.SOCK_STREAM, False,
39 sockname1, None)
40 if error:
41 sys.stderr.write("%s: bind failed (%s)" % (sockname1,
42 os.strerror(error)))
43 sock1.listen(1)
44
45 # Connect to 'sockname2' (which should be the same file, perhaps under a
46 # different name).
47 error, sock2 = ovs.socket_util.make_unix_socket(socket.SOCK_STREAM, False,
48 None, sockname2)
49 if error:
50 sys.stderr.write("%s: connect failed (%s)" % (sockname2,
51 os.strerror(error)))
52
53 if __name__ == '__main__':
54 main(sys.argv)