Skip to content
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

added getsockname for determining a socket name (address & port) of the running server #11012

Merged
merged 2 commits into from
Oct 10, 2015

Conversation

wildart
Copy link
Member

@wildart wildart commented Apr 25, 2015

I added getsockname for determining a socket name (address & port) of the running server. When server socket bound to INPORT_ANY port (0), during listen call the socket is automatically bound to a random free port. By calling getsockname, you can get value of the assigned port.

In addition, I fixed a missing IPv6 support for bind and some documentation.

close(sock)
end

@unix_only begin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea why this fails on windows? Implementation issue, or OS limitation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appveyor failed of this test on Windows, I guess they do not have IPv6 available on test machine. I'll turn if back. Problem is how to tell if IPv6 is on or not before executing this test. Or should I remove it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see #9882 and #10335

On Thu, Apr 30, 2015 at 2:17 PM, Art [email protected] wrote:

In test/socket.jl
#11012 (comment):

+begin

  • default_port = UInt16(11011)
  • default_addr = IPv4("127.0.1.1")
  • sock = Base.TCPServer()
  • bind(sock,Base.InetAddr(default_addr,default_port))
  • listen(sock)
  • new_addr, new_port = getsockname(sock)
  • @test default_addr == new_addr
  • @test default_port == new_port
  • close(sock)
    +end

+@unix_only begin

Appveyor failed of this test on Windows, I guess they do not have IPv6
available on test machine. I'll turn if back. Problem is how to tell if
IPv6 is on or not before executing this test. Or should I remove it?


Reply to this email directly or view it on GitHub
https://github.com/JuliaLang/julia/pull/11012/files#r29455402.

@wildart wildart closed this Aug 18, 2015
@wildart wildart deleted the getsockname branch August 18, 2015 18:28
@wildart wildart restored the getsockname branch August 18, 2015 18:30
@wildart
Copy link
Member Author

wildart commented Aug 18, 2015

Closed by mistake.

@wildart wildart reopened this Aug 18, 2015
@amitmurthy
Copy link
Contributor

@wildart , thanks for the PR. Please rebase against current master. While rebasing you will need to delete

julia/src/jl_uv.c

Lines 693 to 704 in 9c82059

DLLEXPORT int jl_tcp_getsockname_v4(uv_tcp_t *handle, uint32_t * ip, uint16_t * port)
{
struct sockaddr_in name;
int len = sizeof(name);
if (uv_tcp_getsockname(handle, (struct sockaddr *)&name, &len)) {
return -1;
}
*ip = ntohl(name.sin_addr.s_addr);
*port = ntohs(name.sin_port);
return 0;
}
and change the call in managers.jl accordingly.

@wildart wildart added the io Involving the I/O subsystem: libuv, read, write, etc. label Aug 19, 2015
@malmaud
Copy link
Contributor

malmaud commented Sep 5, 2015

Since this won't make it into Julia .4, maybe we could carve out the essential part of this PR and move it to JuliaWeb now.

@wildart
Copy link
Member Author

wildart commented Sep 5, 2015

@malmaud You still need uv_tcp_getsockname call. Do you mean to address libuv directly? PR could be added in following updates.

@ViralBShah ViralBShah added this to the 0.5 milestone Sep 5, 2015
@malmaud
Copy link
Contributor

malmaud commented Sep 5, 2015

Ya, there is nothing technically blocking us from directly addressing libuv in a package, is there? It would just be temporary until the functionality is moved into base in .5.

@malmaud
Copy link
Contributor

malmaud commented Sep 23, 2015

@wildart, want to rebase this? Would be cool to get it into .5.

@wildart wildart force-pushed the getsockname branch 2 times, most recently from b65dbf2 to a40ebc5 Compare September 24, 2015 02:41
@wildart
Copy link
Member Author

wildart commented Sep 24, 2015

Rebased and fixed errors, it's ready to merge.

@tkelman
Copy link
Contributor

tkelman commented Sep 24, 2015

Doc changes here need to be reflected in helpdb

added `getsockname` for determining a socket name (address & port) of the running server
fixed corresponding docimentation
added `uv_tcp_getpeername` to `getsockname` for getting the address and the port of the peer connected to the TCP server socket
fixed generalizing `bind`, Union() => Union{}
fixed AF_INET6 for OSX
added docs
@wildart
Copy link
Member Author

wildart commented Sep 24, 2015

Done.

@@ -893,11 +893,12 @@ System

Get the local machine's host name.

.. function:: getipaddr() -> AbstractString
.. function:: getipaddr()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be getipaddr() -> IPAddr?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Crap, it's so good to have duplicate documentations.

@wildart
Copy link
Member Author

wildart commented Oct 7, 2015

Ready.

(Ptr{Void}, Ref{Cushort}, Ptr{Void}, Ref{Cuint}),
sock.handle, rport, raddress, rfamily)
end
uv_error("cannot obtain socket name", r);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, nevermind.

malmaud added a commit that referenced this pull request Oct 10, 2015
added `getsockname` for determining a socket name (address & port) of the running server
@malmaud malmaud merged commit c16d174 into JuliaLang:master Oct 10, 2015
@malmaud
Copy link
Contributor

malmaud commented Oct 10, 2015

Great, glad to finally have this functionality.

@wildart wildart deleted the getsockname branch October 15, 2015 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
io Involving the I/O subsystem: libuv, read, write, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants