You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by je...@apache.org on 2016/07/24 17:11:31 UTC
[1/2] thrift git commit: THRIFT-2156: fix errno handling in server
socket Client: C++ Patch: Jim King
Repository: thrift
Updated Branches:
refs/heads/master 47f9b9d7c -> bcad91771
THRIFT-2156: fix errno handling in server socket
Client: C++
Patch: Jim King <ji...@simplivity.com>
This closes #1033
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/e5176241
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/e5176241
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/e5176241
Branch: refs/heads/master
Commit: e5176241c325837967a07d6d20e0e9a789fbd107
Parents: 47f9b9d
Author: Jim King <ji...@simplivity.com>
Authored: Mon Jun 20 01:08:58 2016 -0400
Committer: Jens Geyer <je...@apache.org>
Committed: Sun Jul 24 19:10:01 2016 +0200
----------------------------------------------------------------------
lib/cpp/src/thrift/transport/TServerSocket.cpp | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/thrift/blob/e5176241/lib/cpp/src/thrift/transport/TServerSocket.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/transport/TServerSocket.cpp b/lib/cpp/src/thrift/transport/TServerSocket.cpp
index dad0882..b3d8898 100644
--- a/lib/cpp/src/thrift/transport/TServerSocket.cpp
+++ b/lib/cpp/src/thrift/transport/TServerSocket.cpp
@@ -284,7 +284,7 @@ void TServerSocket::listen() {
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
- sprintf(port, "%d", port_);
+ snprintf(port, sizeof("65535"), "%d", port_);
// If address is not specified use wildcard address (NULL)
TGetAddrInfoWrapper info(address_.empty() ? NULL : &address_[0], port, &hints);
@@ -445,6 +445,7 @@ void TServerSocket::listen() {
// we may want to try to bind more than once, since THRIFT_NO_SOCKET_CACHING doesn't
// always seem to work. The client can configure the retry variables.
int retries = 0;
+ int errno_copy = 0;
if (!path_.empty()) {
@@ -453,7 +454,7 @@ void TServerSocket::listen() {
// Unix Domain Socket
size_t len = path_.size() + 1;
if (len > sizeof(((sockaddr_un*)NULL)->sun_path)) {
- int errno_copy = THRIFT_GET_SOCKET_ERROR;
+ errno_copy = THRIFT_GET_SOCKET_ERROR;
GlobalOutput.perror("TSocket::listen() Unix Domain socket path too long", errno_copy);
throw TTransportException(TTransportException::NOT_OPEN,
"Unix Domain socket path too long",
@@ -481,6 +482,7 @@ void TServerSocket::listen() {
if (0 == ::bind(serverSocket_, (struct sockaddr*)&address, structlen)) {
break;
}
+ errno_copy = THRIFT_GET_SOCKET_ERROR;
// use short circuit evaluation here to only sleep if we need to
} while ((retries++ < retryLimit_) && (THRIFT_SLEEP_SEC(retryDelay_) == 0));
#else
@@ -493,6 +495,7 @@ void TServerSocket::listen() {
if (0 == ::bind(serverSocket_, res->ai_addr, static_cast<int>(res->ai_addrlen))) {
break;
}
+ errno_copy = THRIFT_GET_SOCKET_ERROR;
// use short circuit evaluation here to only sleep if we need to
} while ((retries++ < retryLimit_) && (THRIFT_SLEEP_SEC(retryDelay_) == 0));
@@ -502,7 +505,7 @@ void TServerSocket::listen() {
socklen_t len = sizeof(sa);
std::memset(&sa, 0, len);
if (::getsockname(serverSocket_, reinterpret_cast<struct sockaddr*>(&sa), &len) < 0) {
- int errno_copy = errno;
+ errno_copy = THRIFT_GET_SOCKET_ERROR;
GlobalOutput.perror("TServerSocket::getPort() getsockname() ", errno_copy);
} else {
if (sa.ss_family == AF_INET6) {
@@ -520,15 +523,15 @@ void TServerSocket::listen() {
if (retries > retryLimit_) {
char errbuf[1024];
if (!path_.empty()) {
- sprintf(errbuf, "TServerSocket::listen() PATH %s", path_.c_str());
+ snprintf(errbuf, 1024, "TServerSocket::listen() PATH %s", path_.c_str());
} else {
- sprintf(errbuf, "TServerSocket::listen() BIND %d", port_);
+ snprintf(errbuf, 1024, "TServerSocket::listen() BIND %d", port_);
}
GlobalOutput(errbuf);
close();
throw TTransportException(TTransportException::NOT_OPEN,
"Could not bind",
- THRIFT_GET_SOCKET_ERROR);
+ errno_copy);
}
if (listenCallback_)
@@ -536,7 +539,7 @@ void TServerSocket::listen() {
// Call listen
if (-1 == ::listen(serverSocket_, acceptBacklog_)) {
- int errno_copy = THRIFT_GET_SOCKET_ERROR;
+ errno_copy = THRIFT_GET_SOCKET_ERROR;
GlobalOutput.perror("TServerSocket::listen() listen() ", errno_copy);
close();
throw TTransportException(TTransportException::NOT_OPEN, "Could not listen", errno_copy);
[2/2] thrift git commit: THRIFT-2156: fix errno handling in server
socket Client: C++ Patch: Jens Geyer
Posted by je...@apache.org.
THRIFT-2156: fix errno handling in server socket
Client: C++
Patch: Jens Geyer
This closes #1055
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/bcad9177
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/bcad9177
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/bcad9177
Branch: refs/heads/master
Commit: bcad91771b7f0bff28a1cac1981d7ef2b9bcef3c
Parents: e517624
Author: Jens Geyer <je...@apache.org>
Authored: Sun Jul 24 12:11:25 2016 +0200
Committer: Jens Geyer <je...@apache.org>
Committed: Sun Jul 24 19:10:55 2016 +0200
----------------------------------------------------------------------
lib/cpp/src/thrift/transport/TServerSocket.cpp | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/thrift/blob/bcad9177/lib/cpp/src/thrift/transport/TServerSocket.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/transport/TServerSocket.cpp b/lib/cpp/src/thrift/transport/TServerSocket.cpp
index b3d8898..c233e69 100644
--- a/lib/cpp/src/thrift/transport/TServerSocket.cpp
+++ b/lib/cpp/src/thrift/transport/TServerSocket.cpp
@@ -276,15 +276,16 @@ void TServerSocket::listen() {
throw TTransportException(TTransportException::BAD_ARGS, "Specified port is invalid");
}
- struct addrinfo hints;
const struct addrinfo *res;
int error;
char port[sizeof("65535")];
+ snprintf(port, sizeof(port), "%d", port_);
+
+ struct addrinfo hints;
std::memset(&hints, 0, sizeof(hints));
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
- snprintf(port, sizeof("65535"), "%d", port_);
// If address is not specified use wildcard address (NULL)
TGetAddrInfoWrapper info(address_.empty() ? NULL : &address_[0], port, &hints);
@@ -523,9 +524,9 @@ void TServerSocket::listen() {
if (retries > retryLimit_) {
char errbuf[1024];
if (!path_.empty()) {
- snprintf(errbuf, 1024, "TServerSocket::listen() PATH %s", path_.c_str());
+ snprintf(errbuf, sizeof(errbuf), "TServerSocket::listen() PATH %s", path_.c_str());
} else {
- snprintf(errbuf, 1024, "TServerSocket::listen() BIND %d", port_);
+ snprintf(errbuf, sizeof(errbuf), "TServerSocket::listen() BIND %d", port_);
}
GlobalOutput(errbuf);
close();