当前位置: 首页>>代码示例>>Python>>正文


Python win32file.GetOverlappedResult方法代码示例

本文整理汇总了Python中win32file.GetOverlappedResult方法的典型用法代码示例。如果您正苦于以下问题:Python win32file.GetOverlappedResult方法的具体用法?Python win32file.GetOverlappedResult怎么用?Python win32file.GetOverlappedResult使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在win32file的用法示例。


在下文中一共展示了win32file.GetOverlappedResult方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: serialReadEvent

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GetOverlappedResult [as 别名]
def serialReadEvent(self):
        #get that character we set up
        n = win32file.GetOverlappedResult(self._serial.hComPort, self._overlappedRead, 0)
        if n:
            first = str(self.read_buf[:n])
            #now we should get everything that is already in the buffer
            flags, comstat = win32file.ClearCommError(self._serial.hComPort)
            if comstat.cbInQue:
                win32event.ResetEvent(self._overlappedRead.hEvent)
                rc, buf = win32file.ReadFile(self._serial.hComPort,
                                             win32file.AllocateReadBuffer(comstat.cbInQue),
                                             self._overlappedRead)
                n = win32file.GetOverlappedResult(self._serial.hComPort, self._overlappedRead, 1)
                #handle all the received data:
                self.protocol.dataReceived(first + str(buf[:n]))
            else:
                #handle all the received data:
                self.protocol.dataReceived(first)

        #set up next one
        win32event.ResetEvent(self._overlappedRead.hEvent)
        rc, self.read_buf = win32file.ReadFile(self._serial.hComPort,
                                               win32file.AllocateReadBuffer(1),
                                               self._overlappedRead) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:26,代码来源:_win32serialport.py

示例2: serialReadEvent

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GetOverlappedResult [as 别名]
def serialReadEvent(self):
        #get that character we set up
        n = win32file.GetOverlappedResult(self._serial._port_handle, self._overlappedRead, 0)
        first = to_bytes(self.read_buf[:n])
        #now we should get everything that is already in the buffer
        flags, comstat = self._clearCommError()
        if comstat.cbInQue:
            win32event.ResetEvent(self._overlappedRead.hEvent)
            rc, buf = win32file.ReadFile(self._serial._port_handle,
                                         win32file.AllocateReadBuffer(comstat.cbInQue),
                                         self._overlappedRead)
            n = win32file.GetOverlappedResult(self._serial._port_handle, self._overlappedRead, 1)
            #handle all the received data:
            self.protocol.dataReceived(first + to_bytes(buf[:n]))
        else:
            #handle all the received data:
            self.protocol.dataReceived(first)

        #set up next one
        win32event.ResetEvent(self._overlappedRead.hEvent)
        rc, self.read_buf = win32file.ReadFile(self._serial._port_handle,
                                               win32file.AllocateReadBuffer(1),
                                               self._overlappedRead) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:25,代码来源:_win32serialport.py

示例3: testTransactNamedPipeAsync

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GetOverlappedResult [as 别名]
def testTransactNamedPipeAsync(self):
        event = threading.Event()
        overlapped = pywintypes.OVERLAPPED()
        overlapped.hEvent = win32event.CreateEvent(None, 0, 0, None)
        self.startPipeServer(event, 0.5)
        open_mode = win32con.GENERIC_READ | win32con.GENERIC_WRITE

        hpipe = win32file.CreateFile(self.pipename,
                                     open_mode,
                                     0, # no sharing
                                     None, # default security
                                     win32con.OPEN_EXISTING,
                                     win32con.FILE_FLAG_OVERLAPPED,
                                     None)

        # set to message mode.
        win32pipe.SetNamedPipeHandleState(
                        hpipe, win32pipe.PIPE_READMODE_MESSAGE, None, None)

        buffer = win32file.AllocateReadBuffer(1024)
        hr, got = win32pipe.TransactNamedPipe(hpipe, str2bytes("foo\0bar"), buffer, overlapped)
        self.failUnlessEqual(hr, winerror.ERROR_IO_PENDING)
        nbytes = win32file.GetOverlappedResult(hpipe, overlapped, True)
        got = buffer[:nbytes]
        self.failUnlessEqual(got, str2bytes("bar\0foo"))
        event.wait(5)
        self.failUnless(event.isSet(), "Pipe server thread didn't terminate") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:29,代码来源:test_win32pipe.py

