You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Jake Farrell (JIRA)" <ji...@apache.org> on 2014/02/21 16:43:20 UTC
[jira] [Updated] (THRIFT-1676) Allow specifying IP/hostname in
TServer::serve
[ https://issues.apache.org/jira/browse/THRIFT-1676?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Jake Farrell updated THRIFT-1676:
---------------------------------
Fix Version/s: (was: 0.9)
1.0
> Allow specifying IP/hostname in TServer::serve
> ----------------------------------------------
>
> Key: THRIFT-1676
> URL: https://issues.apache.org/jira/browse/THRIFT-1676
> Project: Thrift
> Issue Type: Improvement
> Components: C++ - Library
> Affects Versions: 0.8
> Environment: Mac OS X. Thrift 0.8.0.
> Reporter: Diwaker Gupta
> Assignee: Jake Farrell
> Fix For: 1.0
>
> Attachments: 0001-Allow-TNonBlockingServer-to-bind-a-specific-host.patch
>
>
> Thrift doesn't allow users to specify which IP/hostname to use for bind. As a result, a Thrift server usually ends up listening on ALL interfaces on a machine (bind uses INADDR_ANY). This is clearly undesirable in many cases where we may want to restrict connectivity to localhost or to within a particular subnet or targeted towards a specific host or IP.
> Here's a example of what TNonblockingServer does:
> {code}
> // Wildcard address
> error = getaddrinfo(NULL, port, &hints, &res0);
> if (error) {
> throw TException("TNonblockingServer::serve() getaddrinfo " +
> string(gai_strerror(error)));
> }
> // Pick the ipv6 address first since ipv4 addresses can be mapped
> // into ipv6 space.
> for (res = res0; res; res = res->ai_next) {
> if (res->ai_family == AF_INET6 || res->ai_next == NULL)
> break;
> }
> {code}
> As can be seen, the above code fragment provides NULL as the first param to getaddrinfo and always specifies AI_PASSIVE. This results in the behavior I described above.
> A better approach IMO is to provide the following interface instead:
> {code}
> TServer::serve(const char* hostOrIp, int port)
> {code}
> This is consistent with what other modern server frameworks do (node.js, netty etc.)
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)