diff options
author | Nicolas Noble <nicolasnoble@users.noreply.github.com> | 2015-07-24 14:36:55 -0700 |
---|---|---|
committer | Nicolas Noble <nicolasnoble@users.noreply.github.com> | 2015-07-24 14:36:55 -0700 |
commit | 6e685ff965c4069492e5deabdf6eeeb660b5a5cb (patch) | |
tree | 58d71ad327a4d5d821ace2484b0ed03d68a61e10 /src | |
parent | b3ff7418c62fe4dc03cf5e1265135550b330d1b7 (diff) | |
parent | d298a9528ace23650b9b51cadb85312ec68e0ec2 (diff) |
Merge pull request #2654 from jtattermusch/win_getpeername_fix
Fix getpeername code on windows
Diffstat (limited to 'src')
-rw-r--r-- | src/core/iomgr/tcp_server_windows.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/core/iomgr/tcp_server_windows.c b/src/core/iomgr/tcp_server_windows.c index 8f634fcd7a..cc680507ff 100644 --- a/src/core/iomgr/tcp_server_windows.c +++ b/src/core/iomgr/tcp_server_windows.c @@ -250,6 +250,7 @@ static void on_accept(void *arg, int from_iocp) { DWORD transfered_bytes; DWORD flags; BOOL wsa_success; + int err; /* The general mechanism for shutting down is to queue abortion calls. While this is necessary in the read/write case, it's useless for the accept @@ -281,10 +282,26 @@ static void on_accept(void *arg, int from_iocp) { } } else { if (!sp->shutting_down) { - getpeername(sock, (struct sockaddr*)&peer_name, &peer_name_len); - peer_name_string = grpc_sockaddr_to_uri((struct sockaddr*)&peer_name); + peer_name_string = NULL; + err = setsockopt(sock, SOL_SOCKET, SO_UPDATE_ACCEPT_CONTEXT, + (char *)&sp->socket->socket, + sizeof(sp->socket->socket)); + if (err) { + char *utf8_message = gpr_format_message(WSAGetLastError()); + gpr_log(GPR_ERROR, "setsockopt error: %s", utf8_message); + gpr_free(utf8_message); + } + err = getpeername(sock, (struct sockaddr*)&peer_name, &peer_name_len); + if (!err) { + peer_name_string = grpc_sockaddr_to_uri((struct sockaddr*)&peer_name); + } else { + char *utf8_message = gpr_format_message(WSAGetLastError()); + gpr_log(GPR_ERROR, "getpeername error: %s", utf8_message); + gpr_free(utf8_message); + } gpr_asprintf(&fd_name, "tcp_server:%s", peer_name_string); - ep = grpc_tcp_create(grpc_winsocket_create(sock, fd_name), peer_name_string); + ep = grpc_tcp_create(grpc_winsocket_create(sock, fd_name), + peer_name_string); gpr_free(fd_name); gpr_free(peer_name_string); } |