diff options
author | Yiting.Li <liyiting@huawei.com> | 2015-12-22 17:11:12 -0800 |
---|---|---|
committer | Yiting.Li <liyiting@huawei.com> | 2015-12-22 17:11:12 -0800 |
commit | 8f1101df131a4d3e03b377738507d88b745831c0 (patch) | |
tree | 73f140474fcec2a77c85a453f6946957ca0742d1 /vstf/vstf/common/unix.py | |
parent | 1a24ebbda3f95600c0e7d5ed8661317a8ff7e265 (diff) |
Upload the contribution of vstf as bottleneck network framework.
End to End Performance test
JIRA:BOTTLENECK-29
Change-Id: Ib2c553c8b60d6cda9e7a7b52b737c9139f706ebd
Signed-off-by: Yiting.Li <liyiting@huawei.com>
Diffstat (limited to 'vstf/vstf/common/unix.py')
-rwxr-xr-x | vstf/vstf/common/unix.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/vstf/vstf/common/unix.py b/vstf/vstf/common/unix.py new file mode 100755 index 00000000..f74944e2 --- /dev/null +++ b/vstf/vstf/common/unix.py @@ -0,0 +1,53 @@ +import os +import socket +from vstf.common import constants +from vstf.common import message + + +class UdpServer(object): + def __init__(self): + super(UdpServer, self).__init__() + try: + os.unlink(constants.sockaddr) + except OSError: + if os.path.exists(constants.sockaddr): + raise Exception("socket not found %s" % constants.sockaddr) + self.conn=socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + + def listen(self,backlog=5): + self.conn.listen(backlog) + + def accept(self): + return self.conn.accept() + + def bind(self, addr=constants.sockaddr): + return self.conn.bind(addr) + +# def send(self, data, addr): +# return message.sendto(self.conn.sendto, data, addr) + +# def recv(self, size=constants.buff_size): +# return message.recv(self.conn.recvfrom) + + def close(self): + self.conn.close() + + +class UdpClient(object): + def __init__(self): + super(UdpClient, self).__init__() + if not os.path.exists(constants.sockaddr): + raise Exception("socket not found %s" % constants.sockaddr) + self.conn=socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + + def connect(self, addr=constants.sockaddr): + return self.conn.connect(addr) + + def send(self, data): + message.send(self.conn.send, data) + + def recv(self): + return message.recv(self.conn.recv) + + def close(self): + self.conn.close()
\ No newline at end of file |