[issue43619] convenience of using create_datagram_endpoint (and friends)

2021-03-24 Thread Roman Valov


New submission from Roman Valov :

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.

--
components: asyncio
files: async.py
messages: 389488
nosy: Roman.Valov, asvetlov, yselivanov
priority: normal
severity: normal
status: open
title: convenience of using create_datagram_endpoint (and friends)
type: enhancement
versions: Python 3.8
Added file: https://bugs.python.org/file49912/async.py

___
Python tracker 
<https://bugs.python.org/issue43619>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18095] unable to invoke socket.connect with AF_UNSPEC

2013-05-29 Thread Roman Valov

New submission from Roman Valov:

There is a way to disconnect UDP socket
that was previously connected to specific
remote endpoint in C:

  struct sockaddr_in sin;
  memset((char *)sin, 0, sizeof(sin));
  sin.sin_family = AF_UNSPEC;
  connect(fd, (struct sockaddr *)sin, sizeof(sin));

However in this is not available in python, since connect
accepts only (host, port) as a parameter for UDP socket.

It's possible to drop port connection with port=0,
however I can't find a way to drop host connection.

--
components: IO
messages: 190308
nosy: Roman.Valov
priority: normal
severity: normal
status: open
title: unable to invoke socket.connect with AF_UNSPEC
type: behavior
versions: Python 3.3

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18095
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com