sys_errlist is deprecated.
Summary:
Avoiding usage of sys_errlist. It is deprecated, prefer strerror or strerror_r instead.
Trac Bug: #
Blame Rev:
Reviewed By: mcslee, karl
Test Plan:
Revert Plan: revertible
Notes:
EImportant:
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665156 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/transport/TServerSocket.cpp b/lib/cpp/src/transport/TServerSocket.cpp
index 0a48029..33367a4 100644
--- a/lib/cpp/src/transport/TServerSocket.cpp
+++ b/lib/cpp/src/transport/TServerSocket.cpp
@@ -18,6 +18,7 @@
namespace facebook { namespace thrift { namespace transport {
+using namespace std;
using namespace boost;
TServerSocket::TServerSocket(int port) :
@@ -238,18 +239,24 @@
if (clientSocket < 0) {
GlobalOutput("TServerSocket::accept()");
- throw TTransportException(TTransportException::UNKNOWN, std::string("ERROR:") + sys_errlist[errno]);
+ char b_error[1024];
+ strerror_r(errno, b_error, sizeof(b_error));
+ throw TTransportException(TTransportException::UNKNOWN, string("ERROR:") + b_error);
}
// Make sure client socket is blocking
int flags = fcntl(clientSocket, F_GETFL, 0);
if (flags == -1) {
GlobalOutput("TServerSocket::select() fcntl GETFL");
- throw TTransportException(TTransportException::UNKNOWN, std::string("ERROR:") + sys_errlist[errno]);
+ char b_error[1024];
+ strerror_r(errno, b_error, sizeof(b_error));
+ throw TTransportException(TTransportException::UNKNOWN, string("ERROR:") + b_error);
}
if (-1 == fcntl(clientSocket, F_SETFL, flags & ~O_NONBLOCK)) {
GlobalOutput("TServerSocket::select() fcntl SETFL");
- throw TTransportException(TTransportException::UNKNOWN, std::string("ERROR:") + sys_errlist[errno]);
+ char b_error[1024];
+ strerror_r(errno, b_error, sizeof(b_error));
+ throw TTransportException(TTransportException::UNKNOWN, string("ERROR:") + b_error);
}
shared_ptr<TSocket> client(new TSocket(clientSocket));
diff --git a/lib/cpp/src/transport/TSocket.cpp b/lib/cpp/src/transport/TSocket.cpp
index 711d05d..bfd3387 100644
--- a/lib/cpp/src/transport/TSocket.cpp
+++ b/lib/cpp/src/transport/TSocket.cpp
@@ -98,7 +98,9 @@
if (r == -1) {
GlobalOutput("TSocket::peek()");
close();
- throw TTransportException(TTransportException::UNKNOWN, std::string("recv() ERROR:") + sys_errlist[errno]);
+ char b_error[1024];
+ strerror_r(errno, b_error, sizeof(b_error));
+ throw TTransportException(TTransportException::UNKNOWN, string("recv() ERROR:") + b_error);
}
return (r > 0);
}
@@ -111,7 +113,9 @@
socket_ = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
if (socket_ == -1) {
GlobalOutput("TSocket::open() socket");
- throw TTransportException(TTransportException::NOT_OPEN, std::string("socket() ERROR:") + sys_errlist[errno]);
+ char b_error[1024];
+ strerror_r(errno, b_error, sizeof(b_error));
+ throw TTransportException(TTransportException::NOT_OPEN, string("socket() ERROR:") + b_error);
}
// Send timeout
@@ -155,9 +159,12 @@
if (errno != EINPROGRESS) {
char buff[1024];
- sprintf(buff, "TSocket::open() connect %s %d", host_.c_str(), port_);
GlobalOutput(buff);
- throw TTransportException(TTransportException::NOT_OPEN, std::string("open() ERROR: ") + sys_errlist[errno]);
+ sprintf(buff, "TSocket::open() connect %s %d", host_.c_str(), port_);
+
+ char b_error[1024];
+ strerror_r(errno, b_error, sizeof(b_error));
+ throw TTransportException(TTransportException::NOT_OPEN, string("open() ERROR: ") + b_error);
}
fd_set fds;
@@ -173,19 +180,27 @@
int ret2 = getsockopt(socket_, SOL_SOCKET, SO_ERROR, (void *)&val, &lon);
if (ret2 == -1) {
GlobalOutput("TSocket::open() getsockopt SO_ERROR");
- throw TTransportException(TTransportException::NOT_OPEN, std::string("open() ERROR: ") + sys_errlist[errno]);
+ char b_error[1024];
+ strerror_r(errno, b_error, sizeof(b_error));
+ throw TTransportException(TTransportException::NOT_OPEN, string("open() ERROR: ") + b_error);
}
if (val == 0) {
goto done;
}
GlobalOutput("TSocket::open() SO_ERROR was set");
- throw TTransportException(TTransportException::NOT_OPEN, std::string("open() ERROR: ") + sys_errlist[errno]);
+ char b_error[1024];
+ strerror_r(errno, b_error, sizeof(b_error));
+ throw TTransportException(TTransportException::NOT_OPEN, string("open() ERROR: ") + b_error);
} else if (ret == 0) {
GlobalOutput("TSocket::open() timeed out");
- throw TTransportException(TTransportException::NOT_OPEN, std::string("open() ERROR: ") + sys_errlist[errno]);
+ char b_error[1024];
+ strerror_r(errno, b_error, sizeof(b_error));
+ throw TTransportException(TTransportException::NOT_OPEN, string("open() ERROR: ") + b_error);
} else {
GlobalOutput("TSocket::open() select error");
- throw TTransportException(TTransportException::NOT_OPEN, std::string("open() ERROR: ") + sys_errlist[errno]);
+ char b_error[1024];
+ strerror_r(errno, b_error, sizeof(b_error));
+ throw TTransportException(TTransportException::NOT_OPEN, string("open() ERROR: ") + b_error);
}
done:
@@ -373,7 +388,9 @@
}
GlobalOutput("TSocket::write() send < 0");
- throw TTransportException(TTransportException::UNKNOWN, std::string("ERROR:") + sys_errlist[errno]);
+ char b_error[1024];
+ strerror_r(errno, b_error, sizeof(b_error));
+ throw TTransportException(TTransportException::UNKNOWN, string("ERROR:") + b_error);
}
// Fail on blocked send