Comparison

net/server_epoll.lua @ 11793:9006ff4838ff

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.
author Kim Alvefur <zash@zash.se>
date Sun, 12 Sep 2021 15:47:06 +0200
parent 11761:dbf378dcf27b
child 11804:22825cb5dcd8
comparison
equal deleted inserted replaced
11792:fa130e49f19c 11793:9006ff4838ff
270 return self.peername or self.sockname; 270 return self.peername or self.sockname;
271 end 271 end
272 272
273 -- Get a port number, doesn't matter which 273 -- Get a port number, doesn't matter which
274 function interface:port() 274 function interface:port()
275 return self.sockport or self.peerport; 275 return self.peerport or self.sockport;
276 end 276 end
277 277
278 -- Get local port number 278 -- Client-side port (usually a random high port)
279 function interface:clientport() 279 function interface:clientport()
280 return self.sockport; 280 if self._server then
281 end 281 return self.peerport;
282 282 else
283 -- Get remote port 283 return self.sockport;
284 end
285 end
286
287 -- Get port on the server
284 function interface:serverport() 288 function interface:serverport()
285 if self.sockport then 289 if self._server then
286 return self.sockport; 290 return self.sockport;
287 elseif self._server then 291 else
288 self._server:port(); 292 return self.peerport;
289 end 293 end
290 end 294 end
291 295
292 -- Return underlying socket 296 -- Return underlying socket
293 function interface:socket() 297 function interface:socket()