Skip to content
This repository was archived by the owner on Nov 23, 2017. It is now read-only.
This repository was archived by the owner on Nov 23, 2017. It is now read-only.

Make a single API for setting up UDP transport+protocol #10

@GoogleCodeExporter

Description

@GoogleCodeExporter
(Quoting Stephen Thorne:)

I don't think it's worth having a different API functions to distinguish 
between client and server datagram protocols.

For instance, this function is will do precisely what is needed and no more:
  def start_serving_datagram(protocol_factory, local_addr=None, remote_addr=None, *, family=0, proto=0, flags=0)
    s = socket.socket(family, proto, flags)
    if local_addr:
      s.bind(local_addr) # FIXME: name resolution
    if remote_addr:
      s.connect(remote_addr) # FIXME: name resolution
    # It is, in fact, not necessary to even call bind() *or* connect(), a port will be automatically bound on the first sendto().
    ...

The current implementation of _SelectorDatagramTransport.sendto(data, 
addr=None) should work fine.

(Guido speaking:)
I'm not sure what the name of this method should be.  Maybe 
create_datagram_thingie()? :-)

Note that this assumes local_addr and remote_addr are (host, port) tuples.  The 
alternative would be to have 4 arguments with somewhat complex rules for which 
could be None.  Also note that we should call yield from self.getaddrinfo(...) 
on each address to avoid blocking for the name lookup in the bind() or 
connect() call.  Finally we need to research whether the connect() (for a UDP 
socket) could ever block on any OS -- if so, we'd need to use yield from 
self.sock_connect(...) instead.

Original issue reported on code.google.com by gvanrossum@gmail.com on 20 Mar 2013 at 1:07

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions