Esempio n. 1
0
    def Pipe(duplex=True):
        '''
        Returns pair of connection objects at either end of a pipe
        '''
        address = arbitrary_address('AF_PIPE')
        if duplex:
            openmode = win32.PIPE_ACCESS_DUPLEX
            access = win32.GENERIC_READ | win32.GENERIC_WRITE
            obsize, ibsize = BUFSIZE, BUFSIZE
        else:
            openmode = win32.PIPE_ACCESS_INBOUND
            access = win32.GENERIC_WRITE
            obsize, ibsize = 0, BUFSIZE

        h1 = win32.CreateNamedPipe(
            address, openmode, win32.PIPE_TYPE_MESSAGE
            | win32.PIPE_READMODE_MESSAGE | win32.PIPE_WAIT, 1, obsize, ibsize,
            win32.NMPWAIT_WAIT_FOREVER, win32.NULL)
        h2 = win32.CreateFile(address, access, 0, win32.NULL,
                              win32.OPEN_EXISTING, 0, win32.NULL)
        win32.SetNamedPipeHandleState(h2, win32.PIPE_READMODE_MESSAGE, None,
                                      None)

        try:
            win32.ConnectNamedPipe(h1, win32.NULL)
        except WindowsError, e:
            if e.args[0] != win32.ERROR_PIPE_CONNECTED:
                raise
Esempio n. 2
0
    def PipeClient(address):
        '''
        Return a connection object connected to the pipe given by `address`
        '''
        t = _init_timeout()
        while 1:
            try:
                win32.WaitNamedPipe(address, 1000)
                h = win32.CreateFile(address,
                                     win32.GENERIC_READ | win32.GENERIC_WRITE,
                                     0, win32.NULL, win32.OPEN_EXISTING, 0,
                                     win32.NULL)
            except WindowsError as e:
                if e.args[0] not in (
                        win32.ERROR_SEM_TIMEOUT,
                        win32.ERROR_PIPE_BUSY) or _check_timeout(t):
                    raise
            else:
                break
        else:
            raise

        win32.SetNamedPipeHandleState(h, win32.PIPE_READMODE_MESSAGE, None,
                                      None)
        return _multiprocessing.PipeConnection(h)
    def test_pipe(self):
        from _multiprocess import win32
        import os
        address = r'\\.\pipe\pypy-test-%s' % (os.getpid())
        openmode = win32.PIPE_ACCESS_INBOUND
        access = win32.GENERIC_WRITE
        obsize, ibsize = 0, 8192
        readhandle = win32.CreateNamedPipe(
            address, openmode, win32.PIPE_TYPE_MESSAGE
            | win32.PIPE_READMODE_MESSAGE | win32.PIPE_WAIT, 1, obsize, ibsize,
            win32.NMPWAIT_WAIT_FOREVER, win32.NULL)
        writehandle = win32.CreateFile(address, access, 0, win32.NULL,
                                       win32.OPEN_EXISTING, 0, win32.NULL)
        win32.SetNamedPipeHandleState(writehandle, win32.PIPE_READMODE_MESSAGE,
                                      None, None)

        try:
            win32.ConnectNamedPipe(readhandle, win32.NULL)
        except WindowsError as e:
            if e.args[0] != win32.ERROR_PIPE_CONNECTED:
                raise

        timeout = 100
        exc = raises(WindowsError, win32.WaitNamedPipe, address, timeout)
        assert exc.value.winerror == 121  # ERROR_SEM_TIMEOUT

        win32.CloseHandle(readhandle)
        win32.CloseHandle(writehandle)
Esempio n. 4
0
                win32.WaitNamedPipe(address, 1000)
                h = win32.CreateFile(address,
                                     win32.GENERIC_READ | win32.GENERIC_WRITE,
                                     0, win32.NULL, win32.OPEN_EXISTING, 0,
                                     win32.NULL)
            except WindowsError, e:
                if e.args[0] not in (
                        win32.ERROR_SEM_TIMEOUT,
                        win32.ERROR_PIPE_BUSY) or _check_timeout(t):
                    raise
            else:
                break
        else:
            raise

        win32.SetNamedPipeHandleState(h, win32.PIPE_READMODE_MESSAGE, None,
                                      None)
        return _multiprocessing.PipeConnection(h)


#
# Authentication stuff
#

MESSAGE_LENGTH = 20

CHALLENGE = b'#CHALLENGE#'
WELCOME = b'#WELCOME#'
FAILURE = b'#FAILURE#'


def deliver_challenge(connection, authkey):