0776 async def create_listen_server(cls, addr, port, callback, proto):
1777 def peer_protocol():
2778 """Returns a function that does the protocol handling for a new
3779 connection. To allow different connections to have different
4780 behaviors, the protocol function is first put in the cls.protos
5781 dict. When the connection is made, the function removes the
6782 protocol function from that dict, and returns it so the event loop
7783 can start executing it."""
8784 response = cls.protos.get((addr, port))
9785 # remove protocol function from dict only when reconnection doesn't need to happen/already happened
10786 if not proto.reconnect:
11787 cls.protos[(addr, port)] = None
12788 return response
13789
14790 if (addr, port) not in cls.listeners:
15791 # When creating a listener on a given (addr, port) we only need to
16792 # do it once. If we want different behaviors for different
17793 # connections, we can accomplish this by providing different
18794 # `proto` functions
19795
20796 listener = await cls.network_event_loop.create_server(peer_protocol, addr, port)
21797 # When port=0, the OS assigns an available ephemeral port. Retrieve
22798 # the actual port so callers know where the server is listening.
23799 actual_port = listener.sockets[0].getsockname()[1]
24800 logger.debug("Listening server on %s:%d should be started" % (addr, actual_port))
25801 cls.listeners[(addr, actual_port)] = listener
26802 port = actual_port
27803
28804 cls.protos[(addr, port)] = proto
29805 callback(addr, port)
Is it not the case that inside peer_protocol() and on line 790 port will be 0 which is unintended? That is, those locations expect the actual port?