From 162f54af0cb963e9bbccd400cf83ee1add232481 Mon Sep 17 00:00:00 2001 From: Alex Haynes Date: Sun, 11 Nov 2018 17:38:11 -0500 Subject: [PATCH] send message done --- muxer/mplex/muxed_connection.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/muxer/mplex/muxed_connection.py b/muxer/mplex/muxed_connection.py index c4f3658..6c77c9b 100644 --- a/muxer/mplex/muxed_connection.py +++ b/muxer/mplex/muxed_connection.py @@ -1,4 +1,5 @@ import asyncio +from .utils import encode_uvarint, decode_uvarint from .muxed_connection_interface import IMuxedConn from transport.stream.Stream import Stream @@ -50,14 +51,25 @@ class MuxedConn(IMuxedConn): """ pass - def send_message(self, header, data): + def send_message(self, flag, data, stream_id): """ sends a message over the connection :param header: header to use :param data: data to send in the message + :param stream_id: stream the message is in :return: True if success """ - pass + # << by 3, then or with flag + header = (stream_id << 3) | flag + header = encode_uvarint(header) + data_length = encode_uvarint(len(data)) + _bytes = header + data_length + data + return self.write_to_stream(_bytes) + + async def write_to_stream(self, _bytes): + to_return = self.raw_conn.writer.write(_bytes) + await self.raw_conn.writer.drain() + return to_return async def handle_incoming(self): data = bytearray()