def send(self, sender, host_port, bytes_):
""" Send `bytes_` to `host_port`.
Args:
sender (address): The address of the running node.
host_port (Tuple[(str, int)]): Tuple with the host name and port number.
bytes_ (bytes): The bytes that are going to be sent through the wire.
"""
sleep_timeout = self.throttle_policy.consume(1)
# Don't sleep if timeout is zero, otherwise a context-switch is done
# and the message is delayed, increasing it's latency
if sleep_timeout:
gevent.sleep(sleep_timeout)
if not hasattr(self.server, 'socket'):
raise RuntimeError('trying to send a message on a closed server')
self.server.sendto(bytes_, host_port)
# enable debugging using the DummyNetwork callbacks
DummyTransport.network.track_send(sender, host_port, bytes_)
评论列表
文章目录