mirror of https://gitlab.com/litecord/litecord.git
parent
c85f0806c7
commit
ddd2469066
|
|
@ -283,39 +283,19 @@ class GatewayWebsocket:
|
||||||
# compress and flush (for the rest of compressed data + ZLIB_SUFFIX)
|
# compress and flush (for the rest of compressed data + ZLIB_SUFFIX)
|
||||||
data1 = self.ws_properties.zctx.compress(encoded)
|
data1 = self.ws_properties.zctx.compress(encoded)
|
||||||
data2 = self.ws_properties.zctx.flush(zlib.Z_FULL_FLUSH)
|
data2 = self.ws_properties.zctx.flush(zlib.Z_FULL_FLUSH)
|
||||||
|
data = data1 + data2
|
||||||
|
|
||||||
log.debug(
|
log.debug(
|
||||||
"zlib-stream: length {} -> compressed ({} + {})",
|
"zlib-stream: length {} -> compressed ({})",
|
||||||
len(encoded),
|
len(encoded),
|
||||||
len(data1),
|
len(data),
|
||||||
len(data2),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if not data1:
|
# since we always chunk the entire compressed message, we shouldn't
|
||||||
# if data1 is nothing, that might cause problems
|
# worry about sending big frames to the clients
|
||||||
# to clients, since they'll receive an empty message
|
|
||||||
data1 = bytes([data2[0]])
|
|
||||||
data2 = data2[1:]
|
|
||||||
|
|
||||||
log.debug(
|
|
||||||
"zlib-stream: len(data1) == 0, remaking as ({} + {})",
|
|
||||||
len(data1),
|
|
||||||
len(data2),
|
|
||||||
)
|
|
||||||
|
|
||||||
# NOTE: the old approach was ws.send(data1 + data2).
|
|
||||||
# I changed this to a chunked send of data1 and data2
|
|
||||||
# because that can bring some problems to the network
|
|
||||||
# since we can be potentially sending a really big packet
|
|
||||||
# as a single message.
|
|
||||||
|
|
||||||
# clients should handle chunked sends (via detection
|
|
||||||
# of the ZLIB_SUFFIX suffix appended to data2), so
|
|
||||||
# this shouldn't cause problems.
|
|
||||||
|
|
||||||
# TODO: the chunks are 1024 bytes, 1KB, is this good enough?
|
# TODO: the chunks are 1024 bytes, 1KB, is this good enough?
|
||||||
await self._chunked_send(data1, 1024)
|
await self._chunked_send(data, 1024)
|
||||||
await self._chunked_send(data2, 1024)
|
|
||||||
|
|
||||||
async def _zstd_stream_send(self, encoded):
|
async def _zstd_stream_send(self, encoded):
|
||||||
compressor = self.ws_properties.zsctx.stream_writer(
|
compressor = self.ws_properties.zsctx.stream_writer(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue