Please check the attached source code.
I have to implement an UDP server listening on all interfaces and able to detect what is the local address is used to communicate with remote address. In order to do this I'm using a temporary socket connected to exact remote endpoint to retrieve it's sock name.
When I implement the solution in a pure `asyncio` fashion I faced pair of inconveniences:
ISSUE-1: there is no idiomatic way to sleep forever inside async function. The example of using `create_datagram_endpoint` in documentation uses `sleep(3600)` which is not so useful. I've used `loop.create_future()` but it's perceived to be kind of hack. Also I can't use `loop.run_forever` in this context.
Possible solutions:
- `serve_forever` for a transport object
- `asyncio.setup_and_run_forever(main())` -- function to setup file descriptors for an event loop and run forever.
- `asyncio.sleep(None)` or `asyncio.pause()` -- special argument for sleep or dedicated `pause` function.
ISSUE-2: callbacks for `Protocol` class are assumed to be sync `def`s. Despite the class is designed to be used as a part of `asyncio`. So, in order to invoke async code from sync callback I have to add some boilerplate code. Compare with `start_server`. It's `client_connected_cb` argument maybe a plain callable or co-routine function. So it's proposed to let Protocol callbacks to be `async def`s.
|