Commit e4c83268 authored by David Wilson's avatar David Wilson

core: synchronize Stream._output_buf by deferring send()

Previously _output_buf was racy. This may or may not be cheaper than
simply using a lock, but it requires much less code, so I prefer it for
now.
parent ead67de8
......@@ -624,16 +624,19 @@ class Stream(BasicStream):
if not self._output_buf:
broker.stop_transmit(self)
def send(self, msg):
"""Send `data` to `handle`, and tell the broker we have output. May
be called from any thread."""
def _send(self, msg):
IOLOG.debug('%r._send(%r)', self, msg)
pkt = struct.pack('>hhLLL', msg.dst_id, msg.src_id,
msg.handle, msg.reply_to or 0, len(msg.data)
) + msg.data
self._output_buf += pkt # TODO: It's actually possible for this to race
self._output_buf += pkt
self._router.broker.start_transmit(self)
def send(self, msg):
"""Send `data` to `handle`, and tell the broker we have output. May
be called from any thread."""
self._router.broker.defer(self._send, msg)
def on_disconnect(self, broker):
super(Stream, self).on_disconnect(broker)
self._router.on_disconnect(self, broker)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment