[ https://issues.apache.org/jira/browse/THRIFT-1944?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13841473#comment-13841473 ]
Joseph Urciuoli commented on THRIFT-1944: ----------------------------------------- Sorry, fixing formatting from previous post (no edit?) {code:title=TServerSocket.cpp snippet|borderStyle=solid} // retrieve bind info if (port_ == 0 && retries <= retryLimit_) { struct sockaddr_storage sa; socklen_t len = sizeof(sa); std::memset(&sa, 0, len); if (getsockname(serverSocket_, (sockaddr*)&sa, &len) < 0) { #ifdef _WIN32 int errno_copy = WSAGetLastError(); #else int errno_copy = errno; #endif GlobalOutput.perror("TServerSocket::getPort() getsockname() ", errno_copy); } else { if (sa.ss_family == AF_INET6) { const struct sockaddr_in6* sin = reinterpret_cast<const struct sockaddr_in6 *>(&sa); port_ = ntohs(sin->sin6_port); } else { const struct sockaddr_in* sin = reinterpret_cast<const struct sockaddr_in *>(&sa); port_ = ntohs(sin->sin_port); } } } {code} > Binding to zero port > -------------------- > > Key: THRIFT-1944 > URL: https://issues.apache.org/jira/browse/THRIFT-1944 > Project: Thrift > Issue Type: Improvement > Components: C++ - Library > Affects Versions: 0.9 > Environment: All platforms > Reporter: Akshat Aranya > Assignee: Ben Craig > Labels: bind > Fix For: 1.0 > > Attachments: patch-THRIFT-1944-java.patch, > patch-THRIFT-1944-updated.patch, patch-THRIFT-1944.patch > > Original Estimate: 1h > Remaining Estimate: 1h > > This patch builds upon a previously submitted patch that was not accepted > (THRIFT-966). The purpose of this patch is to allow TServerSocket to bind to > port zero, that is, have the server socket be assigned a port by the OS. > This patch provides a way to query the port after the socket has been bound > and determine the OS assigned port -- This message was sent by Atlassian JIRA (v6.1#6144)