securedWebsocketCore.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:aws-iot-python 作者: vjammar 项目源码 文件源码
def read(self, numberOfBytesToBeBuffered):
        if not self._bufferingInProgress:  # If last read is completed...
            self._remainedLength = numberOfBytesToBeBuffered
            self._bufferingInProgress = True  # Now we start buffering a new length of bytes

        while self._remainedLength > 0:  # Read in a loop, always try to read in the remained length
            # If the data is temporarily not available, socket.error will be raised and catched by paho
            dataChunk = self._sslSocket.read(self._remainedLength)
            self._internalBuffer.extend(dataChunk)  # Buffer the data
            self._remainedLength -= len(dataChunk)  # Update the remained length

        # The requested length of bytes is buffered, recover the context and return it
        # Otherwise error should be raised
        ret = self._internalBuffer
        self._reset()
        return ret

# This is the internal class that sends requested data out chunk by chunk according
# to the availablity of the socket write operation. If the requested bytes of data
# (after encoding) needs to be sent out in separate socket write operations (most
# probably be interrupted by the error socket.error (errno = ssl.SSL_ERROR_WANT_WRITE).)
# , the write pointer is stored to ensure that the continued bytes will be sent next
# time this function gets called.
# *Error handling:
# For retry errors (ssl.SSL_ERROR_WANT_READ, ssl.SSL_ERROR_WANT_WRITE, EAGAIN),
# leave them to the paho _packet_read for further handling (ignored and try
# again when data is available.
# For other errors, leave them to the paho _packet_read for error reporting.
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号