def test_pipe_overlapped(self):
     h1, h2 = windows_utils.pipe(overlapped=(True, True))
     try:
         ov1 = _overlapped.Overlapped()
         self.assertFalse(ov1.pending)
         self.assertEqual(ov1.error, 0)
         ov1.ReadFile(h1, 100)
         self.assertTrue(ov1.pending)
         self.assertEqual(ov1.error, _winapi.ERROR_IO_PENDING)
         ERROR_IO_INCOMPLETE = 996
         try:
             ov1.getresult()
         except OSError as e:
             self.assertEqual(e.winerror, ERROR_IO_INCOMPLETE)
         else:
             raise RuntimeError('expected ERROR_IO_INCOMPLETE')
         ov2 = _overlapped.Overlapped()
         self.assertFalse(ov2.pending)
         self.assertEqual(ov2.error, 0)
         ov2.WriteFile(h2, b'hello')
         self.assertIn(ov2.error, {0, _winapi.ERROR_IO_PENDING})
         res = _winapi.WaitForMultipleObjects([ov2.event], False, 100)
         self.assertEqual(res, _winapi.WAIT_OBJECT_0)
         self.assertFalse(ov1.pending)
         self.assertEqual(ov1.error, ERROR_IO_INCOMPLETE)
         self.assertFalse(ov2.pending)
         self.assertIn(ov2.error, {0, _winapi.ERROR_IO_PENDING})
         self.assertEqual(ov1.getresult(), b'hello')
     finally:
         _winapi.CloseHandle(h1)
         _winapi.CloseHandle(h2)
예제 #2
0
def pipe_with_overlapped_read():
    from asyncio.windows_utils import pipe
    import msvcrt

    read_handle, write_handle = pipe(overlapped=(True, False))
    try:
        write_fd = msvcrt.open_osfhandle(write_handle, 0)
        yield os.fdopen(write_fd, "wb", closefd=False), read_handle
    finally:
        kernel32.CloseHandle(ffi.cast("HANDLE", read_handle))
        kernel32.CloseHandle(ffi.cast("HANDLE", write_handle))
예제 #3
0
async def test_pipe_error_on_close():
    # Make sure we correctly handle a failure from kernel32.CloseHandle
    r, w = pipe()

    send_stream = PipeSendStream(w)
    receive_stream = PipeReceiveStream(r)

    assert kernel32.CloseHandle(_handle(r))
    assert kernel32.CloseHandle(_handle(w))

    with pytest.raises(OSError):
        await send_stream.aclose()
    with pytest.raises(OSError):
        await receive_stream.aclose()
예제 #4
0
    def test_pipe_handle(self):
        h, _ = windows_utils.pipe(overlapped=(True, True))
        _winapi.CloseHandle(_)
        p = windows_utils.PipeHandle(h)
        self.assertEqual(p.fileno(), h)
        self.assertEqual(p.handle, h)

        # check garbage collection of p closes handle
        del p
        test.support.gc_collect()
        try:
            _winapi.CloseHandle(h)
        except OSError as e:
            self.assertEqual(e.winerror, 6)     # ERROR_INVALID_HANDLE
        else:
            raise RuntimeError('expected ERROR_INVALID_HANDLE')
    def test_pipe_handle(self):
        h, _ = windows_utils.pipe(overlapped=(True, True))
        _winapi.CloseHandle(_)
        p = windows_utils.PipeHandle(h)
        self.assertEqual(p.fileno(), h)
        self.assertEqual(p.handle, h)

        # check garbage collection of p closes handle
        del p
        support.gc_collect()
        try:
            _winapi.CloseHandle(h)
        except OSError as e:
            self.assertEqual(e.winerror, 6)  # ERROR_INVALID_HANDLE
        else:
            raise RuntimeError('expected ERROR_INVALID_HANDLE')
 def test_pipe_handle(self):
     h, _ = windows_utils.pipe(overlapped=(True, True))
     _winapi.CloseHandle(_)
     p = windows_utils.PipeHandle(h)
     self.assertEqual(p.fileno(), h)
     self.assertEqual(p.handle, h)
     with warnings.catch_warnings():
         warnings.filterwarnings('ignore', '', ResourceWarning)
         del p
         support.gc_collect()
     try:
         _winapi.CloseHandle(h)
     except OSError as e:
         self.assertEqual(e.winerror, 6)
     else:
         raise RuntimeError('expected ERROR_INVALID_HANDLE')
예제 #7
0
    def test_pipe_handle(self):
        h, _ = windows_utils.pipe(overlapped=(True, True))
        _winapi.CloseHandle(_)
        p = windows_utils.PipeHandle(h)
        self.assertEqual(p.fileno(), h)
        self.assertEqual(p.handle, h)

        # check garbage collection of p closes handle
        with warnings.catch_warnings():
            warnings.filterwarnings("ignore", "",  ResourceWarning)
            del p
            support.gc_collect()
        try:
            _winapi.CloseHandle(h)
        except OSError as e:
            self.assertEqual(e.winerror, 6)     # ERROR_INVALID_HANDLE
        else:
            raise RuntimeError('expected ERROR_INVALID_HANDLE')
예제 #8
0
    def test_pipe_overlapped(self):
        h1, h2 = windows_utils.pipe(overlapped=(True, True))
        try:
            ov1 = _overlapped.Overlapped()
            self.assertFalse(ov1.pending)
            self.assertEqual(ov1.error, 0)

            ov1.ReadFile(h1, 100)
            self.assertTrue(ov1.pending)
            self.assertEqual(ov1.error, _winapi.ERROR_IO_PENDING)
            ERROR_IO_INCOMPLETE = 996
            try:
                ov1.getresult()
            except OSError as e:
                self.assertEqual(e.winerror, ERROR_IO_INCOMPLETE)
            else:
                raise RuntimeError('expected ERROR_IO_INCOMPLETE')

            ov2 = _overlapped.Overlapped()
            self.assertFalse(ov2.pending)
            self.assertEqual(ov2.error, 0)

            ov2.WriteFile(h2, b"hello")
            self.assertIn(ov2.error, {0, _winapi.ERROR_IO_PENDING})

            res = _winapi.WaitForMultipleObjects([ov2.event], False, 100)
            self.assertEqual(res, _winapi.WAIT_OBJECT_0)

            self.assertFalse(ov1.pending)
            self.assertEqual(ov1.error, ERROR_IO_INCOMPLETE)
            self.assertFalse(ov2.pending)
            self.assertIn(ov2.error, {0, _winapi.ERROR_IO_PENDING})
            self.assertEqual(ov1.getresult(), b"hello")
        finally:
            _winapi.CloseHandle(h1)
            _winapi.CloseHandle(h2)
예제 #9
0
async def make_pipe() -> "Tuple[PipeSendStream, PipeReceiveStream]":
    """Makes a new pair of pipes."""
    (r, w) = pipe()
    return PipeSendStream(w), PipeReceiveStream(r)
예제 #10
0
async def make_pipe() -> Tuple[PipeSendStream, PipeReceiveStream]:
    """Makes a new pair of pipes."""
    from asyncio.windows_utils import pipe
    (r, w) = pipe()
    return PipeSendStream(w), PipeReceiveStream(r)