@@ -164,12 +164,29 @@ def read(self, n=-1):
164
164
# PollEventLoop._unregister
165
165
return res # Next iteration raises StopIteration and returns result
166
166
167
- def readinto (self , buf , n = - 1 ): # Experimental and not yet tested TODO
168
- yield IORead (self .polls )
169
- res = self .ios .readinto (buf , n )
170
- assert res , 'zero bytes returned' # Temporary
171
- yield IOReadDone (self .polls )
172
- return res
167
+ def readinto (self , buf , n = 0 ): # Experimental and not yet tested TODO
168
+ if DEBUG and __debug__ :
169
+ log .debug ("StreamReader.readinto() START" )
170
+
171
+ while True :
172
+ yield IORead (self .polls )
173
+ if DEBUG and __debug__ :
174
+ log .debug ("StreamReader.readinto() ... just after IORead" )
175
+ if n :
176
+ res = self .ios .readinto (buf , n ) # Call the device's readinto method
177
+ else :
178
+ res = self .ios .readinto (buf )
179
+ if res is not None :
180
+ break
181
+ # This should not happen for real sockets, but can easily
182
+ # happen for stream wrappers (ssl, websockets, etc.)
183
+ #log.warn("Empty read")
184
+ yield IOReadDone (self .polls ) # uasyncio.core calls remove_reader
185
+ if DEBUG and __debug__ :
186
+ log .debug ("StreamReader.readinto() ... just after IOReadDone" )
187
+ # This de-registers device as a read device with poll via
188
+ # PollEventLoop._unregister
189
+ return res # Next iteration raises StopIteration and returns result
173
190
174
191
def readexactly (self , n ):
175
192
buf = b""
0 commit comments