Merge "Change PTL informatin in INFO"
[bottlenecks.git] / testsuites / vstf / vstf_scripts / vstf / common / unix.py
1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10 import os
11 import socket
12 from vstf.common import constants
13 from vstf.common import message
14
15
16 class UdpServer(object):
17
18     def __init__(self):
19         super(UdpServer, self).__init__()
20         try:
21             os.unlink(constants.sockaddr)
22         except OSError:
23             if os.path.exists(constants.sockaddr):
24                 raise Exception("socket not found %s" % constants.sockaddr)
25         self.conn = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
26
27     def listen(self, backlog=5):
28         self.conn.listen(backlog)
29
30     def accept(self):
31         return self.conn.accept()
32
33     def bind(self, addr=constants.sockaddr):
34         return self.conn.bind(addr)
35
36 #     def send(self, data, addr):
37 #         return message.sendto(self.conn.sendto, data, addr)
38
39 #     def recv(self, size=constants.buff_size):
40 #         return message.recv(self.conn.recvfrom)
41
42     def close(self):
43         self.conn.close()
44
45
46 class UdpClient(object):
47
48     def __init__(self):
49         super(UdpClient, self).__init__()
50         if not os.path.exists(constants.sockaddr):
51             raise Exception("socket not found %s" % constants.sockaddr)
52         self.conn = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
53
54     def connect(self, addr=constants.sockaddr):
55         return self.conn.connect(addr)
56
57     def send(self, data):
58         message.send(self.conn.send, data)
59
60     def recv(self):
61         return message.recv(self.conn.recv)
62
63     def close(self):
64         self.conn.close()