Skip to content

Commit 646c6fa

Browse files
committed
支持zerocopy操作,修复keepalive获取hash时候报错
1 parent 2808d83 commit 646c6fa

File tree

4 files changed

+7
-11
lines changed

4 files changed

+7
-11
lines changed

core/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ def get_hash_content(org, content: io.BytesIO):
257257
h = hashlib.md5()
258258
else:
259259
h = hashlib.sha1()
260-
h.update(content)
260+
h.update(content.getbuffer())
261261
return org == h.hexdigest()
262262

263263

core/certificate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
def _load_cert(cert, key):
2020
global server_side_ssl, client_side_ssl, _loaded
2121
if not os.path.exists(cert) or not os.path.exists(key):
22-
logger.terror("cert.error.failed.file", cert=cert, key=key)
22+
logger.terror("cert.error.failed.file", cert=cert, path=key)
2323
return False
2424
try:
2525
server_side_ssl.load_cert_chain(cert, key)

core/cluster.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,14 +402,14 @@ async def __call__(
402402
self.start_task()
403403
return
404404
with tqdm(
405+
desc=locale.t("cluster.tqdm.desc.check_files"),
405406
total=len(files) * len(storages.get_storages()),
406407
unit=locale.t("cluster.tqdm.unit.file"),
407408
unit_scale=True,
408409
) as pbar:
409410
self.pbar = pbar
410411
self.files = files
411412
await dashboard.set_status_by_tqdm("files.checking", pbar)
412-
pbar.set_description(locale.t("cluster.tqdm.desc.check_files"))
413413
try:
414414
miss_storage: list[list[BMCLAPIFile]] = await asyncio.gather(
415415
*[

core/web.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import zlib
2020
from core.exceptions import (
2121
WebSocketError,
22-
ServerWebSocketError,
2322
ServerWebSocketUnknownDataError,
2423
)
2524
from typing import (
@@ -906,13 +905,10 @@ async def __call__(
906905
client.write(content.getbuffer()[start_bytes : end_bytes + 1])
907906
await client.drain()
908907
elif isinstance(content, Path):
909-
async with aiofiles.open(content, "rb") as r:
910-
cur_length: int = 0
911-
await r.seek(start_bytes, os.SEEK_SET)
912-
while data := await r.read(max(0, min(IO_BUFFER, length - cur_length))):
913-
cur_length += len(data)
914-
client.write(data)
915-
await client.drain()
908+
with open(content, "rb") as r:
909+
await asyncio.get_event_loop().sendfile(
910+
client.writer.transport, r, start_bytes, length
911+
)
916912
else:
917913
cur_length: int = 0
918914
bound: bool = False

0 commit comments

Comments
 (0)