def _send_cb(self, frame, tolerate_peer_gone=False):
"""
This is the callback used by streams to send data on the connection.
It expects to receive a single frame, and then to serialize that frame
and send it on the connection. It does so obeying the connection-level
flow-control principles of HTTP/2.
"""
# Maintain our outgoing flow-control window.
if frame.type == DataFrame.type:
# If we don't have room in the flow control window, we need to look
# for a Window Update frame.
while self._out_flow_control_window < len(frame.data):
self._recv_cb()
self._out_flow_control_window -= len(frame.data)
data = frame.serialize()
max_frame_size = self._settings[SettingsFrame.SETTINGS_MAX_FRAME_SIZE]
if frame.body_len > max_frame_size:
raise ValueError(
"Frame size %d exceeds maximum frame size setting %d" %
(frame.body_len,
self._settings[SettingsFrame.SETTINGS_MAX_FRAME_SIZE])
)
log.info(
"Sending frame %s on stream %d",
frame.__class__.__name__,
frame.stream_id
)
try:
self._sock.send(data)
except socket.error as e:
if (not tolerate_peer_gone or
e.errno not in (errno.EPIPE, errno.ECONNRESET)):
raise
评论列表
文章目录