We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see ourdocumentation.
There was an error while loading.Please reload this page.
1 parent184d278 commitd68fb57Copy full SHA for d68fb57
CMakeLists.txt
@@ -157,6 +157,7 @@ endif(DOXYGEN_FOUND)
157
if(CPP-NETLIB_BUILD_SINGLE_LIB)
158
include_directories(
159
${CMAKE_CURRENT_SOURCE_DIR}/config/src
160
+${CMAKE_CURRENT_SOURCE_DIR}/error/src
161
${CMAKE_CURRENT_SOURCE_DIR}/concurrency/src
162
${CMAKE_CURRENT_SOURCE_DIR}/http/src
163
${CMAKE_CURRENT_SOURCE_DIR}/logging/src
@@ -169,6 +170,7 @@ endif()
169
170
add_subdirectory(uri)
171
#add_subdirectory(message)
172
add_subdirectory(logging)
173
+add_subdirectory(error)
174
#add_subdirectory(concurrency)
175
add_subdirectory(http)
176
#add_subdirectory(mime)
@@ -182,7 +184,7 @@ if(CPP-NETLIB_BUILD_SINGLE_LIB)
182
184
${CPP-NETLIB_MESSAGE_SRCS}
183
185
${CPP-NETLIB_MESSAGE_DIRECTIVES_SRCS}
186
${CPP-NETLIB_MESSAGE_WRAPPERS_SRCS}
- ${CPP-NETLIB_LoOGGING_SRCS}
187
+ ${CPP-NETLIB_LOGGING_SRCS}
188
${CPP-NETLIB_HTTP_CLIENT_SRCS}
189
${CPP-NETLIB_HTTP_CLIENT_CONNECTIONS_SRCS}
190
${CPP-NETLIB_HTTP_SERVER_SRCS}
concurrency/test/thread_pool_test.cpp
@@ -8,7 +8,6 @@
8
9
#include<gtest/gtest.h>
10
#include<network/concurrency/thread_pool.hpp>
11
-// #include <boost/bind.hpp>
12
#include<functional>
13
14
using network::concurrency::thread_pool;
@@ -42,5 +41,5 @@ TEST(concurrency_test, post_work) {
42
41
ASSERT_NO_THROW(pool.post(std::bind(&foo::bar, &instance,2)));
43
// require that pool is destroyed here, RAII baby
44
}
45
-ASSERT_EQ(instance.val(),3);
+ASSERT_EQ(3,instance.val());
46
error/CMakeLists.txt
@@ -0,0 +1,14 @@
1
+# Copyright (c) Glyn Matthews 2013.
2
+# Distributed under the Boost Software License, Version 1.0.
3
+# (See accompanying file LICENSE_1_0.txt or copy at
4
+# http://www.boost.org/LICENSE_1_0.txt)
5
+
6
+add_subdirectory(src)
7
+if(CPP-NETLIB_BUILD_TESTS)
+ enable_testing()
+ add_subdirectory(test)
+endif(CPP-NETLIB_BUILD_TESTS)
+# propagate sources to parent directory for one-lib-build
+set(CPP-NETLIB_ERROR_SRCS ${CPP-NETLIB_ERROR_SRCS} PARENT_SCOPE)
error/src/CMakeLists.txt
@@ -0,0 +1,20 @@
+include_directories(${CPP-NETLIB_SOURCE_DIR}/error/src)
+set(CPP-NETLIB_ERROR_SRCS
+ error.cpp)
+if(NOT CPP-NETLIB_BUILD_SINGLE_LIB)
+ add_library(network_error ${CPP-NETLIB_ERROR_SRCS})
+endif()
15
+# prepend current directory to make paths absolute
16
+prependToElements("${CMAKE_CURRENT_SOURCE_DIR}/"
17
+ CPP-NETLIB_ERROR_SRCS )
18
19
20
error/src/error.cpp
@@ -0,0 +1,42 @@
+// Copyright (C) 2013 by Glyn Matthews
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+#include<network/error.hpp>
+#include<cstring>
+namespacenetwork {
+classnetwork_category_impl :publicstd::error_category {
+public:
+network_category_impl() =default;
+virtual~network_category_impl()noexcept;
+virtualconstchar *name()constnoexcept;
21
+virtual std::stringmessage(int ev)const;
22
23
+ };
24
25
+network_category_impl::~network_category_impl()noexcept {
26
27
+ }
28
29
+constchar *network_category_impl::name()constnoexcept {
30
+staticconstchar name[] ="network_error";
31
+return name;
32
33
34
+ std::stringnetwork_category_impl::message(int ev)const {
35
+returnstd::strerror(ev);
36
37
38
+const std::error_category &network_category() {
39
+static network_category_impl category;
40
+return category;
+}// namespace network
error/src/network/error.hpp
@@ -0,0 +1,24 @@
+#ifndef NETWORK_ERROR_INC
+#defineNETWORK_ERROR_INC
+/**
+ * \file
+ * \brief Contains a set of error classes and exceptions for
+ * network connections.
+*/
+#include<system_error>
+ * \brief Gets the error category for network errors.
+const std::error_category &network_category();
+#endif// NETWORK_ERROR_INC
error/test/CMakeLists.txt
@@ -0,0 +1,23 @@
+include_directories(${CPP-NETLIB_SOURCE_DIR}/error/src
+${GTEST_INCLUDE_DIRS}
+ ${CPP-NETLIB_SOURCE_DIR}
+)
+if (CPP-NETLIB_BUILD_TESTS)
+ add_executable(cpp-netlib-error_test error_test.cpp)
+ target_link_libraries(cpp-netlib-error_test
+${link_cppnetlib_lib}
+ network_error
+${Boost_LIBRARIES}
+${GTEST_BOTH_LIBRARIES}
+${CMAKE_THREAD_LIBS_INIT})
+ set_target_properties(cpp-netlib-error_test PROPERTIES
+RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/tests)
+ add_test(cpp-netlib-error_test
+ ${CPP-NETLIB_BINARY_DIR}/tests/cpp-netlib-error_test)
error/test/error_test.cpp
@@ -0,0 +1,13 @@
+// Copyright (c) Glyn Matthews 2013.
+#include<gtest/gtest.h>
+#include<cerrno>
+TEST(error_test, system_error) {
+ std::system_errorerror(EPIPE,network::network_category());
+ASSERT_EQ(EPIPE, error.code().value());
+}