net.server_epoll: Try to make port number related methods sane
authorKim Alvefur <zash@zash.se>
Sun, 12 Sep 2021 15:47:06 +0200
changeset 11797 9006ff4838ff
parent 11796 fa130e49f19c
child 11798 5d925f340ae6
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.
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