示例4: acceptWorker

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GetOverlappedResult [as 别名]
def acceptWorker(self, port, running_event, stopped_event):
        listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        listener.bind(('', port))
        listener.listen(200)

        # create accept socket
        accepter = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        # An overlapped
        overlapped = pywintypes.OVERLAPPED()
        overlapped.hEvent = win32event.CreateEvent(None, 0, 0, None)
        # accept the connection.
        # We used to allow strings etc to be passed here, and they would be
        # modified!  Obviously this is evil :)
        buffer = " " * 1024 # EVIL - SHOULD NOT BE ALLOWED.
        self.assertRaises(TypeError, win32file.AcceptEx, listener, accepter, buffer, overlapped)

        # This is the correct way to allocate the buffer...
        buffer = win32file.AllocateReadBuffer(1024)
        rc = win32file.AcceptEx(listener, accepter, buffer, overlapped)
        self.failUnlessEqual(rc, winerror.ERROR_IO_PENDING)
        # Set the event to say we are all ready
        running_event.set()
        # and wait for the connection.
        rc = win32event.WaitForSingleObject(overlapped.hEvent, 2000)
        if rc == win32event.WAIT_TIMEOUT:
            self.fail("timed out waiting for a connection")
        nbytes = win32file.GetOverlappedResult(listener.fileno(), overlapped, False)
        #fam, loc, rem = win32file.GetAcceptExSockaddrs(accepter, buffer)
        accepter.send(buffer[:nbytes])
        # NOT set in a finally - this means *successfully* stopped!
        stopped_event.set() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:33,代码来源:test_win32file.py

示例5: testAcceptEx

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GetOverlappedResult [as 别名]
def testAcceptEx(self):
        port = 4680
        running = threading.Event()
        stopped = threading.Event()
        t = threading.Thread(target=self.acceptWorker, args=(port, running,stopped))
        t.start()
        running.wait(2)
        if not running.isSet():
            self.fail("AcceptEx Worker thread failed to start")
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.connect(('127.0.0.1', port))
        win32file.WSASend(s, str2bytes("hello"), None)
        overlapped = pywintypes.OVERLAPPED()
        overlapped.hEvent = win32event.CreateEvent(None, 0, 0, None)
        # Like above - WSARecv used to allow strings as the receive buffer!!
        buffer = " " * 10
        self.assertRaises(TypeError, win32file.WSARecv, s, buffer, overlapped)
        # This one should work :)
        buffer = win32file.AllocateReadBuffer(10)
        win32file.WSARecv(s, buffer, overlapped)
        nbytes = win32file.GetOverlappedResult(s.fileno(), overlapped, True)
        got = buffer[:nbytes]
        self.failUnlessEqual(got, str2bytes("hello"))
        # thread should have stopped
        stopped.wait(2)
        if not stopped.isSet():
            self.fail("AcceptEx Worker thread failed to successfully stop") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:29,代码来源:test_win32file.py

示例6: _watcherThreadOverlapped

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GetOverlappedResult [as 别名]
def _watcherThreadOverlapped(self, dn, dh, changes):
        flags = win32con.FILE_NOTIFY_CHANGE_FILE_NAME
        buf = win32file.AllocateReadBuffer(8192)
        overlapped = pywintypes.OVERLAPPED()
        overlapped.hEvent = win32event.CreateEvent(None, 0, 0, None)
        while 1:
            win32file.ReadDirectoryChangesW(dh,
                                            buf,
                                            False, #sub-tree
                                            flags,
                                            overlapped)
            # Wait for our event, or for 5 seconds.
            rc = win32event.WaitForSingleObject(overlapped.hEvent, 5000)
            if rc == win32event.WAIT_OBJECT_0:
                # got some data!  Must use GetOverlappedResult to find out
                # how much is valid!  0 generally means the handle has
                # been closed.  Blocking is OK here, as the event has
                # already been set.
                nbytes = win32file.GetOverlappedResult(dh, overlapped, True)
                if nbytes:
                    bits = win32file.FILE_NOTIFY_INFORMATION(buf, nbytes)
                    changes.extend(bits)
                else:
                    # This is "normal" exit - our 'tearDown' closes the
                    # handle.
                    # print "looks like dir handle was closed!"
                    return
            else:
                print "ERROR: Watcher thread timed-out!"
                return # kill the thread! 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:32,代码来源:test_win32file.py

