You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by as...@apache.org on 2008/07/30 08:29:16 UTC
svn commit: r680920 - in /incubator/qpid/trunk/qpid/cpp/src: Makefile.am
qpid/Exception.cpp qpid/Exception.h qpid/Url.cpp qpid/sys/StrError.h
qpid/sys/posix/StrError.cpp qpid/sys/posix/check.h tests/SocketProxy.h
Author: astitcher
Date: Tue Jul 29 23:29:16 2008
New Revision: 680920
URL: http://svn.apache.org/viewvc?rev=680920&view=rev
Log:
Related to QPID-1198: Moved posix platform specific "strerror" code to
platform specific directory
Added:
incubator/qpid/trunk/qpid/cpp/src/qpid/sys/StrError.h
incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/StrError.cpp
- copied, changed from r680919, incubator/qpid/trunk/qpid/cpp/src/qpid/Exception.cpp
Modified:
incubator/qpid/trunk/qpid/cpp/src/Makefile.am
incubator/qpid/trunk/qpid/cpp/src/qpid/Exception.cpp
incubator/qpid/trunk/qpid/cpp/src/qpid/Exception.h
incubator/qpid/trunk/qpid/cpp/src/qpid/Url.cpp
incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/check.h
incubator/qpid/trunk/qpid/cpp/src/tests/SocketProxy.h
Modified: incubator/qpid/trunk/qpid/cpp/src/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/Makefile.am?rev=680920&r1=680919&r2=680920&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/Makefile.am (original)
+++ incubator/qpid/trunk/qpid/cpp/src/Makefile.am Tue Jul 29 23:29:16 2008
@@ -78,7 +78,8 @@
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 @@
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 \
Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/Exception.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/Exception.cpp?rev=680920&r1=680919&r2=680920&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/Exception.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/Exception.cpp Tue Jul 29 23:29:16 2008
@@ -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);
}
Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/Exception.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/Exception.h?rev=680920&r1=680919&r2=680920&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/Exception.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/Exception.h Tue Jul 29 23:29:16 2008
@@ -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 @@
/** 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 {
Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/Url.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/Url.cpp?rev=680920&r1=680919&r2=680920&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/Url.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/Url.cpp Tue Jul 29 23:29:16 2008
@@ -47,7 +47,7 @@
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));
}
Added: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/StrError.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/StrError.h?rev=680920&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/StrError.h (added)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/StrError.h Tue Jul 29 23:29:16 2008
@@ -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
Copied: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/StrError.cpp (from r680919, incubator/qpid/trunk/qpid/cpp/src/qpid/Exception.cpp)
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/StrError.cpp?p2=incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/StrError.cpp&p1=incubator/qpid/trunk/qpid/cpp/src/qpid/Exception.cpp&r1=680919&r2=680920&rev=680920&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/Exception.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/StrError.cpp Tue Jul 29 23:29:16 2008
@@ -19,43 +19,26 @@
*
*/
-#include "qpid/log/Statement.h"
-#include "Exception.h"
-#include <typeinfo>
-#include <errno.h>
-#include <assert.h>
+#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];
- return std::string(strerror_r(err, buf, sizeof(buf)));
-}
-
-Exception::Exception(const std::string& msg) throw() : message(msg) {
- QPID_LOG(debug, "Exception constructed: " << message);
-}
-
-Exception::~Exception() throw() {}
-
-std::string Exception::getPrefix() const { return ""; }
-
-std::string Exception::getMessage() const { return message; }
-
-const char* Exception::what() const throw() {
- // Construct the what string the first time it is needed.
- if (whatStr.empty()) {
- whatStr = getPrefix();
- if (!whatStr.empty()) whatStr += ": ";
- whatStr += message;
- }
- return whatStr.c_str();
+ //POSIX strerror_r doesn't return the buffer
+ ::strerror_r(err, buf, sizeof(buf));
+ return std::string(buf);
}
-ClosedException::ClosedException(const std::string& msg)
- : Exception(msg) {}
-
-std::string ClosedException::getPrefix() const { return "Closed"; }
-
-} // namespace qpid
+}}
Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/check.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/check.h?rev=680920&r1=680919&r2=680920&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/check.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/check.h Tue Jul 29 23:29:16 2008
@@ -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) \
Modified: incubator/qpid/trunk/qpid/cpp/src/tests/SocketProxy.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/SocketProxy.h?rev=680920&r1=680919&r2=680920&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/SocketProxy.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/SocketProxy.h Tue Jul 29 23:29:16 2008
@@ -78,7 +78,7 @@
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);