MCPcopy
hub / github.com/aio-libs/aiohttp / receive

Method receive

aiohttp/web_ws.py:214–262  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

212
213 @asyncio.coroutine
214 def receive(self):
215 if self._reader is None:
216 raise RuntimeError('Call .prepare() first')
217 if self._waiting:
218 raise RuntimeError('Concurrent call to receive() is not allowed')
219
220 self._waiting = True
221 try:
222 while True:
223 if self._closed:
224 self._conn_lost += 1
225 if self._conn_lost >= THRESHOLD_CONNLOST_ACCESS:
226 raise RuntimeError('WebSocket connection is closed.')
227 return closedMessage
228
229 try:
230 msg = yield from self._reader.read()
231 except (asyncio.CancelledError, asyncio.TimeoutError):
232 raise
233 except WebSocketError as exc:
234 self._close_code = exc.code
235 yield from self.close(code=exc.code)
236 return Message(MsgType.error, exc, None)
237 except ClientDisconnectedError:
238 self._closed = True
239 self._close_code = 1006
240 return Message(MsgType.close, None, None)
241 except Exception as exc:
242 self._exception = exc
243 self._closing = True
244 self._close_code = 1006
245 yield from self.close()
246 return Message(MsgType.error, exc, None)
247
248 if msg.tp == MsgType.close:
249 self._closing = True
250 self._close_code = msg.data
251 if not self._closed and self._autoclose:
252 yield from self.close()
253 return msg
254 elif not self._closed:
255 if msg.tp == MsgType.ping and self._autoping:
256 self._writer.pong(msg.data)
257 elif msg.tp == MsgType.pong and self._autoping:
258 continue
259 else:
260 return msg
261 finally:
262 self._waiting = False
263
264 @asyncio.coroutine
265 def receive_msg(self):

Callers 15

receive_msgMethod · 0.95
receive_strMethod · 0.95
receive_bytesMethod · 0.95
__anext__Method · 0.95
handlerMethod · 0.95
handlerFunction · 0.95
handlerFunction · 0.95

Calls 3

closeMethod · 0.95
readMethod · 0.45
pongMethod · 0.45

Tested by 9

handlerMethod · 0.76
handlerFunction · 0.76
handlerFunction · 0.76