# HG changeset patch # User Kim Alvefur # Date 1631454426 -7200 # Node ID 9006ff4838ff90f9166c146e4f5a9b3f7b632f87 # Parent fa130e49f19ca48e807367338fd79a4c6c29233f net.server_epoll: Try to make port number related methods sane Previously it was unclear whether "client port" was the port that the client connected to, or from. I hereby declare that the client port is the source port and the server port is the destination port. Incoming and outgoing connections can be distinguished by looking at the_server reference, which only incoming connections have. diff -r fa130e49f19c -r 9006ff4838ff net/server_epoll.lua --- a/net/server_epoll.lua Sun Sep 12 13:45:13 2021 +0200 +++ b/net/server_epoll.lua Sun Sep 12 15:47:06 2021 +0200 @@ -272,20 +272,24 @@ -- Get a port number, doesn't matter which function interface:port() - return self.sockport or self.peerport; + return self.peerport or self.sockport; end --- Get local port number +-- Client-side port (usually a random high port) function interface:clientport() - return self.sockport; + if self._server then + return self.peerport; + else + return self.sockport; + end end --- Get remote port +-- Get port on the server function interface:serverport() - if self.sockport then + if self._server then return self.sockport; - elseif self._server then - self._server:port(); + else + return self.peerport; end end