Github user becrux commented on a diff in the pull request:

    https://github.com/apache/thrift/pull/628#discussion_r45579754
  
    --- Diff: lib/cpp/src/thrift/server/TNonblockingServer.cpp ---
    @@ -1105,10 +1113,17 @@ void TNonblockingServer::listenSocket(THRIFT_SOCKET 
s) {
       serverSocket_ = s;
     
       if (!port_) {
    -    sockaddr_in addr;
    -    socklen_t size = sizeof(addr);
    -    if (!getsockname(serverSocket_, reinterpret_cast<sockaddr*>(&addr), 
&size)) {
    -      listenPort_ = ntohs(addr.sin_port);
    +    #ifdef _WIN32
    +      struct sockaddr_storage addr;
    +      struct sockaddr_in *pAddr = (sockaddr_in *) &addr;
    +      socklen_t size = sizeof(addr);
    +    #else
    +      struct sockaddr_in addr;
    +      struct sockaddr_in *pAddr = &addr;
    +      socklen_t size = sizeof(addr);
    +    #endif
    --- End diff --
    
    getsockname fails cause the buffer is not big enough. If you compare the 
size of "sockaddr_in" and "sockaddr_storage", you'll find out that 
"sockaddr_storage" has many more fields (due to IPv6 and many other stuff).
    
    Some hints here:
    
    
http://stackoverflow.com/questions/14624427/wsaefault-error-when-use-getsockname-function


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to