Beispiel #1
0
    def PipeClient(address):
        '''
        Return a connection object connected to the pipe given by `address`
        '''
        t = _init_timeout()
        while 1:
            try:
                _winapi.WaitNamedPipe(address, 1000)
                h = _winapi.CreateFile(
                    address, _winapi.GENERIC_READ | _winapi.GENERIC_WRITE, 0,
                    _winapi.NULL, _winapi.OPEN_EXISTING,
                    _winapi.FILE_FLAG_OVERLAPPED, _winapi.NULL)
            except OSError as e:
                if e.winerror not in (
                        _winapi.ERROR_SEM_TIMEOUT,
                        _winapi.ERROR_PIPE_BUSY) or _check_timeout(t):
                    raise
            else:
                break
        else:
            raise

        _winapi.SetNamedPipeHandleState(h, _winapi.PIPE_READMODE_MESSAGE, None,
                                        None)
        return PipeConnection(h)
Beispiel #2
0
 def __init__(self, name: str, timeout: Optional[float]) -> None:
     super().__init__(name, timeout)
     if sys.platform == 'win32':
         timeout = int(
             self.timeout *
             1000) if self.timeout else _winapi.NMPWAIT_WAIT_FOREVER
         try:
             _winapi.WaitNamedPipe(self.name, timeout)
         except FileNotFoundError as e:
             raise IPCException(
                 f"The NamedPipe at {self.name} was not found.") from e
         except OSError as e:
             if e.winerror == _winapi.ERROR_SEM_TIMEOUT:
                 raise IPCException(
                     "Timed out waiting for connection.") from e
             else:
                 raise
         try:
             self.connection = _winapi.CreateFile(
                 self.name,
                 _winapi.GENERIC_READ | _winapi.GENERIC_WRITE,
                 0,
                 _winapi.NULL,
                 _winapi.OPEN_EXISTING,
                 _winapi.FILE_FLAG_OVERLAPPED,
                 _winapi.NULL,
             )
         except OSError as e:
             if e.winerror == _winapi.ERROR_PIPE_BUSY:
                 raise IPCException("The connection is busy.") from e
             else:
                 raise
         _winapi.SetNamedPipeHandleState(self.connection,
                                         _winapi.PIPE_READMODE_MESSAGE,
                                         None, None)
     else:
         self.connection = socket.socket(socket.AF_UNIX)
         self.connection.settimeout(timeout)
         self.connection.connect(name)
Beispiel #3
0
 def __init__(self, name: str, timeout: Optional[int]) -> None:
     super().__init__(name)
     if sys.platform == 'win32':
         timeout = timeout or 0xFFFFFFFF  # NMPWAIT_WAIT_FOREVER
         try:
             _winapi.WaitNamedPipe(self.name, timeout)
         except FileNotFoundError:
             raise IPCException("The NamedPipe at {} was not found.".format(self.name))
         except WindowsError as e:
             if e.winerror == _winapi.ERROR_SEM_TIMEOUT:
                 raise IPCException("Timed out waiting for connection.")
             else:
                 raise
         try:
             self.connection = _winapi.CreateFile(
                 self.name,
                 _winapi.GENERIC_READ | _winapi.GENERIC_WRITE,
                 0,
                 _winapi.NULL,
                 _winapi.OPEN_EXISTING,
                 0,
                 _winapi.NULL,
             )
         except WindowsError as e:
             if e.winerror == _winapi.ERROR_PIPE_BUSY:
                 raise IPCException("The connection is busy.")
             else:
                 raise
         _winapi.SetNamedPipeHandleState(self.connection,
                                         _winapi.PIPE_READMODE_MESSAGE,
                                         None,
                                         None)
     else:
         self.connection = socket.socket(socket.AF_UNIX)
         self.connection.settimeout(timeout)
         self.connection.connect(name)