summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorAndrew Stitcher <astitcher@apache.org>2008-07-30 06:29:16 +0000
committerAndrew Stitcher <astitcher@apache.org>2008-07-30 06:29:16 +0000
commitf1f80e7b3b1e17e663113382219d992680461063 (patch)
tree793644f4345437ed0c60ace0c5b7fdf07504e661 /cpp/src
parentab27cb344e9d2e1ea18c1c89cda65a02a7513e4b (diff)
downloadqpid-python-f1f80e7b3b1e17e663113382219d992680461063.tar.gz
Related to QPID-1198: Moved posix platform specific "strerror" code to
platform specific directory git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@680920 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Makefile.am4
-rw-r--r--cpp/src/qpid/Exception.cpp6
-rw-r--r--cpp/src/qpid/Exception.h8
-rw-r--r--cpp/src/qpid/Url.cpp2
-rw-r--r--cpp/src/qpid/sys/StrError.h35
-rw-r--r--cpp/src/qpid/sys/posix/StrError.cpp44
-rw-r--r--cpp/src/qpid/sys/posix/check.h3
-rw-r--r--cpp/src/tests/SocketProxy.h2
8 files changed, 89 insertions, 15 deletions
diff --git a/cpp/src/Makefile.am b/cpp/src/Makefile.am
index c612d6f3ef..592ccf8a76 100644
--- a/cpp/src/Makefile.am
+++ b/cpp/src/Makefile.am
@@ -78,7 +78,8 @@ posix_plat_src = \
qpid/sys/posix/Thread.cpp \
qpid/sys/posix/Shlib.cpp \
qpid/sys/posix/Mutex.cpp \
- qpid/sys/posix/Fork.cpp
+ qpid/sys/posix/Fork.cpp \
+ qpid/sys/posix/StrError.cpp
posix_plat_hdr = \
qpid/sys/posix/check.h \
@@ -559,6 +560,7 @@ nobase_include_HEADERS = \
qpid/sys/ShutdownHandler.h \
qpid/sys/Socket.h \
qpid/sys/StateMonitor.h \
+ qpid/sys/StrError.h \
qpid/sys/Waitable.h \
qpid/sys/Thread.h \
qpid/sys/Time.h \
diff --git a/cpp/src/qpid/Exception.cpp b/cpp/src/qpid/Exception.cpp
index 28c9d3742b..9e884efec0 100644
--- a/cpp/src/qpid/Exception.cpp
+++ b/cpp/src/qpid/Exception.cpp
@@ -22,17 +22,11 @@
#include "qpid/log/Statement.h"
#include "Exception.h"
#include <typeinfo>
-#include <errno.h>
#include <assert.h>
#include <string.h>
namespace qpid {
-std::string strError(int err) {
- char buf[512];
- return std::string(strerror_r(err, buf, sizeof(buf)));
-}
-
Exception::Exception(const std::string& msg) throw() : message(msg) {
QPID_LOG(debug, "Exception constructed: " << message);
}
diff --git a/cpp/src/qpid/Exception.h b/cpp/src/qpid/Exception.h
index c7ddcec109..9cf564104d 100644
--- a/cpp/src/qpid/Exception.h
+++ b/cpp/src/qpid/Exception.h
@@ -24,6 +24,7 @@
#include "qpid/framing/amqp_types.h"
#include "qpid/framing/constants.h"
+#include "qpid/sys/StrError.h"
#include "qpid/Msg.h"
#include <memory>
@@ -33,9 +34,6 @@
namespace qpid
{
-/** Get the error message for a system number err, e.g. errno. */
-std::string strError(int err);
-
/**
* Base class for Qpid runtime exceptions.
*/
@@ -55,8 +53,8 @@ class Exception : public std::exception
/** Exception that includes an errno message. */
struct ErrnoException : public Exception {
- ErrnoException(const std::string& msg, int err) : Exception(msg+": "+strError(err)) {}
- ErrnoException(const std::string& msg) : Exception(msg+": "+strError(errno)) {}
+ ErrnoException(const std::string& msg, int err) : Exception(msg+": "+qpid::sys::strError(err)) {}
+ ErrnoException(const std::string& msg) : Exception(msg+": "+qpid::sys::strError(errno)) {}
};
struct SessionException : public Exception {
diff --git a/cpp/src/qpid/Url.cpp b/cpp/src/qpid/Url.cpp
index 20e3a55f8d..95d6a34136 100644
--- a/cpp/src/qpid/Url.cpp
+++ b/cpp/src/qpid/Url.cpp
@@ -47,7 +47,7 @@ std::istream& operator>>(std::istream&, const TcpAddress&);
Url Url::getHostNameUrl(uint16_t port) {
char name[HOST_NAME_MAX];
if (::gethostname(name, sizeof(name)) != 0)
- throw InvalidUrl(QPID_MSG("Cannot get host name: " << strError(errno)));
+ throw InvalidUrl(QPID_MSG("Cannot get host name: " << qpid::sys::strError(errno)));
return Url(TcpAddress(name, port));
}
diff --git a/cpp/src/qpid/sys/StrError.h b/cpp/src/qpid/sys/StrError.h
new file mode 100644
index 0000000000..3843f2abe1
--- /dev/null
+++ b/cpp/src/qpid/sys/StrError.h
@@ -0,0 +1,35 @@
+#ifndef _sys_StrError_h
+#define _sys_StrError_h
+
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#include <string>
+
+namespace qpid {
+namespace sys {
+
+/** Get the error message for a system number err, e.g. errno. */
+std::string strError(int err);
+
+}} // namespace qpid
+
+#endif // _sys_StrError_h
diff --git a/cpp/src/qpid/sys/posix/StrError.cpp b/cpp/src/qpid/sys/posix/StrError.cpp
new file mode 100644
index 0000000000..deb2fca7eb
--- /dev/null
+++ b/cpp/src/qpid/sys/posix/StrError.cpp
@@ -0,0 +1,44 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#include "qpid/sys/StrError.h"
+
+// Ensure we get the POSIX verion of strerror_r
+#ifndef _XOPEN_SOURCE
+#define _XOPEN_SOURCE 600
+#include <string.h>
+#undef _XOPEN_SOURCE
+#else
+#include <string.h>
+#endif
+
+
+namespace qpid {
+namespace sys {
+
+std::string strError(int err) {
+ char buf[512];
+ //POSIX strerror_r doesn't return the buffer
+ ::strerror_r(err, buf, sizeof(buf));
+ return std::string(buf);
+}
+
+}}
diff --git a/cpp/src/qpid/sys/posix/check.h b/cpp/src/qpid/sys/posix/check.h
index 32fdc48077..f3031b7593 100644
--- a/cpp/src/qpid/sys/posix/check.h
+++ b/cpp/src/qpid/sys/posix/check.h
@@ -23,11 +23,12 @@
*/
#include "qpid/Exception.h"
+
#include <cerrno>
#include <assert.h>
#include <stdio.h>
-#define QPID_POSIX_ERROR(ERRNO) qpid::Exception(QPID_MSG(qpid::strError(ERRNO)))
+#define QPID_POSIX_ERROR(ERRNO) qpid::Exception(QPID_MSG(qpid::sys::strError(ERRNO)))
/** THROW QPID_POSIX_ERROR(errno) if RESULT is less than zero */
#define QPID_POSIX_CHECK(RESULT) \
diff --git a/cpp/src/tests/SocketProxy.h b/cpp/src/tests/SocketProxy.h
index b53387bd57..a1a1351c7d 100644
--- a/cpp/src/tests/SocketProxy.h
+++ b/cpp/src/tests/SocketProxy.h
@@ -78,7 +78,7 @@ class SocketProxy : private qpid::sys::Runnable
private:
static void throwErrno(const std::string& msg) {
- throw qpid::Exception(msg+":"+qpid::strError(errno));
+ throw qpid::Exception(msg+":"+qpid::sys::strError(errno));
}
static void throwIf(bool condition, const std::string& msg) {
if (condition) throw qpid::Exception(msg);