示例7: connect_thread_runner

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GetOverlappedResult [as 别名]
def connect_thread_runner(self, expect_payload, giveup_event):
        # As Windows 2000 doesn't do ConnectEx, we need to use a non-blocking
        # accept, as our test connection may never come.  May as well use
        # AcceptEx for this...
        listener = socket.socket()
        self.addr = ('localhost', random.randint(10000,64000))
        listener.bind(self.addr)
        listener.listen(1)

        # create accept socket
        accepter = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        # An overlapped
        overlapped = pywintypes.OVERLAPPED()
        overlapped.hEvent = win32event.CreateEvent(None, 0, 0, None)
        # accept the connection.
        if expect_payload:
            buf_size = 1024
        else:
            # when we don't expect data we must be careful to only pass the
            # exact number of bytes for the endpoint data...
            buf_size = win32file.CalculateSocketEndPointSize(listener)

        buffer = win32file.AllocateReadBuffer(buf_size)
        win32file.AcceptEx(listener, accepter, buffer, overlapped)
        # wait for the connection or our test to fail.
        events = giveup_event, overlapped.hEvent
        rc = win32event.WaitForMultipleObjects(events, False, 2000)
        if rc == win32event.WAIT_TIMEOUT:
            self.fail("timed out waiting for a connection")
        if rc == win32event.WAIT_OBJECT_0:
            # Our main thread running the test failed and will never connect.
            return
        # must be a connection.
        nbytes = win32file.GetOverlappedResult(listener.fileno(), overlapped, False)
        if expect_payload:
            self.request = buffer[:nbytes]
        accepter.send(str2bytes('some expected response')) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:39,代码来源:test_win32file.py

示例8: write

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GetOverlappedResult [as 别名]
def write(self, s):
        win32file.WriteFile(self._hfile, s, self._write_ovrlpd)
        win32file.GetOverlappedResult(self._hfile, self._write_ovrlpd, True) 
开发者ID:avocado-framework,项目名称:avocado-vt,代码行数:5,代码来源:windows_support.py

示例9: is_modified

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GetOverlappedResult [as 别名]
def is_modified(self, buffer):
        print "path", self.path
        result = win32file.ReadDirectoryChangesW(
             self.handle,
             buffer,
             True,
                win32con.FILE_NOTIFY_CHANGE_FILE_NAME 
              | win32con.FILE_NOTIFY_CHANGE_DIR_NAME
              | win32con.FILE_NOTIFY_CHANGE_ATTRIBUTES
              | win32con.FILE_NOTIFY_CHANGE_SIZE
              | win32con.FILE_NOTIFY_CHANGE_LAST_WRITE
              | win32con.FILE_NOTIFY_CHANGE_SECURITY,
             self.overlapped,
            )
        print "result  1", result
        result = win32event.WaitForMultipleObjects([self.overlapped.hEvent], True, 0)
        print "result  2", result
        if result != win32event.WAIT_TIMEOUT:
#            result = win32file.GetOverlappedResult(self.handle, self.overlapped, False)
            return True
        else:
            return False


#===========================================================================
# Directory monitor class. 
开发者ID:t4ngo,项目名称:dragonfly,代码行数:28,代码来源:dirmon.py

示例10: Write

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GetOverlappedResult [as 别名]
def Write(self, data, timeout):
        if self.handle:
            try:
                self.lockObject.acquire()
                if eg.debugLevel:
                    print "writing " + str(len(data)) + " bytes to " + self.getName()
                if not self._overlappedWrite:
                    self._overlappedWrite = win32file.OVERLAPPED()
                err, n = win32file.WriteFile(self.handle, data, self._overlappedWrite)
                if err:  #will be ERROR_IO_PENDING:
                    # Wait for the write to complete.
                    n = win32file.GetOverlappedResult(self.handle, self._overlappedWrite, 1)
                    if n != len(data):
                        raise Exception("could not write full data")
                elif n != len(data):
                    raise Exception("could not write full data")
                if timeout:  #waits for response from device
                    win32event.ResetEvent(self._overlappedRead.hEvent)
                    res = win32event.WaitForSingleObject(self._overlappedRead.hEvent, timeout)
                    if res == win32event.WAIT_TIMEOUT:
                        raise Exception("no response from device within timeout")
            finally:
                self.lockObject.release()
        else:
            raise Exception("invalid handle")
            return 
