Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions app/c_connection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from app.utility.base_object import BaseObject


class Connection(BaseObject):

def __init__(self, reader, writer):
super().__init__()
self.reader = reader
self.writer = writer

async def recv(self, num_bytes):
return await self.reader.read(num_bytes)
Copy link

Copilot AI Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The recv method doesn't handle the case where fewer bytes than requested are returned or when EOF is reached. Consider adding error handling or documentation about these edge cases.

Suggested change
return await self.reader.read(num_bytes)
"""
Read exactly num_bytes bytes from the stream unless EOF is reached.
Returns fewer than num_bytes bytes only if EOF is encountered before enough bytes are read.
"""
data = b''
while len(data) < num_bytes:
chunk = await self.reader.read(num_bytes - len(data))
if not chunk:
# EOF reached
break
data += chunk
return data

Copilot uses AI. Check for mistakes.

async def send(self, data):
self.writer.write(data)
await self.writer.drain()
Copy link

Copilot AI Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The send method doesn't return any value or indicate success/failure. Consider returning the number of bytes written or a success indicator to provide feedback to callers about the operation result.

Suggested change
await self.writer.drain()
await self.writer.drain()
return len(data)

Copilot uses AI. Check for mistakes.
3 changes: 2 additions & 1 deletion app/c_session.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from app.utility.base_object import BaseObject
from plugins.manx.app.c_connection import Connection


class Session(BaseObject):
Expand All @@ -7,7 +8,7 @@ class Session(BaseObject):
def unique(self):
return self.hash('%s' % self.paw)

def __init__(self, id, paw, connection):
def __init__(self, id, paw, connection: Connection):
super().__init__()
self.id = id
self.paw = paw
Expand Down