[ovs-dev] [PATCH V6 11/17] python tests: Ported UNIX sockets to Windows
Alin Serdean
aserdean at cloudbasesolutions.com
Tue Jul 12 19:10:51 UTC 2016
Thanks for the patch. I will change the test after the named pipe implementation gets in.
Acked-by: Alin Gabriel Serdean <aserdean at cloudbasesolutions.com>
> -----Mesaj original-----
> De la: dev [mailto:dev-bounces at openvswitch.org] În numele Paul Boca
> Trimis: Wednesday, July 6, 2016 3:38 PM
> Către: dev at openvswitch.org
> Subiect: [ovs-dev] [PATCH V6 11/17] python tests: Ported UNIX sockets to
> Windows
>
> AF_UNIX sockets are not supported on Windows.
> Instead of an AF_UNIX socket use localhost tcp connections to communicate
> between components. This makes the python sockets compatible with the
> ones used in Windows applications.
>
> In case the socket returns WSAEWOULDBLOCK, it is replaced by EAGAIN
> error in order to be compatible with Windows.
>
> Signed-off-by: Paul-Daniel Boca <pboca at cloudbasesolutions.com>
> + if sys.platform == "win32":
> + sock.bind(("127.0.0.1", 0))
> + compat_write_unix_socket(bind_path, sock.getsockname()[1])
> + else:
> + sock.bind(bind_path)
>
> - try:
> - os.fchmod(sock.fileno(), 0o700)
> - except OSError as e:
> - pass
> + try:
> + os.fchmod(sock.fileno(), 0o700)
> + except OSError as e:
> + pass
> if connect_path is not None:
> try:
> - sock.connect(connect_path)
> + if sys.platform == "win32":
> + port = compat_read_unix_socket(connect_path)
> + sock.connect(("127.0.0.1", port))
> + else:
> + sock.connect(connect_path)
> except socket.error as e:
> - if get_exception_errno(e) != errno.EINPROGRESS:
> + error = get_exception_errno(e)
> + if sys.platform == "win32" and error == errno.WSAEWOULDBLOCK:
> + error = errno.EINPROGRESS
> + if error != errno.EINPROGRESS:
> raise
> return 0, sock
> except socket.error as e:
> @@ -228,7 +260,10 @@ def inet_open_active(style, target, default_port,
> dscp):
> try:
> sock.connect(address)
> except socket.error as e:
> - if get_exception_errno(e) != errno.EINPROGRESS:
> + error = get_exception_errno(e)
> + if sys.platform == "win32" and error == errno.WSAEWOULDBLOCK:
> + error = errno.EINPROGRESS
> + if error != errno.EINPROGRESS:
> raise
> return 0, sock
> except socket.error as e:
> diff --git a/python/ovs/stream.py b/python/ovs/stream.py index
> 97b22ac..fd894d9 100644
> --- a/python/ovs/stream.py
> +++ b/python/ovs/stream.py
> @@ -15,7 +15,7 @@
> import errno
> import os
> import socket
> -
> +import sys
> import six
>
> import ovs.poller
> @@ -136,6 +136,8 @@ class Stream(object):
> if not error:
> while True:
> error = stream.connect()
> + if sys.platform == "win32" and error == errno.WSAEWOULDBLOCK:
> + error = errno.EAGAIN
> if error != errno.EAGAIN:
> break
> stream.run()
> @@ -338,7 +340,7 @@ class PassiveStream(object):
> try:
> sock, addr = self.socket.accept()
> ovs.socket_util.set_nonblocking(sock)
> - if (sock.family == socket.AF_UNIX):
> + if (sys.platform != "win32") and (sock.family == socket.AF_UNIX):
> return 0, Stream(sock, "unix:%s" % addr, 0)
> return 0, Stream(sock, 'ptcp:%s:%s' % (addr[0],
> str(addr[1])), 0) diff --git
> a/python/ovs/unixctl/server.py b/python/ovs/unixctl/server.py index
> cc712bf..4aa02bb 100644
> --- a/python/ovs/unixctl/server.py
> +++ b/python/ovs/unixctl/server.py
> @@ -15,6 +15,7 @@
> import copy
> import errno
> import os
> +import sys
>
> import six
> from six.moves import range
> @@ -147,6 +148,8 @@ class UnixctlServer(object):
> def run(self):
> for _ in range(10):
> error, stream = self._listener.accept()
> + if sys.platform == "win32" and error == errno.WSAEWOULDBLOCK:
> + error = errno.EAGAIN
> if not error:
> rpc = ovs.jsonrpc.Connection(stream)
> self._conns.append(UnixctlConnection(rpc))
> @@ -154,8 +157,8 @@ class UnixctlServer(object):
> break
> else:
> # XXX: rate-limit
> - vlog.warn("%s: accept failed: %s" % (self._listener.name,
> - os.strerror(error)))
> + vlog.warn("%s: accept failed: %s %d %d" % (self._listener.name,
> +
> + os.strerror(error), error))
>
> for conn in copy.copy(self._conns):
> error = conn.run()
> @@ -188,8 +191,12 @@ class UnixctlServer(object):
> if path is not None:
> path = "punix:%s" % ovs.util.abs_file_name(ovs.dirs.RUNDIR, path)
> else:
> - path = "punix:%s/%s.%d.ctl" % (ovs.dirs.RUNDIR,
> - ovs.util.PROGRAM_NAME, os.getpid())
> + if sys.platform == "win32":
> + path = "punix:%s/%s.ctl" % (ovs.dirs.RUNDIR,
> + ovs.util.PROGRAM_NAME)
> + else:
> + path = "punix:%s/%s.%d.ctl" % (ovs.dirs.RUNDIR,
> + ovs.util.PROGRAM_NAME,
> + os.getpid())
>
> if version is None:
> version = ovs.version.VERSION
> --
> 2.7.2.windows.1
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev
More information about the dev
mailing list