예제 #1
0
    def doWrite(self):
        numWrites = 0
        while 1:
            if len(self.dataBuffer) - self.offset < self.SEND_LIMIT:
                # If there is currently less than SEND_LIMIT bytes left to send
                # in the string, extend it with the array data.
                self.dataBuffer = (buffer(self.dataBuffer, self.offset) +
                                   "".join(self._tempDataBuffer))
                self.offset = 0
                self._tempDataBuffer = []
                self._tempDataLen = 0

            evt = _iocp.Event(self._cbWrite, self)

            # Send as much data as you can.
            if self.offset:
                evt.buff = buff = buffer(self.dataBuffer, self.offset)
            else:
                evt.buff = buff = self.dataBuffer
            rc, bytes = self.writeToHandle(buff, evt)
            if (rc == ERROR_IO_PENDING
                    or (not rc and numWrites >= self.maxWrites)):
                break
            else:
                evt.ignore = True
                if not self._handleWrite(rc, bytes, evt):
                    break
            numWrites += 1
예제 #2
0
    def doConnect(self):
        if not hasattr(self, "connector"):
            # this happens if we connector.stopConnecting in
            # factory.startedConnecting
            return
        assert _iocp.have_connectex
        self.reactor.addActiveHandle(self)
        evt = _iocp.Event(self.cbConnect, self)

        rc = _iocp.connect(self.socket.fileno(), self.realAddress, evt)
        if rc == ERROR_IO_PENDING:
            return
        else:
            evt.ignore = True
            self.cbConnect(rc, 0, 0, evt)
예제 #3
0
    def doRead(self):
        numReads = 0
        while 1:
            evt = _iocp.Event(self._cbRead, self)

            evt.buff = buff = self._readBuffers
            rc, bytes = self.readFromHandle(buff, evt)

            if (rc == ERROR_IO_PENDING
                    or (not rc and numReads >= self.maxReads)):
                self._readScheduledInOS = True
                break
            else:
                evt.ignore = True
                if not self._handleRead(rc, bytes, evt):
                    break
            numReads += 1
예제 #4
0
    def doRead(self):
        read = 0
        while self.reading:
            evt = _iocp.Event(self.cbRead, self)

            evt.buff = buff = self._readBuffers[0]
            evt.addr_buff = addr_buff = self.addressBuffer
            evt.addr_len_buff = addr_len_buff = self.addressLengthBuffer
            rc, bytes = _iocp.recvfrom(self.getFileHandle(), buff, addr_buff,
                                       addr_len_buff, evt)

            if (rc == ERROR_IO_PENDING
                    or (not rc and read >= self.maxThroughput)):
                break
            else:
                evt.ignore = True
                self.handleRead(rc, bytes, evt)
                read += bytes
예제 #5
0
    def doAccept(self):
        numAccepts = 0
        while 1:
            evt = _iocp.Event(self.cbAccept, self)

            # see AcceptEx documentation
            evt.buff = buff = _iocp.AllocateReadBuffer(2 * (self.addrLen + 16))

            evt.newskt = newskt = self.reactor.createSocket(
                self.addressFamily, self.socketType)
            rc = _iocp.accept(self.socket.fileno(), newskt.fileno(), buff, evt)

            if (rc == ERROR_IO_PENDING
                    or (not rc and numAccepts >= self.maxAccepts)):
                break
            else:
                evt.ignore = True
                if not self.handleAccept(rc, evt):
                    break
            numAccepts += 1