-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
retrieve the port number used by a listener. #175
Conversation
add `cowboy:get_port/1` function to retrieve the port number used by a listener.
I like this change in principle but i disagree with the implementation. We would rather open the listener socket higher up in the supervisor tree and propagate it down to the acceptors supervisor than open it down in the acceptor supervisor and send information about it back up again with a function that we wouldn't otherwise need. The listener server should also be started with the socket returned from `Transport:listen' over the port number. This way all information that it provides is available - if needed at a later point. |
the question is how to open up higher. The reason I did it in the listener was because you already do that for some other information you are retrieving. Also what do you mean by "The listener server should also be started with the socket returned from `Transport:listen' over the port number". Do you plan to change that soon? How could I help. |
@benoitc With "The listener server should also be started with the socket returned from @essen your two cents? |
So, once the acceptor pool has been factored out in to ranch, this should go into ranch imo. Should be easy enough to rewrite the patch for ranch with the changes we discussed. @benoitc are we putting this on you're table or mine? whichever you prefer. |
I think the changes to the transport are somewhat redundant given that my sockname patch was merged, which gives access to the IP/Port pair. A specific function for getting a port doesn't seem necessary IMO. |
I was traveling a lot these days, is ranch supposed to be used in cowboy as a dependency. If yes, sure this change should be done in ranch. For the get_port or not, this is a more a convenience than anything, ie returning the port. But I don't see why ranch or cowboy couldn't offer this convenience to the user. |
@benoitc I don't see why not either. The functions exported from the cowboy module aren't expected to map 1:1 with functions in the transport modules. We can reuse the sockname functions to implement a |
You're confusing things. @Vagabond was talking about the cowboy_tcp|ssl_transport get_port function, NOT the code to retrieve the listener's port. Cowboy current already has facilities to retrieve the accepted socket port. So that part of this PR became redundant. |
I'm not confusing things and was addressing this specific case.
|
Just to be sure we're talking about the same thing, you want: Port = cowboy_tcp_transport:get_port(Socket) Instead of: {ok, {Addr, Port}} = cowboy_tcp_transport:sockname(Socket) Is that right? |
One part of my patch is about that yes. The other is how to get the socket used by a listener. |
This will be merged into Ranch. Issue here: ninenines/ranch#4 Thanks! |
add
cowboy:get_port/1
function to retrieve the port number used bya listener.