Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
uael committed Nov 6, 2023
1 parent 1ca950f commit 1a07763
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bumble/l2cap.py
Original file line number Diff line number Diff line change
Expand Up @@ -1463,7 +1463,7 @@ class Any:
source_cid: int

def expired(self) -> bool:
...
return True

class Future(asyncio.Future[TPendingConnection]):
def accept(self, pend: TPendingConnection) -> bool:
Expand Down
13 changes: 8 additions & 5 deletions bumble/pandora/l2cap.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ async def listen(self) -> AsyncIterator[l2cap.IncomingConnection.Any]:
self.pending.remove(incoming)
continue
yield incoming
queue = asyncio.Queue()
queue: asyncio.Queue[l2cap.IncomingConnection.Any] = asyncio.Queue()
self.accepts.append(queue)
try:
while incoming := await queue.get():
Expand All @@ -168,6 +168,7 @@ async def Connect(
if connection is None:
raise RuntimeError(f'{connection_handle}: not connection for handle')

channel: Union[l2cap.ClassicChannel, l2cap.LeCreditBasedChannel]
if request.type_variant() == 'basic':
assert request.basic
channel = await connection.create_l2cap_channel(
Expand Down Expand Up @@ -214,11 +215,11 @@ async def WaitConnection(
if isinstance(it, l2cap.IncomingConnection.Basic)
and it.psm == request.basic.psm
):
pend = l2cap.PendingConnection.Basic(
basic = l2cap.PendingConnection.Basic(
fut.set_result,
request.basic.mtu or l2cap.L2CAP_MIN_BR_EDR_MTU,
)
if it.accept(pend):
if it.accept(basic):
break
elif request.type_variant() == 'le_credit_based':
assert request.le_credit_based
Expand All @@ -228,7 +229,7 @@ async def WaitConnection(
if isinstance(it, l2cap.IncomingConnection.LeCreditBased)
and it.psm == request.le_credit_based.spsm
):
pend = l2cap.PendingConnection.LeCreditBased(
le_credit_based = l2cap.PendingConnection.LeCreditBased(
fut.set_result,
request.le_credit_based.mtu
or l2cap.L2CAP_LE_CREDIT_BASED_CONNECTION_DEFAULT_MTU,
Expand All @@ -237,7 +238,7 @@ async def WaitConnection(
request.le_credit_based.initial_credit
or l2cap.L2CAP_LE_CREDIT_BASED_CONNECTION_DEFAULT_INITIAL_CREDITS,
)
if it.accept(pend):
if it.accept(le_credit_based):
break
else:
raise NotImplementedError(f"{request.type_variant()}: unsupported type")
Expand Down Expand Up @@ -268,6 +269,7 @@ async def Receive(
self, request: l2cap_pb2.ReceiveRequest, context: grpc.ServicerContext
) -> AsyncGenerator[l2cap_pb2.ReceiveResponse, None]:
# TODO: fixed channel `Receive`
assert request.channel
channel = self.channels[ChannelIndex.from_token(request.channel)]
while packet := await channel.receive():
yield l2cap_pb2.ReceiveResponse(data=packet)
Expand All @@ -277,6 +279,7 @@ async def Send(
self, request: l2cap_pb2.SendRequest, context: grpc.ServicerContext
) -> l2cap_pb2.SendResponse:
# TODO: fixed channel `Send`
assert request.channel
channel = self.channels[ChannelIndex.from_token(request.channel)]
channel.send(request.data)
return l2cap_pb2.SendResponse(success=empty_pb2.Empty())

0 comments on commit 1a07763

Please sign in to comment.