def __init__(self, socket, name, status, pipe=None, is_server=False):
        self.socket = socket
        self.pipe = pipe
        if sys.platform == 'win32':
            if pipe is not None:
                # Flag to check if fd is a server HANDLE.  In the case of a
                # server handle we have to issue a disconnect before closing
                # the actual handle.
                self._server = is_server
                suffix = name.split(":", 1)[1]
                suffix = ovs.util.abs_file_name(ovs.dirs.RUNDIR, suffix)
                self._pipename = winutils.get_pipe_name(suffix)
                self._read = pywintypes.OVERLAPPED()
                self._read.hEvent = winutils.get_new_event()
                self._write = pywintypes.OVERLAPPED()
                self._write.hEvent = winutils.get_new_event()
            else:
                self._wevent = winutils.get_new_event(bManualReset=False,
                                                      bInitialState=False)

        self.name = name
        if status == errno.EAGAIN:
            self.state = Stream.__S_CONNECTING
        elif status == 0:
            self.state = Stream.__S_CONNECTED
        else:
            self.state = Stream.__S_DISCONNECTED

        self.error = 0
Example #2
0
    def __init__(self, socket, name, status, pipe=None, is_server=False):
        self.socket = socket
        self.pipe = pipe
        if sys.platform == 'win32':
            self._read = pywintypes.OVERLAPPED()
            self._read.hEvent = winutils.get_new_event()
            self._write = pywintypes.OVERLAPPED()
            self._write.hEvent = winutils.get_new_event()
            if pipe is not None:
                # Flag to check if fd is a server HANDLE.  In the case of a
                # server handle we have to issue a disconnect before closing
                # the actual handle.
                self._server = is_server
                suffix = name.split(":", 1)[1]
                suffix = ovs.util.abs_file_name(ovs.dirs.RUNDIR, suffix)
                self._pipename = winutils.get_pipe_name(suffix)

        self.name = name
        if status == errno.EAGAIN:
            self.state = Stream.__S_CONNECTING
        elif status == 0:
            self.state = Stream.__S_CONNECTED
        else:
            self.state = Stream.__S_DISCONNECTED

        self.error = 0
Example #3
0
def check_connection_completion(sock):
    p = ovs.poller.SelectPoll()
    if sys.platform == "win32":
        event = winutils.get_new_event(None, False, True, None)
        # Receive notification of readiness for writing, of completed
        # connection or multipoint join operation, and of socket closure.
        win32file.WSAEventSelect(sock, event,
                                 win32file.FD_WRITE |
                                 win32file.FD_CONNECT |
                                 win32file.FD_CLOSE)
        p.register(event, ovs.poller.POLLOUT)
    else:
        p.register(sock, ovs.poller.POLLOUT)
    pfds = p.poll(0)
    if len(pfds) == 1:
        revents = pfds[0][1]
        if revents & ovs.poller.POLLERR:
            try:
                # The following should raise an exception.
                socket.send("\0", socket.MSG_DONTWAIT)

                # (Here's where we end up if it didn't.)
                # XXX rate-limit
                vlog.err("poll return POLLERR but send succeeded")
                return errno.EPROTO
            except socket.error as e:
                return get_exception_errno(e)
        else:
            return 0
    else:
        return errno.EAGAIN
Example #4
0
def check_connection_completion(sock):
    if sys.platform == "win32":
        p = ovs.poller.SelectPoll()
        event = winutils.get_new_event(None, False, True, None)
        # Receive notification of readiness for writing, of completed
        # connection or multipoint join operation, and of socket closure.
        win32file.WSAEventSelect(sock, event,
                                 win32file.FD_WRITE |
                                 win32file.FD_CONNECT |
                                 win32file.FD_CLOSE)
        p.register(event, ovs.poller.POLLOUT)
    else:
        p = ovs.poller.get_system_poll()
        p.register(sock, ovs.poller.POLLOUT)
    pfds = p.poll(0)
    if len(pfds) == 1:
        revents = pfds[0][1]
        if revents & ovs.poller.POLLERR or revents & ovs.poller.POLLHUP:
            try:
                # The following should raise an exception.
                sock.send("\0".encode(), socket.MSG_DONTWAIT)

                # (Here's where we end up if it didn't.)
                # XXX rate-limit
                vlog.err("poll return POLLERR but send succeeded")
                return errno.EPROTO
            except socket.error as e:
                return get_exception_errno(e)
        else:
            return 0
    else:
        return errno.EAGAIN
 def init_alert_notification(self):
     # We will use an event to get signaled when there is something in
     # the queue. The OVS poller can wait on events on Windows.
     # NOTE(abalutoiu) The assumption made is that the queue has
     # length 1, otherwise we will need to have a list of events with
     # the size of the queue.
     self.alert_event = winutils.get_new_event(bManualReset=True,
                                               bInitialState=False)
Example #6
0
    def __init__(self, sock, name, bind_path, pipe=None):
        self.name = name
        self.pipe = pipe
        self.socket = sock
        if pipe is not None:
            self.connect = pywintypes.OVERLAPPED()
            self.connect.hEvent = winutils.get_new_event(bManualReset=True)
            self.connect_pending = False
            suffix = name.split(":", 1)[1]
            suffix = ovs.util.abs_file_name(ovs.dirs.RUNDIR, suffix)
            self._pipename = winutils.get_pipe_name(suffix)

        self.bind_path = bind_path
    def __init__(self, sock, name, bind_path, pipe=None):
        self.name = name
        self.pipe = pipe
        self.socket = sock
        if pipe is not None:
            self.connect = pywintypes.OVERLAPPED()
            self.connect.hEvent = winutils.get_new_event()
            self.connect_pending = False
            suffix = name.split(":", 1)[1]
            suffix = ovs.util.abs_file_name(ovs.dirs.RUNDIR, suffix)
            self._pipename = winutils.get_pipe_name(suffix)

        self.bind_path = bind_path
Example #8
0
    def __init__(self, pipe_name=None, sec_attributes=-1):
        """Create a named pipe with the given name.

        :param pipe_name(Optional): string representing the name of the pipe
            which should be used to create the named pipe
        :param sec_attributes(Optional): type win32security.SECURITY_ATTRIBUTES
            The default value is -1 which uses the default security attributes.
            This means that the named pipe handle is inherited when a new
            process is created.
        """
        # For reading from the named pipe, we will use an overlapped structure
        # for non-blocking I/O
        self._read = ovs_winutils.pywintypes.OVERLAPPED()
        # Create a new event which will be used by the overlapped structure
        self._read.hEvent = ovs_winutils.get_new_event()
        # This property tells if there is a pending reading operation on
        # the named pipe or not.
        self._read_pending = False

        if pipe_name is None:
            # Generate a random name for the named pipe if the name was not
            # passed explicitly as parameter.
            pipe_name = ("NamedPipe_%d_%s" %
                         (time.time(), str(random.random()).split(".")[1]))

        # Creating the name for a local named pipe. The property "name" will
        # have "\\.\pipe\" appended at the start of pipe_name
        self.name = ovs_winutils.get_pipe_name(pipe_name)
        # This property will contain the handle of the named pipe which can
        # be accessed later on.
        self.namedpipe = ovs_winutils.create_named_pipe(self.name,
                                                        saAttr=sec_attributes)
        # This property should be initialised explicitly later on by calling
        # the method create_file of this class.
        self._npipe_file = None

        if not self.namedpipe:
            # If there was an error when creating the named pipe, the property
            # "namedpipe" should be None. We raise an exception in this case
            raise NamedPipeException("Failed to create named pipe.")