@@ -61,6 +61,12 @@ def __init__(self, device: Device, config: Config) -> None:
6161 self .config = config
6262 self .sdu_queue : asyncio .Queue = asyncio .Queue ()
6363
64+ def on_channel_sdu (self , sdu ):
65+ async def handle_sdu ():
66+ await self .sdu_queue .put (sdu )
67+
68+ asyncio .create_task (handle_sdu ())
69+
6470 @utils .rpc
6571 async def WaitConnection (
6672 self , request : WaitConnectionRequest , context : grpc .ServicerContext
@@ -113,6 +119,7 @@ def on_l2cap_channel(
113119 l2cap_channel : Union [ClassicChannel , LeCreditBasedChannel ]
114120 ):
115121 try :
122+ l2cap_channel .sink = self .on_channel_sdu
116123 channel_future .set_result (l2cap_channel )
117124 self .log .debug (
118125 f'Channel future set successfully with channel= { l2cap_channel } '
@@ -155,7 +162,7 @@ def on_close():
155162 closed_event .set ()
156163
157164 l2cap_channel .on ('close' , on_close )
158- await closed_event .wait ()
165+ closed_event .wait ()
159166 return WaitDisconnectionResponse (success = empty_pb2 .Empty ())
160167 except Exception as e :
161168 self .log .exception (f'WaitDisonnection failed: { e } ' )
@@ -173,17 +180,13 @@ async def Receive(
173180 if not isinstance (channel , Channel ):
174181 raise NotImplementedError (f'TODO: { type (channel )} not currently supported.' )
175182
176- def on_channel_sdu (sdu ):
177- async def handle_sdu ():
178- await self .sdu_queue .put (sdu )
179-
180- asyncio .create_task (handle_sdu ())
181-
182183 l2cap_channel = self .get_l2cap_channel (channel )
183184 if l2cap_channel is None :
184185 raise ValueError ('The channel in the request is not valid.' )
185186
186- l2cap_channel .sink = on_channel_sdu
187+ if not l2cap_channel .sink :
188+ l2cap_channel .sink = self .on_channel_sdu
189+
187190 while sdu := await self .sdu_queue .get ():
188191 # Retrieve the next SDU from the queue
189192 self .log .debug (f'Receive: Received { len (sdu )} bytes -> { sdu .decode ()} ' )
@@ -299,6 +302,7 @@ def get_l2cap_channel(
299302 l2cap_channel = self .device .l2cap_channel_manager .find_le_coc_channel (
300303 connection_handle , destination_cid
301304 )
305+ self .log .debug (f'get_l2cap_channel: l2cap_channel={ l2cap_channel } ' )
302306 return l2cap_channel
303307
304308 def channel_to_proto (
0 commit comments