@@ -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.
@@ -210,6 +212,7 @@ def __init__(self):
210
212
self .__writer = None
211
213
self .__target_names = None
212
214
self .__description = None
215
+ self .__closed = False
213
216
214
217
async def connect_rpc (self , host , port , target_name ):
215
218
"""Connects to the server. This cannot be done in __init__ because
@@ -269,8 +272,12 @@ def __send(self, obj):
269
272
line = pyon .encode (obj ) + "\n "
270
273
self .__writer .write (line .encode ())
271
274
272
- async def __recv (self ):
273
- line = await self .__reader .readline ()
275
+ async def __recv (self ):
276
+ if not self .__closed :
277
+ line = await self .__reader .readline ()
278
+ if self .__closed or not line :
279
+ self .__closed = True
280
+ raise CONNECTION_CLOSED_ERR
274
281
return pyon .decode (line .decode ())
275
282
276
283
async def __do_rpc (self , name , args , kwargs ):
0 commit comments