开发者ID:EventGhost,项目名称:EventGhost,代码行数:28,代码来源:HID.py

示例11: read

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GetOverlappedResult [as 别名]
def read(self, n):
        while True:  # emulate blocking IO
            if self._n >= n:
                frags = []
                frags_length = 0
                if self.verbose:
                    txt = "get %s, | bufs = %s " % (n, self._n)
                    txt += "[%s]" % ','.join(map(lambda x: str(len(x)),
                                                 self._bufs))
                    print(txt)
                while frags_length < n:
                    frags.append(self._bufs.pop(0))
                    frags_length += len(frags[-1])
                self._n -= n
                whole = ''.join(frags)
                ret = whole[:n]
                rest = whole[n:]
                if len(rest) > 0:
                    self._bufs.append(rest)
                if self.verbose:
                    txt = "return %s(%s), | bufs = %s " % (len(ret), n,
                                                           self._n)
                    txt += "[%s]" % ','.join(map(lambda x: str(len(x)),
                                                 self._bufs))
                    print(txt)
                return ret
            try:
                # 4096 is the largest result viosdev will return right now.
                err, b = win32file.ReadFile(self._hfile, 4096,
                                            self._read_ovrlpd)
                nr = win32file.GetOverlappedResult(self._hfile,
                                                   self._read_ovrlpd,
                                                   True)
                if nr > 0:
                    self._bufs.append(b[:nr])
                    self._n += nr
                if self.verbose:
                    txt = "read %s, err %s | bufs = %s " % (nr, err, self._n)
                    txt += "[%s]" % ','.join(map(lambda x: str(len(x)),
                                                 self._bufs))
                    print(txt)
            except Exception:
                pass
        # Never Reached
        raise Exception("Error in WinBufferedReadFile - should never be reached") 
开发者ID:avocado-framework,项目名称:avocado-vt,代码行数:47,代码来源:windows_support.py

示例12: ReceiveThread

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GetOverlappedResult [as 别名]
def ReceiveThread(self):
        from win32event import (
            ResetEvent,
            MsgWaitForMultipleObjects,
            QS_ALLINPUT,
            WAIT_OBJECT_0,
            WAIT_TIMEOUT,
        )
        from win32file import ReadFile, AllocateReadBuffer, GetOverlappedResult
        from win32api import GetLastError

        continueLoop = True
        overlapped = self.serial._overlappedRead
        hComPort = self.serial.hComPort
        hEvent = overlapped.hEvent
        stopEvent = self.stopEvent
        n = 1
        waitingOnRead = False
        buf = AllocateReadBuffer(n)
        while continueLoop:
            if not waitingOnRead:
                ResetEvent(hEvent)
                hr, _ = ReadFile(hComPort, buf, overlapped)
                if hr == 997:
                    waitingOnRead = True
                elif hr == 0:
                    pass
                    #n = GetOverlappedResult(hComPort, overlapped, 1)
                    #self.HandleChar(str(buf))
                else:
                    self.PrintError("error")
                    raise

            rc = MsgWaitForMultipleObjects(
                (hEvent, stopEvent),
                0,
                1000,
                QS_ALLINPUT
            )
            if rc == WAIT_OBJECT_0:
                n = GetOverlappedResult(hComPort, overlapped, 1)
                if n:
                    self.HandleChar(str(buf))
                #else:
                #    print "WAIT_OBJECT_0", n, str(buf[:n])
                waitingOnRead = False
            elif rc == WAIT_OBJECT_0+1:
                continueLoop = False
            elif rc == WAIT_TIMEOUT:
                pass
            else:
                self.PrintError("unknown message") 
开发者ID:EventGhost,项目名称:EventGhost,代码行数:54,代码来源:__init__.py


注:本文中的win32file.GetOverlappedResult方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。