@@ -153,15 +153,14 @@ def __send(self, obj):
153
153
self .__socket .sendall (line .encode ())
154
154
155
155
def __recv (self ):
156
- if self .__closed :
157
- raise CONNECTION_CLOSED_ERR
158
- buf = self .__socket .recv (4096 ).decode ()
159
- while "\n " not in buf :
160
- more = self .__socket .recv (4096 )
161
- if not more :
162
- break
163
- buf += more .decode ()
164
- if not buf :
156
+ if not self .__closed :
157
+ buf = self .__socket .recv (4096 ).decode ()
158
+ while "\n " not in buf :
159
+ more = self .__socket .recv (4096 )
160
+ if not more :
161
+ break
162
+ buf += more .decode ()
163
+ if self .__closed or not buf :
165
164
self .__closed = True
166
165
raise CONNECTION_CLOSED_ERR
167
166
return pyon .decode (buf )
@@ -198,7 +197,10 @@ class AsyncioClient:
198
197
"""This class is similar to :class:`sipyco.pc_rpc.Client`, but
199
198
uses ``asyncio`` instead of blocking calls.
200
199
201
- All RPC methods are coroutines.
200
+ All RPC methods are coroutines. As with :class:`sipyco.pc_rpc.Client`,
201
+ methods will raise ConnectionAbortedError if the server closes the
202
+ connection. The user should call :meth:`~sipyco.pc_rpc.AsyncioClient.close_rpc`
203
+ and then discard this object.
202
204
203
205
Concurrent access from different asyncio tasks is supported; all calls
204
206
use a single lock.
@@ -269,8 +271,12 @@ def __send(self, obj):
269
271
line = pyon .encode (obj ) + "\n "
270
272
self .__writer .write (line .encode ())
271
273
272
- async def __recv (self ):
273
- line = await self .__reader .readline ()
274
+ async def __recv (self ):
275
+ if not self .__closed :
276
+ line = await self .__reader .readline ()
277
+ if self .__closed or not line :
278
+ self .__closed = True
279
+ raise CONNECTION_CLOSED_ERR
274
280
return pyon .decode (line .decode ())
275
281
276
282
async def __do_rpc (self , name , args , kwargs ):
0 commit comments