From ed52971d7904f572791136bd42a2cf3d78579d75 Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Sun, 21 May 2017 00:49:57 +0300 Subject: [PATCH] Move all library identifiers to the seastar namespace --- apps/fair_queue_tester/fair_queue_tester.cc | 1 + apps/httpd/main.cc | 1 + apps/iotune/iotune.cc | 4 + apps/memcached/ascii.rl | 2 + apps/memcached/memcache.cc | 5 +- apps/memcached/memcached.hh | 2 + apps/seawreck/seawreck.cc | 2 + core/align.hh | 4 + core/aligned_buffer.hh | 4 + core/app-template.cc | 4 + core/app-template.hh | 4 + core/apply.hh | 4 + core/array_map.hh | 4 +- core/bitops.hh | 4 + core/bitset-iter.hh | 3 + core/byteorder.hh | 4 + core/chunked_fifo.hh | 4 + core/circular_buffer.hh | 4 + core/condition-variable.hh | 4 + core/deleter.hh | 4 + core/distributed.hh | 7 +- core/do_with.hh | 4 + core/dpdk_rte.cc | 4 + core/dpdk_rte.hh | 5 + core/enum.hh | 4 + core/expiring_fifo.hh | 4 + core/fair_queue.hh | 4 + core/file-impl.hh | 3 + core/file.hh | 24 +-- core/fsqual.cc | 4 + core/fsqual.hh | 4 + core/fstream.cc | 4 + core/fstream.hh | 7 +- core/function_traits.hh | 3 + core/future-util.hh | 16 +- core/future.hh | 53 +++--- core/iostream-impl.hh | 4 + core/iostream.hh | 4 + core/lowres_clock.hh | 5 + core/manual_clock.hh | 5 + core/memory.cc | 65 ++++--- core/memory.hh | 11 +- core/metrics.cc | 2 +- core/metrics_api.hh | 6 +- core/posix.cc | 5 + core/posix.hh | 8 +- core/preempt.hh | 4 +- core/prefetch.hh | 4 + core/print.hh | 3 +- core/prometheus.cc | 3 +- core/prometheus.hh | 4 + core/queue.hh | 4 + core/ragel.hh | 4 + core/reactor.cc | 24 ++- core/reactor.hh | 33 ++-- core/report_exception.hh | 5 + core/resource.cc | 12 ++ core/resource.hh | 5 + core/rwlock.hh | 4 + core/scattered_message.hh | 4 + core/scollectd-impl.hh | 4 + core/scollectd.cc | 10 +- core/scollectd.hh | 10 +- core/scollectd_api.hh | 6 +- core/seastar.hh | 8 +- core/semaphore.hh | 4 + core/sharded.hh | 20 +- core/shared_future.hh | 4 + core/shared_ptr.hh | 20 +- core/shared_ptr_debug_helper.hh | 4 + core/slab.hh | 4 + core/sleep.hh | 3 + core/sstring.hh | 12 +- core/stream.hh | 4 + core/systemwide_memory_barrier.cc | 5 + core/systemwide_memory_barrier.hh | 5 + core/task.hh | 4 + core/temporary_buffer.hh | 4 + core/thread.cc | 4 +- core/thread.hh | 4 +- core/timer-set.hh | 3 +- core/timer.hh | 6 +- core/transfer.hh | 4 + core/unaligned.hh | 4 + core/units.hh | 4 + core/vector-data-sink.hh | 4 + core/vla.hh | 4 +- core/weak_ptr.hh | 5 + core/xen/gntalloc.hh | 4 + http/api_docs.cc | 4 + http/api_docs.hh | 4 + http/common.cc | 5 + http/common.hh | 4 + http/exception.hh | 4 + http/file_handler.cc | 4 + http/file_handler.hh | 4 + http/function_handlers.hh | 4 + http/handlers.hh | 4 + http/http_response_parser.rl | 4 + http/httpd.cc | 4 + http/httpd.hh | 6 +- http/json_path.cc | 4 + http/json_path.hh | 5 + http/matcher.cc | 4 + http/matcher.hh | 4 + http/matchrules.hh | 4 + http/mime_types.cc | 4 + http/mime_types.hh | 4 + http/reply.cc | 4 + http/reply.hh | 4 + http/request.hh | 4 + http/request_parser.rl | 4 + http/routes.cc | 4 + http/routes.hh | 4 + http/transformers.cc | 4 + http/transformers.hh | 5 + json/formatter.cc | 4 + json/formatter.hh | 4 + json/json2code.py | 2 + json/json_elements.cc | 4 + json/json_elements.hh | 4 + net/api.hh | 24 ++- net/arp.cc | 4 + net/arp.hh | 4 + net/byteorder.hh | 4 + net/const.hh | 6 + net/dhcp.cc | 4 + net/dhcp.hh | 4 + net/dns.cc | 80 ++++---- net/dns.hh | 8 +- net/dpdk.cc | 4 + net/dpdk.hh | 4 + net/ethernet.cc | 4 +- net/ethernet.hh | 4 + net/inet_address.cc | 5 + net/ip.cc | 4 + net/ip.hh | 18 +- net/ip_checksum.cc | 4 + net/ip_checksum.hh | 4 + net/native-stack-impl.hh | 4 +- net/native-stack.cc | 8 +- net/native-stack.hh | 4 + net/net.cc | 24 ++- net/net.hh | 12 +- net/packet-data-source.hh | 4 + net/packet-util.hh | 5 + net/packet.cc | 4 + net/packet.hh | 4 + net/posix-stack.cc | 4 + net/posix-stack.hh | 6 +- net/proxy.cc | 4 + net/proxy.hh | 5 + net/socket_defs.hh | 12 +- net/stack.cc | 18 +- net/stack.hh | 5 +- net/tcp-stack.hh | 4 + net/tcp.cc | 3 + net/tcp.hh | 18 +- net/tls.cc | 191 ++++++++++---------- net/tls.hh | 28 +-- net/toeplitz.hh | 5 + net/udp.cc | 5 + net/udp.hh | 4 + net/virtio.cc | 4 + net/virtio.hh | 4 + net/xenfront.cc | 4 + net/xenfront.hh | 4 + rpc/lz4_compressor.cc | 4 + rpc/lz4_compressor.hh | 4 + rpc/multi_algo_compressor_factory.hh | 4 + rpc/rpc.cc | 4 + rpc/rpc.hh | 14 +- rpc/rpc_impl.hh | 26 +-- rpc/rpc_types.hh | 11 +- tests/alloc_test.cc | 2 +- tests/allocator_test.cc | 2 + tests/blkdiscard_test.cc | 2 + tests/checked_ptr_test.cc | 2 + tests/chunked_fifo_test.cc | 2 + tests/circular_buffer_test.cc | 2 + tests/connect_test.cc | 1 + tests/defer_test.cc | 2 + tests/directory_test.cc | 2 + tests/distributed_test.cc | 2 + tests/echotest.cc | 1 + tests/execution_stage_test.cc | 2 + tests/fair_queue_test.cc | 1 + tests/fileiotest.cc | 2 + tests/foreign_ptr_test.cc | 2 + tests/fstream_test.cc | 2 + tests/futures_test.cc | 1 + tests/httpd.cc | 1 + tests/ip_test.cc | 1 + tests/l3_test.cc | 1 + tests/linecount.cc | 2 + tests/loopback_socket.hh | 4 + tests/memcached/test_ascii_parser.cc | 1 + tests/mock_file.hh | 4 + tests/output_stream_test.cc | 1 + tests/packet_test.cc | 1 + tests/perf/perf_fstream.cc | 1 + tests/rpc.cc | 2 + tests/shared_ptr_test.cc | 2 + tests/slab_test.cc | 2 + tests/smp_test.cc | 2 + tests/sstring_test.cc | 2 + tests/tcp_sctp_client.cc | 2 +- tests/tcp_test.cc | 1 + tests/test-utils.cc | 6 +- tests/test-utils.hh | 4 + tests/test_runner.cc | 4 + tests/test_runner.hh | 4 + tests/timertest.cc | 1 + tests/udp_client.cc | 1 + tests/udp_server.cc | 1 + tests/udp_zero_copy.cc | 1 + tests/unwind_test.cc | 2 + tests/weak_ptr_test.cc | 2 + util/backtrace.hh | 12 +- util/bool_class.hh | 4 + util/conversions.cc | 3 + util/conversions.hh | 4 + util/defer.hh | 4 + util/function_input_iterator.hh | 4 + util/indirect.hh | 4 + util/is_smart_ptr.hh | 4 + util/print_safe.hh | 4 + util/spinlock.hh | 4 + util/transform_iterator.hh | 4 + 229 files changed, 1160 insertions(+), 384 deletions(-) diff --git a/apps/fair_queue_tester/fair_queue_tester.cc b/apps/fair_queue_tester/fair_queue_tester.cc index 9b75d2d9674..4ddb0705b0f 100644 --- a/apps/fair_queue_tester/fair_queue_tester.cc +++ b/apps/fair_queue_tester/fair_queue_tester.cc @@ -33,6 +33,7 @@ #include #include +using namespace seastar; using namespace std::chrono_literals; static auto random_seed = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); diff --git a/apps/httpd/main.cc b/apps/httpd/main.cc index f112a6ed5c3..8c76cfafd15 100644 --- a/apps/httpd/main.cc +++ b/apps/httpd/main.cc @@ -28,6 +28,7 @@ namespace bpo = boost::program_options; +using namespace seastar; using namespace httpd; class handl : public httpd::handler_base { diff --git a/apps/iotune/iotune.cc b/apps/iotune/iotune.cc index 2c42d1bf5ee..304328ebc2d 100644 --- a/apps/iotune/iotune.cc +++ b/apps/iotune/iotune.cc @@ -44,9 +44,13 @@ #include "core/aligned_buffer.hh" #include "util/defer.hh" +using namespace seastar; using namespace std::chrono_literals; +namespace seastar { bool filesystem_has_good_aio_support(sstring directory, bool verbose); +} + class iotune_manager; class iotune_timeout_exception : public std::exception { diff --git a/apps/memcached/ascii.rl b/apps/memcached/ascii.rl index f6f577c4126..fe5ad0a9b6c 100644 --- a/apps/memcached/ascii.rl +++ b/apps/memcached/ascii.rl @@ -25,6 +25,8 @@ #include #include +using namespace seastar; + %%{ machine memcache_ascii_protocol; diff --git a/apps/memcached/memcache.cc b/apps/memcached/memcache.cc index ef53ff0a38c..9a03677e3cc 100644 --- a/apps/memcached/memcache.cc +++ b/apps/memcached/memcache.cc @@ -48,12 +48,13 @@ #define VERSION "v1.0" #define VERSION_STRING PLATFORM " " VERSION +using namespace seastar; using namespace net; -namespace bi = boost::intrusive; - namespace memcache { +namespace bi = boost::intrusive; + static constexpr double default_slab_growth_factor = 1.25; static constexpr uint64_t default_slab_page_size = 1UL*MB; static constexpr uint64_t default_per_cpu_slab_size = 0UL; // zero means reclaimer is enabled. diff --git a/apps/memcached/memcached.hh b/apps/memcached/memcached.hh index 54fa217fccd..10a355328fd 100644 --- a/apps/memcached/memcached.hh +++ b/apps/memcached/memcached.hh @@ -22,6 +22,8 @@ namespace memcache { +using namespace seastar; + class item; class cache; diff --git a/apps/seawreck/seawreck.cc b/apps/seawreck/seawreck.cc index fc9fbd72e3b..bb0298040f9 100644 --- a/apps/seawreck/seawreck.cc +++ b/apps/seawreck/seawreck.cc @@ -29,6 +29,8 @@ #include "core/future-util.hh" #include +using namespace seastar; + template void http_debug(const char* fmt, Args&&... args) { #if HTTP_DEBUG diff --git a/core/align.hh b/core/align.hh index e53c5dd91e4..52f644667d7 100644 --- a/core/align.hh +++ b/core/align.hh @@ -25,6 +25,8 @@ #include #include +namespace seastar { + template inline constexpr T align_up(T v, T align) { @@ -51,4 +53,6 @@ T* align_down(T* v, size_t align) { return reinterpret_cast(align_down(reinterpret_cast(v), align)); } +} + #endif /* ALIGN_HH_ */ diff --git a/core/aligned_buffer.hh b/core/aligned_buffer.hh index 1d8245a7a9c..ad6e0db02b1 100644 --- a/core/aligned_buffer.hh +++ b/core/aligned_buffer.hh @@ -24,6 +24,9 @@ #include #include "print.hh" +namespace seastar { + + struct free_deleter { void operator()(void* p) { ::free(p); } }; @@ -45,3 +48,4 @@ std::unique_ptr allocate_aligned_buffer(size_t size, s } +} diff --git a/core/app-template.cc b/core/app-template.cc index 69430fe82da..29d73b8b774 100644 --- a/core/app-template.cc +++ b/core/app-template.cc @@ -30,6 +30,8 @@ #include #include +namespace seastar { + namespace bpo = boost::program_options; app_template::app_template(app_template::config cfg) @@ -141,3 +143,5 @@ app_template::run_deprecated(int ac, char ** av, std::function&& func) smp::cleanup(); return exit_code; } + +} diff --git a/core/app-template.hh b/core/app-template.hh index 9e85197d00a..be5b0718833 100644 --- a/core/app-template.hh +++ b/core/app-template.hh @@ -27,6 +27,8 @@ #include #include +namespace seastar { + class app_template { public: struct config { @@ -63,4 +65,6 @@ public: int run(int ac, char ** av, std::function ()>&& func); }; +} + #endif diff --git a/core/apply.hh b/core/apply.hh index c015274fde7..437166ad5bd 100644 --- a/core/apply.hh +++ b/core/apply.hh @@ -25,6 +25,8 @@ #include #include +namespace seastar { + template struct apply_helper; @@ -56,4 +58,6 @@ auto apply(Func&& func, const std::tuple& args) { return helper::apply(std::forward(func), args); } +} + #endif /* APPLY_HH_ */ diff --git a/core/array_map.hh b/core/array_map.hh index 9e0a1f60d18..e9d46319cd8 100644 --- a/core/array_map.hh +++ b/core/array_map.hh @@ -24,6 +24,8 @@ #include +namespace seastar { + // unordered_map implemented as a simple array template @@ -46,6 +48,6 @@ public: } }; - +} #endif /* ARRAY_MAP_HH_ */ diff --git a/core/bitops.hh b/core/bitops.hh index c33768f5602..22458dba6a5 100644 --- a/core/bitops.hh +++ b/core/bitops.hh @@ -24,6 +24,8 @@ #include +namespace seastar { + inline constexpr unsigned count_leading_zeros(unsigned x) { return __builtin_clz(x); @@ -66,4 +68,6 @@ inline constexpr unsigned log2floor(T n) { return std::numeric_limits::digits - count_leading_zeros(n) - 1; } +} + #endif /* BITOPS_HH_ */ diff --git a/core/bitset-iter.hh b/core/bitset-iter.hh index a79a097f512..cec275fbc72 100644 --- a/core/bitset-iter.hh +++ b/core/bitset-iter.hh @@ -17,6 +17,8 @@ #include #include +namespace seastar { + namespace bitsets { static constexpr int ulong_bits = std::numeric_limits::digits; @@ -172,6 +174,7 @@ static inline set_range for_each_set(std::bitset bitset, int offset = 0) return set_range(bitset, offset); } +} } diff --git a/core/byteorder.hh b/core/byteorder.hh index beabdcfe17d..a3ac3f26499 100644 --- a/core/byteorder.hh +++ b/core/byteorder.hh @@ -25,6 +25,8 @@ #include #include "unaligned.hh" +namespace seastar { + inline uint8_t cpu_to_le(uint8_t x) { return x; } inline uint8_t le_to_cpu(uint8_t x) { return x; } inline uint16_t cpu_to_le(uint16_t x) { return htole16(x); } @@ -121,3 +123,5 @@ produce_be(char*& p, T datum) { write_be(p, datum); p += sizeof(T); } + +} diff --git a/core/chunked_fifo.hh b/core/chunked_fifo.hh index a60b796c4b9..c2fcbbd64f7 100644 --- a/core/chunked_fifo.hh +++ b/core/chunked_fifo.hh @@ -21,6 +21,8 @@ #pragma once +namespace seastar { + // An unbounded FIFO queue of objects of type T. // // It provides operations to push items in one end of the queue, and pop them @@ -462,3 +464,5 @@ void chunked_fifo::reserve(size_t n) { ++_nfree_chunks; } } + +} diff --git a/core/circular_buffer.hh b/core/circular_buffer.hh index 838dfe379a8..316792ad110 100644 --- a/core/circular_buffer.hh +++ b/core/circular_buffer.hh @@ -37,6 +37,8 @@ #include #include +namespace seastar { + template > class circular_buffer { struct impl : Alloc { @@ -440,4 +442,6 @@ circular_buffer::erase(iterator first, iterator last) { } } +} + #endif /* CIRCULAR_BUFFER_HH_ */ diff --git a/core/condition-variable.hh b/core/condition-variable.hh index 33eef0e8431..9f948d913dc 100644 --- a/core/condition-variable.hh +++ b/core/condition-variable.hh @@ -24,6 +24,8 @@ #include "core/future-util.hh" #include "core/semaphore.hh" +namespace seastar { + /// \addtogroup fiber-module /// @{ @@ -174,3 +176,5 @@ public: }; /// @} + +} diff --git a/core/deleter.hh b/core/deleter.hh index 7749f624b34..ea3b0ef7e73 100644 --- a/core/deleter.hh +++ b/core/deleter.hh @@ -27,6 +27,8 @@ #include #include +namespace seastar { + /// \addtogroup memory-module /// @{ @@ -272,4 +274,6 @@ make_object_deleter(deleter d, T&& obj) { /// @} +} + #endif /* DELETER_HH_ */ diff --git a/core/distributed.hh b/core/distributed.hh index d95a6eea39f..0c4b62f7928 100644 --- a/core/distributed.hh +++ b/core/distributed.hh @@ -23,5 +23,10 @@ #include "sharded.hh" +namespace seastar { + + template -using distributed = seastar::sharded; +using distributed = sharded; + +} diff --git a/core/do_with.hh b/core/do_with.hh index 630bf8d2a3a..f991be69611 100644 --- a/core/do_with.hh +++ b/core/do_with.hh @@ -26,6 +26,8 @@ #include #include +namespace seastar { + /// \addtogroup future-util /// @{ @@ -112,3 +114,5 @@ do_with(T1&& rv1, T2&& rv2, T3_or_F&& rv3, More&&... more) { } /// @} + +} diff --git a/core/dpdk_rte.cc b/core/dpdk_rte.cc index 46cc08897cd..5e358fcddf1 100644 --- a/core/dpdk_rte.cc +++ b/core/dpdk_rte.cc @@ -24,6 +24,8 @@ #include #include +namespace seastar { + namespace dpdk { bool eal::initialized = false; @@ -111,4 +113,6 @@ size_t eal::mem_size(int num_cpus, bool hugetlbfs_membackend) } // namespace dpdk +} + #endif // HAVE_DPDK diff --git a/core/dpdk_rte.hh b/core/dpdk_rte.hh index 215c1481add..52cec58a19a 100644 --- a/core/dpdk_rte.hh +++ b/core/dpdk_rte.hh @@ -38,6 +38,8 @@ #endif /******************************************************************************/ +namespace seastar { + namespace dpdk { // DPDK Environment Abstraction Layer @@ -57,5 +59,8 @@ public: }; } // namespace dpdk + +} + #endif // HAVE_DPDK #endif // DPDK_RTE_HH_ diff --git a/core/enum.hh b/core/enum.hh index be6c4ff9843..1ea3423224b 100644 --- a/core/enum.hh +++ b/core/enum.hh @@ -31,6 +31,8 @@ #include #include +namespace seastar { + template class enum_hash { static_assert(std::is_enum::value, "must be an enum"); @@ -40,3 +42,5 @@ public: return std::hash()(static_cast(e)); } }; + +} diff --git a/core/expiring_fifo.hh b/core/expiring_fifo.hh index d5b8ceee696..63fe96259be 100644 --- a/core/expiring_fifo.hh +++ b/core/expiring_fifo.hh @@ -29,6 +29,8 @@ #include "future-util.hh" #include "lowres_clock.hh" +namespace seastar { + template struct dummy_expiry { void operator()(T&) noexcept {}; @@ -165,3 +167,5 @@ public: drop_expired_front(); } }; + +} diff --git a/core/fair_queue.hh b/core/fair_queue.hh index 0862868ec6d..be8aa37244a 100644 --- a/core/fair_queue.hh +++ b/core/fair_queue.hh @@ -33,6 +33,8 @@ #include #include +namespace seastar { + /// \addtogroup io-module /// @{ @@ -227,3 +229,5 @@ public: } }; /// @} + +} diff --git a/core/file-impl.hh b/core/file-impl.hh index f9cf465f63c..c35a9f9f887 100644 --- a/core/file-impl.hh +++ b/core/file-impl.hh @@ -25,6 +25,8 @@ #include #include +namespace seastar { + class posix_file_handle_impl : public seastar::file_handle_impl { int _fd; std::atomic* _refcount; @@ -157,3 +159,4 @@ public: virtual future<> allocate(uint64_t position, uint64_t length) override; }; +} diff --git a/core/file.hh b/core/file.hh index 30028fa4c71..d8e6576c0a2 100644 --- a/core/file.hh +++ b/core/file.hh @@ -36,6 +36,8 @@ #include #include +namespace seastar { + /// \addtogroup fileio-module /// @{ @@ -99,8 +101,6 @@ const io_priority_class& default_priority_class(); class file; class file_impl; -namespace seastar { - class file_handle; // A handle that can be transported across shards and used to @@ -112,8 +112,6 @@ public: virtual shared_ptr to_file() && = 0; }; -} - class file_impl { protected: static file_impl* get_file_impl(file& f); @@ -135,7 +133,7 @@ public: virtual future<> allocate(uint64_t position, uint64_t length) = 0; virtual future size(void) = 0; virtual future<> close() = 0; - virtual std::unique_ptr dup(); + virtual std::unique_ptr dup(); virtual subscription list_directory(std::function (directory_entry de)> next) = 0; virtual future> dma_read_bulk(uint64_t offset, size_t range_size, const io_priority_class& pc) = 0; @@ -174,7 +172,7 @@ public: : _file_impl(std::move(impl)) {} /// Constructs a file object from a \ref file_handle obtained from another shard - explicit file(seastar::file_handle&& handle); + explicit file(file_handle&& handle); /// Checks whether the file object was initialized. /// @@ -430,7 +428,7 @@ public: /// /// \note Use on read-only files. /// - seastar::file_handle dup(); + file_handle dup(); template struct read_state; @@ -439,8 +437,6 @@ private: friend class file_impl; }; -namespace seastar { - /// \brief A shard-transportable handle to a file /// /// If you need to access a file (for reads only) across multiple shards, @@ -449,9 +445,9 @@ namespace seastar { /// object on that shard. This is more efficient than calling open_file_dma() /// again. class file_handle { - std::unique_ptr _impl; + std::unique_ptr _impl; private: - explicit file_handle(std::unique_ptr impl) : _impl(std::move(impl)) {} + explicit file_handle(std::unique_ptr impl) : _impl(std::move(impl)) {} public: /// Copies a file handle object file_handle(const file_handle&); @@ -466,11 +462,9 @@ public: /// Converts the file handle object to a \ref file. file to_file() &&; - friend class ::file; + friend class file; }; -} - /// \cond internal template @@ -543,4 +537,6 @@ private: /// @} +} + #endif /* FILE_HH_ */ diff --git a/core/fsqual.cc b/core/fsqual.cc index a7c50bb8b12..96c7ea6d9ff 100644 --- a/core/fsqual.cc +++ b/core/fsqual.cc @@ -31,6 +31,8 @@ #include #include "fsqual.hh" +namespace seastar { + // Runs func(), and also adds the number of context switches // that happened during func() to counter. template @@ -92,3 +94,5 @@ bool filesystem_has_good_aio_support(sstring directory, bool verbose) { } return ok; } + +} diff --git a/core/fsqual.hh b/core/fsqual.hh index c00a93ce2fd..5c6ee028346 100644 --- a/core/fsqual.hh +++ b/core/fsqual.hh @@ -25,6 +25,10 @@ #include "sstring.hh" +namespace seastar { + bool filesystem_has_good_aio_support(sstring directory, bool verbose = false); +} + #endif /* CORE_FSQUAL_HH_ */ diff --git a/core/fstream.cc b/core/fstream.cc index 636f719a746..354cea75948 100644 --- a/core/fstream.cc +++ b/core/fstream.cc @@ -27,6 +27,8 @@ #include #include +namespace seastar { + class file_data_source_impl : public data_source_impl { struct issued_read { uint64_t _pos; @@ -426,3 +428,5 @@ output_stream make_file_output_stream(file f, file_output_stream_options o return output_stream(file_data_sink(std::move(f), options), options.buffer_size, true); } +} + diff --git a/core/fstream.hh b/core/fstream.hh index 79f7d00e3cb..e92622e9244 100644 --- a/core/fstream.hh +++ b/core/fstream.hh @@ -34,6 +34,8 @@ #include "iostream.hh" #include "shared_ptr.hh" +namespace seastar { + class file_input_stream_history { static constexpr uint64_t window_size = 4 * 1024 * 1024; struct window { @@ -51,7 +53,7 @@ class file_input_stream_history { struct file_input_stream_options { size_t buffer_size = 8192; ///< I/O buffer size unsigned read_ahead = 0; ///< Maximum number of extra read-ahead operations - ::io_priority_class io_priority_class = default_priority_class(); + ::seastar::io_priority_class io_priority_class = default_priority_class(); lw_shared_ptr dynamic_adjustments = { }; ///< Input stream history, if null dynamic adjustments are disabled }; @@ -83,7 +85,7 @@ struct file_output_stream_options { unsigned buffer_size = 8192; unsigned preallocation_size = 1024*1024; // 1MB unsigned write_behind = 1; ///< Number of buffers to write in parallel - ::io_priority_class io_priority_class = default_priority_class(); + ::seastar::io_priority_class io_priority_class = default_priority_class(); }; // Create an output_stream for writing starting at the position zero of a @@ -100,3 +102,4 @@ output_stream make_file_output_stream( file file, file_output_stream_options options); +} diff --git a/core/function_traits.hh b/core/function_traits.hh index 1d278a6207f..a3b9b9d31a8 100644 --- a/core/function_traits.hh +++ b/core/function_traits.hh @@ -23,6 +23,8 @@ #include +namespace seastar { + template struct function_traits; @@ -63,3 +65,4 @@ template struct function_traits : public function_traits> {}; +} diff --git a/core/future-util.hh b/core/future-util.hh index bcc93d9fcad..cfe1dbe31f6 100644 --- a/core/future-util.hh +++ b/core/future-util.hh @@ -37,6 +37,8 @@ #include #include "util/tuple_utils.hh" +namespace seastar { + /// \cond internal extern __thread size_t task_quota; /// \endcond @@ -403,7 +405,6 @@ future<> do_for_each(Container& c, AsyncAction&& action) { } /// \cond internal -namespace seastar { namespace internal { template @@ -446,12 +447,9 @@ public: } }; -} } /// \endcond -namespace seastar { - GCC6_CONCEPT( /// \cond internal @@ -480,8 +478,6 @@ concept bool AllAreFutures = impl::is_tuple_of_futures>::val ) -} - /// Wait for many futures to complete, capturing possible errors (variadic version). /// @@ -497,14 +493,13 @@ GCC6_CONCEPT( requires seastar::AllAreFutures ) inline future> when_all(Futs&&... futs) { - namespace si = seastar::internal; + namespace si = internal; using state = si::when_all_state, Futs...>; auto s = make_lw_shared(std::forward(futs)...); return s->wait_all(std::make_index_sequence()); } /// \cond internal -namespace seastar { namespace internal { template @@ -563,7 +558,6 @@ do_when_all(FutureIterator begin, FutureIterator end) { return complete_when_all(std::move(ret), ret.begin()); } -} } /// \endcond @@ -582,7 +576,7 @@ GCC6_CONCEPT( requires requires (FutureIterator i) { { *i++ }; requires is_futur inline future::value_type>> when_all(FutureIterator begin, FutureIterator end) { - namespace si = seastar::internal; + namespace si = internal; using itraits = std::iterator_traits; using result_transform = si::identity_futures_vector; return si::do_when_all(std::move(begin), std::move(end)); @@ -848,8 +842,6 @@ future with_timeout(std::chrono::time_point timeout, futu return result; } -namespace seastar { - namespace internal { template diff --git a/core/future.hh b/core/future.hh index de551fb6257..7e82684ea34 100644 --- a/core/future.hh +++ b/core/future.hh @@ -35,6 +35,8 @@ #include "function_traits.hh" #include "../util/gcc6-concepts.hh" +namespace seastar { + /// \defgroup future-module Futures and Promises /// /// \brief @@ -74,6 +76,9 @@ class promise; template class future; +template +class shared_future; + /// \brief Creates a \ref future in an available, value state. /// /// Creates a \ref future object that is already resolved. This @@ -648,8 +653,6 @@ using futurize_t = typename futurize::type; /// @} -namespace seastar { - GCC6_CONCEPT( template @@ -672,8 +675,6 @@ concept bool ApplyReturnsAnyFuture = requires (Func f, T... args) { ) -} - /// \addtogroup future-module /// @{ @@ -721,7 +722,7 @@ private: template void schedule(Func&& func) { if (state()->available()) { - ::schedule(std::make_unique>(std::move(func), std::move(*state()))); + ::seastar::schedule(std::make_unique>(std::move(func), std::move(*state()))); } else { assert(_promise); _promise->schedule(std::move(func)); @@ -811,8 +812,8 @@ public: std::tuple get() { if (!state()->available()) { wait(); - } else if (seastar::thread_impl::get() && seastar::thread_impl::should_yield()) { - seastar::thread_impl::yield(); + } else if (thread_impl::get() && thread_impl::should_yield()) { + thread_impl::yield(); } return get_available_state().get(); } @@ -836,13 +837,13 @@ public: /// \cond internal void wait() { - auto thread = seastar::thread_impl::get(); + auto thread = thread_impl::get(); assert(thread); schedule([this, thread] (future_state&& new_state) { *state() = std::move(new_state); - seastar::thread_impl::switch_in(thread); + thread_impl::switch_in(thread); }); - seastar::thread_impl::switch_out(thread); + thread_impl::switch_out(thread); } /// \endcond @@ -878,7 +879,7 @@ public: /// \return a \c future representing the return value of \c func, applied /// to the eventual value of this future. template >> - GCC6_CONCEPT( requires seastar::CanApply ) + GCC6_CONCEPT( requires ::seastar::CanApply ) Result then(Func&& func) noexcept { using futurator = futurize>; @@ -925,7 +926,7 @@ public: /// \return a \c future representing the return value of \c func, applied /// to the eventual value of this future. template >> - GCC6_CONCEPT( requires seastar::CanApply ) + GCC6_CONCEPT( requires ::seastar::CanApply ) Result then_wrapped(Func&& func) noexcept { using futurator = futurize>; @@ -985,7 +986,7 @@ public: * nested will be propagated. */ template - GCC6_CONCEPT( requires seastar::CanApply ) + GCC6_CONCEPT( requires ::seastar::CanApply ) future finally(Func&& func) noexcept { return then_wrapped(finally_body>::value>(std::forward(func))); } @@ -1072,9 +1073,9 @@ public: /// future<>, the handler function does not need to return anything. template /* Broken? - GCC6_CONCEPT( requires seastar::ApplyReturns, std::exception_ptr> - || (sizeof...(T) == 0 && seastar::ApplyReturns) - || (sizeof...(T) == 1 && seastar::ApplyReturns) + GCC6_CONCEPT( requires ::seastar::ApplyReturns, std::exception_ptr> + || (sizeof...(T) == 0 && ::seastar::ApplyReturns) + || (sizeof...(T) == 1 && ::seastar::ApplyReturns) ) */ future handle_exception(Func&& func) noexcept { using func_ret = std::result_of_t; @@ -1162,9 +1163,9 @@ void promise::make_ready() noexcept { if (_task) { _state = nullptr; if (Urgent == urgent::yes && !need_preempt()) { - ::schedule_urgent(std::move(_task)); + ::seastar::schedule_urgent(std::move(_task)); } else { - ::schedule(std::move(_task)); + ::seastar::schedule(std::move(_task)); } } } @@ -1222,7 +1223,7 @@ template template typename futurize::type futurize::apply(Func&& func, std::tuple&& args) noexcept { try { - return convert(::apply(std::forward(func), std::move(args))); + return convert(::seastar::apply(std::forward(func), std::move(args))); } catch (...) { return make_exception_future(std::current_exception()); } @@ -1266,7 +1267,7 @@ inline std::enable_if_t>::value, future<>> do_void_futurize_apply_tuple(Func&& func, std::tuple&& args) noexcept { try { - ::apply(std::forward(func), std::move(args)); + ::seastar::apply(std::forward(func), std::move(args)); return make_ready_future<>(); } catch (...) { return make_exception_future(std::current_exception()); @@ -1278,7 +1279,7 @@ inline std::enable_if_t>::value, future<>> do_void_futurize_apply_tuple(Func&& func, std::tuple&& args) noexcept { try { - return ::apply(std::forward(func), std::move(args)); + return ::seastar::apply(std::forward(func), std::move(args)); } catch (...) { return make_exception_future(std::current_exception()); } @@ -1298,7 +1299,7 @@ template template typename futurize>::type futurize>::apply(Func&& func, std::tuple&& args) noexcept { try { - return ::apply(std::forward(func), std::move(args)); + return ::seastar::apply(std::forward(func), std::move(args)); } catch (...) { return make_exception_future(std::current_exception()); } @@ -1319,7 +1320,7 @@ template inline future futurize::make_exception_future(Arg&& arg) { - return ::make_exception_future(std::forward(arg)); + return ::seastar::make_exception_future(std::forward(arg)); } template @@ -1327,14 +1328,14 @@ template inline future futurize>::make_exception_future(Arg&& arg) { - return ::make_exception_future(std::forward(arg)); + return ::seastar::make_exception_future(std::forward(arg)); } template inline future<> futurize::make_exception_future(Arg&& arg) { - return ::make_exception_future<>(std::forward(arg)); + return ::seastar::make_exception_future<>(std::forward(arg)); } template @@ -1371,4 +1372,6 @@ auto futurize_apply(Func&& func, Args&&... args) { /// \endcond +} + #endif /* FUTURE_HH_ */ diff --git a/core/iostream-impl.hh b/core/iostream-impl.hh index eea88fbfdb9..a371adfa642 100644 --- a/core/iostream-impl.hh +++ b/core/iostream-impl.hh @@ -27,6 +27,8 @@ #include "net/packet.hh" #include "core/future-util.hh" +namespace seastar { + inline future> data_source_impl::skip(uint64_t n) { return do_with(uint64_t(n), [this] (uint64_t& n) { @@ -466,3 +468,5 @@ output_stream::close() { return _fd.close(); }); } + +} diff --git a/core/iostream.hh b/core/iostream.hh index ad58802a57d..5e833995138 100644 --- a/core/iostream.hh +++ b/core/iostream.hh @@ -39,6 +39,8 @@ #include "temporary_buffer.hh" #include "scattered_message.hh" +namespace seastar { + namespace net { class packet; } class data_source_impl { @@ -224,4 +226,6 @@ private: friend class reactor; }; +} + #include "iostream-impl.hh" diff --git a/core/lowres_clock.hh b/core/lowres_clock.hh index b79f7935574..a92ab333eb3 100644 --- a/core/lowres_clock.hh +++ b/core/lowres_clock.hh @@ -25,6 +25,8 @@ #include #include "timer.hh" +namespace seastar { + class lowres_clock { public: typedef int64_t rep; @@ -49,3 +51,6 @@ private: // High resolution timer expires every 10 milliseconds static constexpr std::chrono::milliseconds _granularity{10}; }; + +} + diff --git a/core/manual_clock.hh b/core/manual_clock.hh index cfdaf3d5f52..34e490573ae 100644 --- a/core/manual_clock.hh +++ b/core/manual_clock.hh @@ -23,6 +23,8 @@ #include +namespace seastar { + class manual_clock { public: using rep = int64_t; @@ -39,3 +41,6 @@ public: } static void advance(duration d); }; + +} + diff --git a/core/memory.cc b/core/memory.cc index 7883d6094b3..f63a7eb6557 100644 --- a/core/memory.cc +++ b/core/memory.cc @@ -53,6 +53,8 @@ #include "memory.hh" #include "reactor.hh" +namespace seastar { + namespace memory { static thread_local int abort_on_alloc_failure_suppressed = 0; @@ -67,6 +69,8 @@ disable_abort_on_alloc_failure_temporarily::~disable_abort_on_alloc_failure_temp } +} + #ifndef DEFAULT_ALLOCATOR #include "bitops.hh" @@ -92,6 +96,8 @@ disable_abort_on_alloc_failure_temporarily::~disable_abort_on_alloc_failure_temp #include #endif +namespace seastar { + struct allocation_site { mutable size_t count = 0; // number of live objects allocated at backtrace. mutable size_t size = 0; // amount of bytes in live objects allocated at backtrace. @@ -107,17 +113,21 @@ struct allocation_site { } }; +} + namespace std { template<> -struct hash<::allocation_site> { - size_t operator()(const ::allocation_site& bi) const { - return std::hash()(bi.backtrace); +struct hash { + size_t operator()(const seastar::allocation_site& bi) const { + return std::hash()(bi.backtrace); } }; } +namespace seastar { + using allocation_site_ptr = const allocation_site*; namespace memory { @@ -883,7 +893,7 @@ bool cpu_pages::initialize() { } mmap_area -allocate_anonymous_memory(optional where, size_t how_much) { +allocate_anonymous_memory(std::experimental::optional where, size_t how_much) { return mmap_anonymous(where.value_or(nullptr), how_much, PROT_READ | PROT_WRITE, @@ -891,7 +901,7 @@ allocate_anonymous_memory(optional where, size_t how_much) { } mmap_area -allocate_hugetlbfs_memory(file_desc& fd, optional where, size_t how_much) { +allocate_hugetlbfs_memory(file_desc& fd, std::experimental::optional where, size_t how_much) { auto pos = fd.size(); fd.truncate(pos + how_much); auto ret = fd.map( @@ -1347,7 +1357,9 @@ void set_min_free_pages(size_t pages) { } -using namespace memory; +} + +using namespace seastar::memory; extern "C" [[gnu::visibility("default")]] @@ -1371,7 +1383,7 @@ extern "C" [[gnu::externally_visible]] void free(void* ptr) { if (ptr) { - memory::free(ptr); + seastar::memory::free(ptr); } } @@ -1410,7 +1422,7 @@ void* realloc(void* ptr, size_t size) { return nullptr; } if (size < old_size) { - memory::shrink(ptr, size); + seastar::memory::shrink(ptr, size); return ptr; } auto nptr = malloc(size); @@ -1525,28 +1537,28 @@ void* operator new[](size_t size) { [[gnu::visibility("default")]] void operator delete(void* ptr) throw () { if (ptr) { - memory::free(ptr); + seastar::memory::free(ptr); } } [[gnu::visibility("default")]] void operator delete[](void* ptr) throw () { if (ptr) { - memory::free(ptr); + seastar::memory::free(ptr); } } [[gnu::visibility("default")]] void operator delete(void* ptr, size_t size) throw () { if (ptr) { - memory::free(ptr, size); + seastar::memory::free(ptr, size); } } [[gnu::visibility("default")]] void operator delete[](void* ptr, size_t size) throw () { if (ptr) { - memory::free(ptr, size); + seastar::memory::free(ptr, size); } } @@ -1577,49 +1589,51 @@ void* operator new[](size_t size, std::nothrow_t) throw () { [[gnu::visibility("default")]] void operator delete(void* ptr, std::nothrow_t) throw () { if (ptr) { - memory::free(ptr); + seastar::memory::free(ptr); } } [[gnu::visibility("default")]] void operator delete[](void* ptr, std::nothrow_t) throw () { if (ptr) { - memory::free(ptr); + seastar::memory::free(ptr); } } [[gnu::visibility("default")]] void operator delete(void* ptr, size_t size, std::nothrow_t) throw () { if (ptr) { - memory::free(ptr, size); + seastar::memory::free(ptr, size); } } [[gnu::visibility("default")]] void operator delete[](void* ptr, size_t size, std::nothrow_t) throw () { if (ptr) { - memory::free(ptr, size); + seastar::memory::free(ptr, size); } } -void* operator new(size_t size, with_alignment wa) { +void* operator new(size_t size, seastar::with_alignment wa) { return allocate_aligned(wa.alignment(), size); } -void* operator new[](size_t size, with_alignment wa) { +void* operator new[](size_t size, seastar::with_alignment wa) { return allocate_aligned(wa.alignment(), size); } -void operator delete(void* ptr, with_alignment wa) { +void operator delete(void* ptr, seastar::with_alignment wa) { // only called for matching operator new, so we know ptr != nullptr - return memory::free(ptr); + return seastar::memory::free(ptr); } -void operator delete[](void* ptr, with_alignment wa) { +void operator delete[](void* ptr, seastar::with_alignment wa) { // only called for matching operator new, so we know ptr != nullptr - return memory::free(ptr); + return seastar::memory::free(ptr); } +namespace seastar { + #else namespace memory { @@ -1671,6 +1685,8 @@ void set_min_free_pages(size_t pages) { } +} + void* operator new(size_t size, with_alignment wa) { void* ret; if (posix_memalign(&ret, wa.alignment(), size) != 0) { @@ -1695,6 +1711,11 @@ void operator delete[](void* ptr, with_alignment wa) { return ::free(ptr); } +namespace seastar { + #endif /// \endcond + +} + diff --git a/core/memory.hh b/core/memory.hh index d8be08082bb..2e6ff5be73b 100644 --- a/core/memory.hh +++ b/core/memory.hh @@ -27,6 +27,7 @@ #include #include +namespace seastar { /// \defgroup memory-module Memory management /// @@ -207,9 +208,11 @@ public: size_t alignment() const { return _align; } }; -void* operator new(size_t size, with_alignment wa); -void* operator new[](size_t size, with_alignment wa); -void operator delete(void* ptr, with_alignment wa); -void operator delete[](void* ptr, with_alignment wa); +} + +void* operator new(size_t size, seastar::with_alignment wa); +void* operator new[](size_t size, seastar::with_alignment wa); +void operator delete(void* ptr, seastar::with_alignment wa); +void operator delete[](void* ptr, seastar::with_alignment wa); #endif /* MEMORY_HH_ */ diff --git a/core/metrics.cc b/core/metrics.cc index 503c3f40733..2f90fead1fe 100644 --- a/core/metrics.cc +++ b/core/metrics.cc @@ -175,7 +175,7 @@ metric_groups_impl& metric_groups_impl::add_metric(group_name_type name, const m metric_id id(name, md._impl->name, md._impl->labels); shared_ptr rm = - ::make_shared(id, md._impl->type.base_type, md._impl->f, md._impl->d, md._impl->enabled); + ::seastar::make_shared(id, md._impl->type.base_type, md._impl->f, md._impl->d, md._impl->enabled); get_local_impl()->add_registration(id, rm); diff --git a/core/metrics_api.hh b/core/metrics_api.hh index f794263db17..6b85bdad8ad 100644 --- a/core/metrics_api.hh +++ b/core/metrics_api.hh @@ -50,7 +50,7 @@ struct hash { result_type operator()(argument_type const& s) const { result_type h = 0; for (auto&& i : s) { - boost::hash_combine(h, std::hash{}(i.second)); + boost::hash_combine(h, std::hash{}(i.second)); } return h; } @@ -133,8 +133,8 @@ struct hash typedef ::std::size_t result_type; result_type operator()(argument_type const& s) const { - result_type const h1 ( std::hash{}(s.group_name()) ); - result_type const h2 ( std::hash{}(s.instance_id()) ); + result_type const h1 ( std::hash{}(s.group_name()) ); + result_type const h2 ( std::hash{}(s.instance_id()) ); return h1 ^ (h2 << 1); // or use boost::hash_combine } }; diff --git a/core/posix.cc b/core/posix.cc index 7aa7ea96494..7dae9804a70 100644 --- a/core/posix.cc +++ b/core/posix.cc @@ -23,6 +23,8 @@ #include "align.hh" #include +namespace seastar { + file_desc file_desc::temporary(sstring directory) { // FIXME: add O_TMPFILE support one day @@ -100,3 +102,6 @@ void posix_thread::join() { pthread_join(_pthread, NULL); _valid = false; } + +} + diff --git a/core/posix.hh b/core/posix.hh index 87965eda556..1a363771d53 100644 --- a/core/posix.hh +++ b/core/posix.hh @@ -44,6 +44,8 @@ #include #include "net/socket_defs.hh" +namespace seastar { + /// \file /// \defgroup posix-support POSIX Support /// @@ -317,8 +319,6 @@ private: }; -namespace seastar { - namespace posix { /// Converts a duration value to a `timespec` @@ -363,8 +363,6 @@ to_absolute_itimerspec(std::chrono::time_point base, std::chron } -} - class posix_thread { public: class attr; @@ -462,4 +460,6 @@ void pin_this_thread(unsigned cpu_id) { /// @} +} + #endif /* FILE_DESC_HH_ */ diff --git a/core/preempt.hh b/core/preempt.hh index 92a0b54e1de..e821473706d 100644 --- a/core/preempt.hh +++ b/core/preempt.hh @@ -22,6 +22,8 @@ #pragma once #include +namespace seastar { + extern __thread bool g_need_preempt; inline bool need_preempt() { @@ -34,4 +36,4 @@ inline bool need_preempt() { #endif } - +} diff --git a/core/prefetch.hh b/core/prefetch.hh index 296f22f6648..71f6d2d6d8c 100644 --- a/core/prefetch.hh +++ b/core/prefetch.hh @@ -27,6 +27,8 @@ #include #include "align.hh" +namespace seastar { + static constexpr size_t cacheline_size = 64; template struct prefetcher; @@ -111,4 +113,6 @@ void prefetchw_n(T** pptr) { boost::mpl::for_each< boost::mpl::range_c >( [pptr] (size_t x) { prefetchw(*(pptr + x)); } ); } +} + #endif diff --git a/core/print.hh b/core/print.hh index f07fc604a56..b2536bbac74 100644 --- a/core/print.hh +++ b/core/print.hh @@ -47,6 +47,8 @@ operator<<(std::ostream&& os, const void* ptr) { return os << ptr; // selects non-rvalue version } +namespace seastar { + template std::ostream& fprint(std::ostream& os, const char* fmt, A&&... a) { @@ -119,7 +121,6 @@ log(A&&... a) { print(std::forward(a)...); } -namespace seastar { /** * Evaluate the formatted string in a native fmt library format * diff --git a/core/prometheus.cc b/core/prometheus.cc index 05d5f5188b0..d7717a19532 100644 --- a/core/prometheus.cc +++ b/core/prometheus.cc @@ -33,7 +33,7 @@ #include #include -using namespace seastar; +namespace seastar { namespace prometheus { namespace pm = io::prometheus::client; @@ -294,3 +294,4 @@ future<> start(httpd::http_server_control& http_server, config ctx) { } } +} diff --git a/core/prometheus.hh b/core/prometheus.hh index 32e61d4cbb6..7cc031e6ba4 100644 --- a/core/prometheus.hh +++ b/core/prometheus.hh @@ -23,6 +23,8 @@ #include "http/httpd.hh" +namespace seastar { + namespace prometheus { /*! @@ -36,3 +38,5 @@ struct config { future<> start(httpd::http_server_control& http_server, config ctx); } + +} diff --git a/core/queue.hh b/core/queue.hh index 98de0751279..b3ed8f4d21b 100644 --- a/core/queue.hh +++ b/core/queue.hh @@ -27,6 +27,8 @@ #include #include +namespace seastar { + template class queue { std::queue> _q; @@ -235,4 +237,6 @@ future<> queue::not_full() { } } +} + #endif /* QUEUE_HH_ */ diff --git a/core/ragel.hh b/core/ragel.hh index daefca6cf82..7a7ed801019 100644 --- a/core/ragel.hh +++ b/core/ragel.hh @@ -31,6 +31,8 @@ #include #include "future.hh" +namespace seastar { + // Support classes for Ragel parsers // Builds an sstring that can be scattered across multiple packets. @@ -137,4 +139,6 @@ public: } }; +} + #endif /* RAGEL_HH_ */ diff --git a/core/reactor.cc b/core/reactor.cc index d29e1f16410..dd8bbf90687 100644 --- a/core/reactor.cc +++ b/core/reactor.cc @@ -94,10 +94,11 @@ #include "core/metrics.hh" #include "execution_stage.hh" +namespace seastar { + using namespace std::chrono_literals; using namespace net; -using namespace seastar; seastar::logger seastar_logger("seastar"); @@ -1786,8 +1787,6 @@ reactor::touch_directory(sstring name) { }); } -namespace seastar { - file_handle::file_handle(const file_handle& x) : _impl(x._impl ? x._impl->clone() : std::unique_ptr()) { } @@ -1812,8 +1811,6 @@ file_handle::to_file() && { return file(std::move(*_impl).to_file()); } -} - file::file(seastar::file_handle&& handle) : _file_impl(std::move(std::move(handle).to_file()._file_impl)) { } @@ -1860,7 +1857,7 @@ posix_file_handle_impl::clone() const { shared_ptr posix_file_handle_impl::to_file() && { - auto ret = ::make_shared(_fd, _refcount); + auto ret = ::seastar::make_shared(_fd, _refcount); _fd = -1; _refcount = nullptr; return ret; @@ -3256,10 +3253,14 @@ void schedule_urgent(std::unique_ptr t) { engine().add_urgent_task(std::move(t)); } +} + bool operator==(const ::sockaddr_in a, const ::sockaddr_in b) { return (a.sin_addr.s_addr == b.sin_addr.s_addr) && (a.sin_port == b.sin_port); } +namespace seastar { + void network_stack_registry::register_stack(sstring name, boost::program_options::options_description opts, std::function> (options opts)> create, bool make_default) { @@ -4131,6 +4132,9 @@ network_stack_registrator nsr_posix{"posix", }; #ifndef NO_EXCEPTION_INTERCEPT + +} + #include extern "C" @@ -4143,12 +4147,14 @@ int _Unwind_RaiseException(void *h) { if (!org) { org = (throw_fn)dlsym (RTLD_NEXT, "_Unwind_RaiseException"); } - if (local_engine) { - engine()._cxx_exceptions++; + if (seastar::local_engine) { + seastar::engine()._cxx_exceptions++; } return org(h); } +namespace seastar { + #endif steady_clock_type::duration reactor::total_idle_time() { @@ -4158,3 +4164,5 @@ steady_clock_type::duration reactor::total_idle_time() { steady_clock_type::duration reactor::total_busy_time() { return steady_clock_type::now() - _start_time - _total_idle; } + +} diff --git a/core/reactor.hh b/core/reactor.hh index c26082674df..af7eb32b161 100644 --- a/core/reactor.hh +++ b/core/reactor.hh @@ -84,6 +84,8 @@ extern "C" int _Unwind_RaiseException(void *h); +namespace seastar { + using shard_id = unsigned; @@ -158,6 +160,7 @@ private: std::unique_ptr _s; }; +} namespace std { @@ -172,6 +175,8 @@ struct hash<::sockaddr_in> { bool operator==(const ::sockaddr_in a, const ::sockaddr_in b); +namespace seastar { + class network_stack_registrator { public: using options = boost::program_options::variables_map; @@ -303,7 +308,7 @@ class smp_message_queue { // this makes sure that they have at least one cache line // between them, so hw prefecther will not accidentally prefetch // cache line used by aother cpu. - seastar::metrics::metric_groups _metrics; + metrics::metric_groups _metrics; struct alignas(64) { size_t _received = 0; size_t _last_rcv_batch = 0; @@ -529,7 +534,7 @@ private: uint64_t ops; uint32_t nr_queued; std::chrono::duration queue_time; - seastar::metrics::metric_groups _metric_groups; + metrics::metric_groups _metric_groups; priority_class_data(sstring name, priority_class_ptr ptr, shard_id owner); }; @@ -700,12 +705,12 @@ private: unsigned _tasks_processed_report_threshold; unsigned _max_task_backlog = 1000; - seastar::timer_set, &timer<>::_link> _timers; - seastar::timer_set, &timer<>::_link>::timer_list_t _expired_timers; - seastar::timer_set, &timer::_link> _lowres_timers; - seastar::timer_set, &timer::_link>::timer_list_t _expired_lowres_timers; - seastar::timer_set, &timer::_link> _manual_timers; - seastar::timer_set, &timer::_link>::timer_list_t _expired_manual_timers; + timer_set, &timer<>::_link> _timers; + timer_set, &timer<>::_link>::timer_list_t _expired_timers; + timer_set, &timer::_link> _lowres_timers; + timer_set, &timer::_link>::timer_list_t _expired_lowres_timers; + timer_set, &timer::_link> _manual_timers; + timer_set, &timer::_link>::timer_list_t _expired_manual_timers; io_context_t _io_context; std::vector _pending_aio; semaphore _io_context_available; @@ -816,13 +821,13 @@ public: server_socket listen(socket_address sa, listen_options opts = {}); future connect(socket_address sa); - future connect(socket_address, socket_address, seastar::transport proto = seastar::transport::TCP); + future connect(socket_address, socket_address, transport proto = transport::TCP); pollable_fd posix_listen(socket_address sa, listen_options opts = {}); bool posix_reuseport_available() const { return _reuseport; } - lw_shared_ptr make_pollable_fd(socket_address sa, seastar::transport proto = seastar::transport::TCP); + lw_shared_ptr make_pollable_fd(socket_address sa, transport proto = transport::TCP); future<> posix_connect(lw_shared_ptr pfd, socket_address sa, socket_address local); future accept(pollable_fd_state& listen_fd); @@ -946,8 +951,8 @@ private: friend class smp_message_queue; friend class poller; friend void add_to_flush_poller(output_stream* os); - friend int _Unwind_RaiseException(void *h); - seastar::metrics::metric_groups _metric_groups; + friend int ::_Unwind_RaiseException(void *h); + metrics::metric_groups _metric_groups; public: bool wait_and_process(int timeout = 0, const sigset_t* active_sigmask = nullptr) { return _backend.wait_and_process(timeout, active_sigmask); @@ -1419,6 +1424,8 @@ typename timer::time_point timer::get_timeout() { return _expiry; } -extern seastar::logger seastar_logger; +extern logger seastar_logger; + +} #endif /* REACTOR_HH_ */ diff --git a/core/report_exception.hh b/core/report_exception.hh index 65f1cb4eabb..af2de3b6e79 100644 --- a/core/report_exception.hh +++ b/core/report_exception.hh @@ -23,4 +23,9 @@ #include +namespace seastar { + void report_exception(std::experimental::string_view message, std::exception_ptr) noexcept; + +} + diff --git a/core/resource.cc b/core/resource.cc index 0a9127977eb..1b6fa49dbce 100644 --- a/core/resource.cc +++ b/core/resource.cc @@ -25,6 +25,8 @@ #include "resource.hh" #include "core/align.hh" +namespace seastar { + // Overload for boost program options parsing/validation void validate(boost::any& v, const std::vector& values, @@ -84,6 +86,8 @@ size_t calculate_memory(configuration c, size_t available_memory, float panic_fa } +} + #ifdef HAVE_HWLOC #include "util/defer.hh" @@ -92,6 +96,8 @@ size_t calculate_memory(configuration c, size_t available_memory, float panic_fa #include #include +namespace seastar { + cpu_set_t cpuid_to_cpuset(unsigned cpuid) { cpu_set_t cs; CPU_ZERO(&cs); @@ -329,11 +335,15 @@ unsigned nr_processing_units() { } +} + #else #include "resource.hh" #include +namespace seastar { + namespace resource { // Without hwloc, we don't support tuning the number of IO queues. So each CPU gets their. @@ -378,4 +388,6 @@ unsigned nr_processing_units() { } +} + #endif diff --git a/core/resource.hh b/core/resource.hh index 27dffc232ce..6f77634b504 100644 --- a/core/resource.hh +++ b/core/resource.hh @@ -30,6 +30,8 @@ #include #include +namespace seastar { + cpu_set_t cpuid_to_cpuset(unsigned cpuid); namespace resource { @@ -91,4 +93,7 @@ extern void validate(boost::any& v, const std::vector& values, cpuset_bpo_wrapper* target_type, int); + +} + #endif /* RESOURCE_HH_ */ diff --git a/core/rwlock.hh b/core/rwlock.hh index 492f22b4320..bf66be93126 100644 --- a/core/rwlock.hh +++ b/core/rwlock.hh @@ -24,6 +24,8 @@ #include "semaphore.hh" +namespace seastar { + /// \cond internal // lock / unlock semantics for rwlock, so it can be used with with_lock() class rwlock; @@ -141,4 +143,6 @@ inline void rwlock_for_write::unlock() { /// @} +} + #endif /* CORE_RWLOCK_HH_ */ diff --git a/core/scattered_message.hh b/core/scattered_message.hh index edb04feb8a4..109f3993834 100644 --- a/core/scattered_message.hh +++ b/core/scattered_message.hh @@ -30,6 +30,8 @@ #include #include +namespace seastar { + template class scattered_message { private: @@ -102,4 +104,6 @@ public: } }; +} + #endif diff --git a/core/scollectd-impl.hh b/core/scollectd-impl.hh index 6fa8319fd50..bb21705f2e8 100644 --- a/core/scollectd-impl.hh +++ b/core/scollectd-impl.hh @@ -25,6 +25,8 @@ #include "core/reactor.hh" #include "core/metrics_api.hh" +namespace seastar { + namespace scollectd { using namespace std::chrono_literals; @@ -84,3 +86,5 @@ private: impl & get_impl(); }; + +} diff --git a/core/scollectd.cc b/core/scollectd.cc index ab0742e9a2b..49cace8c313 100644 --- a/core/scollectd.cc +++ b/core/scollectd.cc @@ -34,6 +34,8 @@ #include "core/metrics_api.hh" #include "core/byteorder.hh" +namespace seastar { + bool scollectd::type_instance_id::operator<( const scollectd::type_instance_id& id2) const { auto& id1 = *this; @@ -53,7 +55,7 @@ bool scollectd::type_instance_id::operator==( namespace scollectd { -seastar::logger logger("scollectd"); +::seastar::logger logger("scollectd"); thread_local unsigned type_instance_id::_next_truncated_idx = 0; registration::~registration() { @@ -945,8 +947,10 @@ type_id type_id_for(known_type t) { } } -seastar::metrics::impl::value_map get_value_map() { - return seastar::metrics::impl::get_value_map(); +metrics::impl::value_map get_value_map() { + return metrics::impl::get_value_map(); +} + } } diff --git a/core/scollectd.hh b/core/scollectd.hh index 20533c95ab8..2fced1dbe18 100644 --- a/core/scollectd.hh +++ b/core/scollectd.hh @@ -43,6 +43,8 @@ #include "core/metrics_api.hh" +namespace seastar { + /** * Implementation of rudimentary collectd data gathering. * @@ -449,7 +451,7 @@ struct typed_value { private: type_id _type_id; scollectd::type_instance _type_instance; - ::shared_ptr _values; + shared_ptr _values; }; class plugin_instance_metrics { @@ -793,7 +795,7 @@ template Arg&& arg, bool enabled = true) { namespace sm = seastar::metrics::impl; shared_ptr rm = - ::make_shared(arg.type, sm::make_function(arg.value, arg.type), d, enabled); + make_shared(arg.type, sm::make_function(arg.value, arg.type), d, enabled); seastar::metrics::impl::get_local_impl()->add_registration(to_metrics_id(id), rm); return id; } @@ -843,11 +845,13 @@ template typed_value::typed_value(const type_id& tid, const scollectd::type_instance& ti, description d, Args&&... args) : _type_id(tid) , _type_instance(ti) - , _values(::make_shared(args)...))>(make_type_instance(std::move(d), std::forward(args)...))) + , _values(::seastar::make_shared(args)...))>(make_type_instance(std::move(d), std::forward(args)...))) {} // Send a message packet (string) future<> send_notification(const type_instance_id & id, const sstring & msg); }; +} + #endif /* SCOLLECTD_HH_ */ diff --git a/core/scollectd_api.hh b/core/scollectd_api.hh index 91ace8889e7..9baf7463f53 100644 --- a/core/scollectd_api.hh +++ b/core/scollectd_api.hh @@ -8,6 +8,8 @@ #include "core/scollectd.hh" #include "core/metrics_api.hh" +namespace seastar { + namespace scollectd { using collectd_value = seastar::metrics::impl::metric_value; @@ -28,7 +30,9 @@ bool is_enabled(const scollectd::type_instance_id& id); void enable(const scollectd::type_instance_id& id, bool enable); -seastar::metrics::impl::value_map get_value_map(); +metrics::impl::value_map get_value_map(); +} + } #endif /* CORE_SCOLLECTD_API_HH_ */ diff --git a/core/seastar.hh b/core/seastar.hh index 0654b99c23c..241dd214582 100644 --- a/core/seastar.hh +++ b/core/seastar.hh @@ -44,6 +44,8 @@ #include "sstring.hh" #include "future.hh" +namespace seastar { + // iostream.hh template class input_stream; template class output_stream; @@ -53,9 +55,7 @@ class server_socket; class connected_socket; class socket_address; class listen_options; -namespace seastar { enum class transport; -} // file.hh class file; @@ -121,7 +121,7 @@ future connect(socket_address sa); /// \param proto transport protocol (TCP or SCTP) /// /// \return a \ref connected_socket object, or an exception -future connect(socket_address sa, socket_address local, seastar::transport proto); +future connect(socket_address sa, socket_address local, transport proto); /// @} @@ -281,3 +281,5 @@ future<> link_file(sstring oldpath, sstring newpath); future file_system_at(sstring name); /// @} + +} diff --git a/core/semaphore.hh b/core/semaphore.hh index 4ec99465f13..8ad99b41275 100644 --- a/core/semaphore.hh +++ b/core/semaphore.hh @@ -29,6 +29,8 @@ #include "timer.hh" #include "expiring_fifo.hh" +namespace seastar { + /// \addtogroup fiber-module /// @{ @@ -416,4 +418,6 @@ using semaphore = basic_semaphore; /// @} +} + #endif /* CORE_SEMAPHORE_HH_ */ diff --git a/core/sharded.hh b/core/sharded.hh index b28226a2aa3..b15d6f944a9 100644 --- a/core/sharded.hh +++ b/core/sharded.hh @@ -79,7 +79,7 @@ public: template class sharded { struct entry { - ::shared_ptr service; + shared_ptr service; promise<> freed; }; std::vector _instances; @@ -163,7 +163,7 @@ public: map_reduce(Reducer&& r, Ret (Service::*func)(FuncArgs...), Args&&... args) -> typename reducer_traits::future_type { - return ::map_reduce(boost::make_counting_iterator(0), + return ::seastar::map_reduce(boost::make_counting_iterator(0), boost::make_counting_iterator(_instances.size()), [this, func, args = std::make_tuple(std::forward(args)...)] (unsigned c) mutable { return smp::submit_to(c, [this, func, args] () mutable { @@ -187,7 +187,7 @@ public: inline auto map_reduce(Reducer&& r, Func&& func) -> typename reducer_traits::future_type { - return ::map_reduce(boost::make_counting_iterator(0), + return ::seastar::map_reduce(boost::make_counting_iterator(0), boost::make_counting_iterator(_instances.size()), [this, &func] (unsigned c) mutable { return smp::submit_to(c, [this, func] () mutable { @@ -223,7 +223,7 @@ public: return map(*inst); }); }; - return ::map_reduce(smp::all_cpus().begin(), smp::all_cpus().end(), + return ::seastar::map_reduce(smp::all_cpus().begin(), smp::all_cpus().end(), std::move(wrapped_map), std::move(initial), std::move(reduce)); @@ -297,18 +297,18 @@ public: bool local_is_initialized(); private: - void track_deletion(::shared_ptr& s, std::false_type) { + void track_deletion(shared_ptr& s, std::false_type) { // do not wait for instance to be deleted since it is not going to notify us service_deleted(); } - void track_deletion(::shared_ptr& s, std::true_type) { + void track_deletion(shared_ptr& s, std::true_type) { s->_delete_cb = std::bind(std::mem_fn(&sharded::service_deleted), this); } template shared_ptr create_local_service(Args&&... args) { - auto s = ::make_shared(std::forward(args)...); + auto s = ::seastar::make_shared(std::forward(args)...); track_deletion(s, std::is_base_of, Service>()); return s; } @@ -452,8 +452,6 @@ inline bool sharded::local_is_initialized() { _instances[engine().cpu_id()].service; } -} - /// Smart pointer wrapper which makes it safe to move across CPUs. /// /// \c foreign_ptr<> is a smart pointer wrapper which, unlike @@ -540,7 +538,9 @@ foreign_ptr make_foreign(T ptr) { } template -struct is_smart_ptr<::foreign_ptr> : std::true_type {}; +struct is_smart_ptr> : std::true_type {}; + +} /// @} diff --git a/core/shared_future.hh b/core/shared_future.hh index ba96dacdc3b..1d407255b59 100644 --- a/core/shared_future.hh +++ b/core/shared_future.hh @@ -28,6 +28,8 @@ /// \addtogroup future-module /// @{ +namespace seastar { + /// Changes the clock used by shared_future<> and shared_promise<> when passed as the first template parameter. template struct with_clock {}; @@ -248,3 +250,5 @@ public: }; /// @} + +} diff --git a/core/shared_ptr.hh b/core/shared_ptr.hh index fec7fb202f4..4b8b0700c0e 100644 --- a/core/shared_ptr.hh +++ b/core/shared_ptr.hh @@ -30,6 +30,8 @@ #include "util/is_smart_ptr.hh" #include "util/indirect.hh" +namespace seastar { + // This header defines two shared pointer facilities, lw_shared_ptr<> and // shared_ptr<>, both modeled after std::shared_ptr<>. // @@ -704,28 +706,34 @@ using shared_ptr_equal_by_value = indirect_equal_to>; template using shared_ptr_value_hash = indirect_hash>; +} + namespace std { template -struct hash> : private hash { - size_t operator()(const lw_shared_ptr& p) const { +struct hash> : private hash { + size_t operator()(const seastar::lw_shared_ptr& p) const { return hash::operator()(p.get()); } }; template -struct hash<::shared_ptr> : private hash { - size_t operator()(const ::shared_ptr& p) const { +struct hash> : private hash { + size_t operator()(const seastar::shared_ptr& p) const { return hash::operator()(p.get()); } }; } +namespace seastar { + template -struct is_smart_ptr<::shared_ptr> : std::true_type {}; +struct is_smart_ptr> : std::true_type {}; template -struct is_smart_ptr<::lw_shared_ptr> : std::true_type {}; +struct is_smart_ptr> : std::true_type {}; + +} #endif /* SHARED_PTR_HH_ */ diff --git a/core/shared_ptr_debug_helper.hh b/core/shared_ptr_debug_helper.hh index 869fb96348a..ab2295891aa 100644 --- a/core/shared_ptr_debug_helper.hh +++ b/core/shared_ptr_debug_helper.hh @@ -26,6 +26,8 @@ #include #include +namespace seastar { + // A counter that is only comfortable being incremented on the cpu // it was created on. Useful for verifying that a shared_ptr // or lw_shared_ptr isn't misued across cores. @@ -62,5 +64,7 @@ private: } }; +} + #endif diff --git a/core/slab.hh b/core/slab.hh index 9b356f019f4..552732b7a7b 100644 --- a/core/slab.hh +++ b/core/slab.hh @@ -34,6 +34,8 @@ #include "core/align.hh" #include "core/memory.hh" +namespace seastar { + static constexpr uint16_t SLAB_MAGIC_NUMBER = 0x51AB; // meant to be 'SLAB' :-) namespace bi = boost::intrusive; @@ -565,4 +567,6 @@ public: } }; +} + #endif /* __SLAB_ALLOCATOR__ */ diff --git a/core/sleep.hh b/core/sleep.hh index 405a88e91cd..f48d923317d 100644 --- a/core/sleep.hh +++ b/core/sleep.hh @@ -29,6 +29,7 @@ #include "core/reactor.hh" #include "core/future.hh" +namespace seastar { /// \file @@ -78,3 +79,5 @@ future<> sleep_abortable(std::chrono::duration dur) { } catch(condition_variable_timed_out&) {}; }); } + +} diff --git a/core/sstring.hh b/core/sstring.hh index 2bd165ad9ff..d3a4389e991 100644 --- a/core/sstring.hh +++ b/core/sstring.hh @@ -37,6 +37,8 @@ #include #include "core/temporary_buffer.hh" +namespace seastar { + template class basic_sstring; @@ -655,17 +657,21 @@ operator>>(std::basic_istream& is, return is; } +} + namespace std { template -struct hash> { - size_t operator()(const basic_sstring& s) const { +struct hash> { + size_t operator()(const seastar::basic_sstring& s) const { return std::hash>()(s); } }; } +namespace seastar { + static inline char* copy_str_to(char* dst) { return dst; @@ -690,6 +696,8 @@ inline string_type to_sstring(T value) { return sstring::to_sstring(value); } +} + namespace std { template inline diff --git a/core/stream.hh b/core/stream.hh index c6c9c248725..a7f26122103 100644 --- a/core/stream.hh +++ b/core/stream.hh @@ -27,6 +27,8 @@ #include #include +namespace seastar { + // A stream/subscription pair is similar to a promise/future pair, // but apply to a sequence of values instead of a single value. // @@ -235,4 +237,6 @@ subscription::done() { return _stream->_done.get_future(); } +} + #endif /* STREAM_HH_ */ diff --git a/core/systemwide_memory_barrier.cc b/core/systemwide_memory_barrier.cc index a0f8800978b..2a0ec12c313 100644 --- a/core/systemwide_memory_barrier.cc +++ b/core/systemwide_memory_barrier.cc @@ -24,6 +24,8 @@ #include #include +namespace seastar { + // cause all threads to invoke a full memory barrier void systemwide_memory_barrier() { @@ -47,3 +49,6 @@ systemwide_memory_barrier() { int r2 = mprotect(mem, getpagesize(), PROT_READ); assert(r2 == 0); } + +} + diff --git a/core/systemwide_memory_barrier.hh b/core/systemwide_memory_barrier.hh index abb09882ad6..a408310d6f2 100644 --- a/core/systemwide_memory_barrier.hh +++ b/core/systemwide_memory_barrier.hh @@ -21,6 +21,8 @@ #pragma once +namespace seastar { + /// \cond internal // cause all threads to invoke a full memory barrier @@ -28,3 +30,6 @@ void systemwide_memory_barrier(); /// \endcond + +} + diff --git a/core/task.hh b/core/task.hh index e510f2af065..05955013632 100644 --- a/core/task.hh +++ b/core/task.hh @@ -23,6 +23,8 @@ #include +namespace seastar { + class task { public: virtual ~task() noexcept {} @@ -47,3 +49,5 @@ std::unique_ptr make_task(Func&& func) { return std::make_unique>(std::forward(func)); } + +} diff --git a/core/temporary_buffer.hh b/core/temporary_buffer.hh index 8f7cc3d2172..c0dd9e6d426 100644 --- a/core/temporary_buffer.hh +++ b/core/temporary_buffer.hh @@ -27,6 +27,8 @@ #include #include +namespace seastar { + /// \addtogroup memory-module /// @{ @@ -222,4 +224,6 @@ public: /// @} +} + #endif /* TEMPORARY_BUFFER_HH_ */ diff --git a/core/thread.cc b/core/thread.cc index 1df156affb9..a923364aeb8 100644 --- a/core/thread.cc +++ b/core/thread.cc @@ -260,10 +260,10 @@ thread_context::yield() { } bool thread::try_run_one_yielded_thread() { - if (seastar::thread_context::_preempted_threads.empty()) { + if (thread_context::_preempted_threads.empty()) { return false; } - auto&& t = seastar::thread_context::_preempted_threads.front(); + auto&& t = thread_context::_preempted_threads.front(); t._sched_timer.cancel(); t._sched_promise->set_value(); thread_context::_preempted_threads.pop_front(); diff --git a/core/thread.hh b/core/thread.hh index fa7938803eb..01443c57f57 100644 --- a/core/thread.hh +++ b/core/thread.hh @@ -193,10 +193,10 @@ public: static bool should_yield(); static bool running_in_thread() { - return seastar::thread_impl::get() != nullptr; + return thread_impl::get() != nullptr; } private: - friend class ::reactor; + friend class reactor; // To be used by seastar reactor only. static bool try_run_one_yielded_thread(); }; diff --git a/core/timer-set.hh b/core/timer-set.hh index 7a29906bed7..1999d355b09 100644 --- a/core/timer-set.hh +++ b/core/timer-set.hh @@ -21,9 +21,10 @@ #include #include "bitset-iter.hh" +namespace seastar { + namespace bi = boost::intrusive; -namespace seastar { /** * A data structure designed for holding and expiring timers. It's * optimized for timer non-delivery by deferring sorting cost until diff --git a/core/timer.hh b/core/timer.hh index ea7f118f598..3fdb180b7d6 100644 --- a/core/timer.hh +++ b/core/timer.hh @@ -28,6 +28,8 @@ #include "future.hh" #include "timer-set.hh" +namespace seastar { + using steady_clock_type = std::chrono::steady_clock; template @@ -67,6 +69,8 @@ public: bool cancel(); time_point get_timeout(); friend class reactor; - friend class seastar::timer_set; + friend class timer_set; }; +} + diff --git a/core/transfer.hh b/core/transfer.hh index c04fff80f1b..d912e52bc85 100644 --- a/core/transfer.hh +++ b/core/transfer.hh @@ -37,6 +37,8 @@ #include #include +namespace seastar { + template inline void @@ -69,4 +71,6 @@ transfer_pass2(Alloc& a, T* from, T* to, a.destroy(from); } +} + #endif /* TRANSFER_HH_ */ diff --git a/core/unaligned.hh b/core/unaligned.hh index d9fb92c0416..470390c6e0e 100644 --- a/core/unaligned.hh +++ b/core/unaligned.hh @@ -46,6 +46,8 @@ // cause the sanitizer not to generate runtime alignment checks for this // access. +namespace seastar { + template struct unaligned { T raw; @@ -67,3 +69,5 @@ template inline auto unaligned_cast(const F* p) { return reinterpret_cast>*>(p); } + +} diff --git a/core/units.hh b/core/units.hh index cca368b5bb2..8bb503b761d 100644 --- a/core/units.hh +++ b/core/units.hh @@ -22,8 +22,12 @@ #ifndef UNITS_HH_ #define UNITS_HH_ +namespace seastar { + static constexpr size_t KB = 1 << 10; static constexpr size_t MB = 1 << 20; static constexpr size_t GB = 1 << 30; +} + #endif diff --git a/core/vector-data-sink.hh b/core/vector-data-sink.hh index c45b0f93fa6..76cb46c6727 100644 --- a/core/vector-data-sink.hh +++ b/core/vector-data-sink.hh @@ -24,6 +24,8 @@ #include "core/reactor.hh" +namespace seastar { + class vector_data_sink final : public data_sink_impl { public: using vector_type = std::vector; @@ -43,4 +45,6 @@ public: } }; +} + #endif diff --git a/core/vla.hh b/core/vla.hh index e6cd71eee5a..11a569b640b 100644 --- a/core/vla.hh +++ b/core/vla.hh @@ -28,6 +28,8 @@ #include #include +namespace seastar { + // Some C APIs have a structure with a variable length array at the end. // This is a helper function to help allocate it. // @@ -56,6 +58,6 @@ make_struct_with_vla(E S::*last, size_t nr) { return s; } - +} #endif /* VLA_HH_ */ diff --git a/core/weak_ptr.hh b/core/weak_ptr.hh index df3d930a885..272696bfabb 100644 --- a/core/weak_ptr.hh +++ b/core/weak_ptr.hh @@ -23,6 +23,8 @@ #include +namespace seastar { + template class weak_ptr { template @@ -94,3 +96,6 @@ public: return ptr; } }; + +} + diff --git a/core/xen/gntalloc.hh b/core/xen/gntalloc.hh index 79fb2ed6c87..e6d94de520d 100644 --- a/core/xen/gntalloc.hh +++ b/core/xen/gntalloc.hh @@ -20,6 +20,8 @@ #include "core/posix.hh" +namespace seastar { + namespace xen { class gntref { @@ -66,4 +68,6 @@ extern gntref invalid_ref; } +} + #endif diff --git a/http/api_docs.cc b/http/api_docs.cc index 473ec7fb15b..32ffbca04da 100644 --- a/http/api_docs.cc +++ b/http/api_docs.cc @@ -26,9 +26,13 @@ using namespace std; +namespace seastar { + namespace httpd { const sstring api_registry_builder::DEFAULT_PATH = "/api-doc"; const sstring api_registry_builder::DEFAULT_DIR = "."; } + +} diff --git a/http/api_docs.hh b/http/api_docs.hh index facf059a0f8..16410fd8201 100644 --- a/http/api_docs.hh +++ b/http/api_docs.hh @@ -27,6 +27,8 @@ #include "transformers.hh" #include +namespace seastar { + namespace httpd { struct api_doc : public json::json_base { @@ -156,4 +158,6 @@ public: } +} + #endif /* API_DOCS_HH_ */ diff --git a/http/common.cc b/http/common.cc index e6966680a4c..1612e0ef119 100644 --- a/http/common.cc +++ b/http/common.cc @@ -21,6 +21,8 @@ #include "common.hh" +namespace seastar { + namespace httpd { operation_type str2type(const sstring& type) { @@ -37,3 +39,6 @@ operation_type str2type(const sstring& type) { } } + +} + diff --git a/http/common.hh b/http/common.hh index 56f83263665..d78db8cde53 100644 --- a/http/common.hh +++ b/http/common.hh @@ -25,6 +25,8 @@ #include #include "core/sstring.hh" +namespace seastar { + namespace httpd { @@ -70,4 +72,6 @@ operation_type str2type(const sstring& type); } +} + #endif /* COMMON_HH_ */ diff --git a/http/exception.hh b/http/exception.hh index e79d025bc17..66410af7aa2 100644 --- a/http/exception.hh +++ b/http/exception.hh @@ -25,6 +25,8 @@ #include "reply.hh" #include "json/json_elements.hh" +namespace seastar { + namespace httpd { /** @@ -136,4 +138,6 @@ private: } +} + #endif /* EXCEPTION_HH_ */ diff --git a/http/file_handler.cc b/http/file_handler.cc index 98b2938a62f..db611cefa2b 100644 --- a/http/file_handler.cc +++ b/http/file_handler.cc @@ -28,6 +28,8 @@ #include "core/app-template.hh" #include "exception.hh" +namespace seastar { + namespace httpd { directory_handler::directory_handler(const sstring& doc_root, @@ -132,3 +134,5 @@ future> file_handler::handle(const sstring& path, } } + +} diff --git a/http/file_handler.hh b/http/file_handler.hh index 2c2bb66c931..afed2debca7 100644 --- a/http/file_handler.hh +++ b/http/file_handler.hh @@ -24,6 +24,8 @@ #include "handlers.hh" +namespace seastar { + namespace httpd { /** * This is a base class for file transformer. @@ -158,4 +160,6 @@ private: } +} + #endif /* HTTP_FILE_HANDLER_HH_ */ diff --git a/http/function_handlers.hh b/http/function_handlers.hh index 3f5fce7ab3a..48e390782a4 100644 --- a/http/function_handlers.hh +++ b/http/function_handlers.hh @@ -25,6 +25,8 @@ #include #include "json/json_elements.hh" +namespace seastar { + namespace httpd { /** @@ -120,3 +122,5 @@ protected: }; } + +} diff --git a/http/handlers.hh b/http/handlers.hh index 9a9888af61d..269aff34044 100644 --- a/http/handlers.hh +++ b/http/handlers.hh @@ -29,6 +29,8 @@ #include +namespace seastar { + namespace httpd { typedef const httpd::request& const_req; @@ -70,4 +72,6 @@ public: } +} + #endif /* HANDLERS_HH_ */ diff --git a/http/http_response_parser.rl b/http/http_response_parser.rl index 832223eeee2..3b109fd025f 100644 --- a/http/http_response_parser.rl +++ b/http/http_response_parser.rl @@ -23,6 +23,8 @@ #include #include +namespace seastar { + struct http_response { sstring _version; std::unordered_map _headers; @@ -127,3 +129,5 @@ public: return _state == state::eof; } }; + +} diff --git a/http/httpd.cc b/http/httpd.cc index 527e57141b0..b15f28eddef 100644 --- a/http/httpd.cc +++ b/http/httpd.cc @@ -39,6 +39,8 @@ using namespace std::chrono_literals; +namespace seastar { + namespace httpd { http_stats::http_stats(http_server& server, const sstring& name) { @@ -60,3 +62,5 @@ sstring http_server_control::generate_server_name() { return seastar::format("http-{}", idgen++); } } + +} diff --git a/http/httpd.hh b/http/httpd.hh index afd55d0224a..750515ba440 100644 --- a/http/httpd.hh +++ b/http/httpd.hh @@ -45,6 +45,8 @@ #include "reply.hh" #include "http/routes.hh" +namespace seastar { + namespace httpd { class http_server; @@ -53,7 +55,7 @@ class http_stats; using namespace std::chrono_literals; class http_stats { - seastar::metrics::metric_groups _metric_groups; + metrics::metric_groups _metric_groups; public: http_stats(http_server& server, const sstring& name); }; @@ -456,4 +458,6 @@ public: } +} + #endif /* APPS_HTTPD_HTTPD_HH_ */ diff --git a/http/json_path.cc b/http/json_path.cc index 695dd859b5e..12721c8a61d 100644 --- a/http/json_path.cc +++ b/http/json_path.cc @@ -21,6 +21,8 @@ #include "json_path.hh" +namespace seastar { + namespace httpd { using namespace std; @@ -66,3 +68,5 @@ path_description::path_description(const sstring& path, operation_type method, } } + +} diff --git a/http/json_path.hh b/http/json_path.hh index 8f234ba0063..456ca2aa751 100644 --- a/http/json_path.hh +++ b/http/json_path.hh @@ -30,6 +30,8 @@ #include "routes.hh" #include "function_handlers.hh" +namespace seastar { + namespace httpd { /** @@ -134,4 +136,7 @@ struct path_description { }; } + +} + #endif /* JSON_PATH_HH_ */ diff --git a/http/matcher.cc b/http/matcher.cc index 8e766c6d65d..3dc706e46c4 100644 --- a/http/matcher.cc +++ b/http/matcher.cc @@ -23,6 +23,8 @@ #include +namespace seastar { + namespace httpd { using namespace std; @@ -68,3 +70,5 @@ size_t str_matcher::match(const sstring& url, size_t ind, parameters& param) { } } + +} diff --git a/http/matcher.hh b/http/matcher.hh index 10d781b928d..a990949b13a 100644 --- a/http/matcher.hh +++ b/http/matcher.hh @@ -26,6 +26,8 @@ #include "core/sstring.hh" +namespace seastar { + namespace httpd { /** @@ -107,4 +109,6 @@ private: } +} + #endif /* MATCHER_HH_ */ diff --git a/http/matchrules.hh b/http/matchrules.hh index f2e575ef5cb..30245f4d183 100644 --- a/http/matchrules.hh +++ b/http/matchrules.hh @@ -29,6 +29,8 @@ #include "core/sstring.hh" #include +namespace seastar { + namespace httpd { /** @@ -115,4 +117,6 @@ private: } +} + #endif /* MATCH_RULES_HH_ */ diff --git a/http/mime_types.cc b/http/mime_types.cc index 3ffc84d7dd2..f516dbc06c1 100644 --- a/http/mime_types.cc +++ b/http/mime_types.cc @@ -10,6 +10,8 @@ #include "mime_types.hh" +namespace seastar { + namespace httpd { namespace mime_types { @@ -43,3 +45,5 @@ const char* extension_to_type(const sstring& extension) } // namespace mime_types } // httpd + +} diff --git a/http/mime_types.hh b/http/mime_types.hh index 7241887de6b..02ce81e47cf 100644 --- a/http/mime_types.hh +++ b/http/mime_types.hh @@ -13,6 +13,8 @@ #include "core/sstring.hh" +namespace seastar { + namespace httpd { namespace mime_types { @@ -29,4 +31,6 @@ const char* extension_to_type(const sstring& extension); } // namespace httpd +} + #endif // HTTP_MIME_TYPES_HH diff --git a/http/reply.cc b/http/reply.cc index dea9c291bf1..6753bc30299 100644 --- a/http/reply.cc +++ b/http/reply.cc @@ -30,6 +30,8 @@ // #include "reply.hh" +namespace seastar { + namespace httpd { namespace status_strings { @@ -96,3 +98,5 @@ sstring reply::response_line() { } } // namespace server + +} diff --git a/http/reply.hh b/http/reply.hh index 4361ba578ee..6d91b6ae4b8 100644 --- a/http/reply.hh +++ b/http/reply.hh @@ -35,6 +35,8 @@ #include #include "http/mime_types.hh" +namespace seastar { + namespace httpd { /** * A reply to be sent to a client. @@ -130,3 +132,5 @@ struct reply { }; } // namespace httpd + +} diff --git a/http/request.hh b/http/request.hh index 2c3417f9153..cef7111b56d 100644 --- a/http/request.hh +++ b/http/request.hh @@ -37,6 +37,8 @@ #include #include "common.hh" +namespace seastar { + namespace httpd { class connection; @@ -116,4 +118,6 @@ struct request { } // namespace httpd +} + #endif // HTTP_REQUEST_HPP diff --git a/http/request_parser.rl b/http/request_parser.rl index b06c82b65b9..91b522bb11d 100644 --- a/http/request_parser.rl +++ b/http/request_parser.rl @@ -26,6 +26,8 @@ #include #include "http/request.hh" +namespace seastar { + using namespace httpd; %% machine request; @@ -137,3 +139,5 @@ public: return _state == state::eof; } }; + +} diff --git a/http/routes.cc b/http/routes.cc index 18d973b5f04..9429d78eae8 100644 --- a/http/routes.cc +++ b/http/routes.cc @@ -23,6 +23,8 @@ #include "reply.hh" #include "exception.hh" +namespace seastar { + namespace httpd { using namespace std; @@ -142,3 +144,5 @@ routes& routes::add(operation_type type, const url& url, } } + +} diff --git a/http/routes.hh b/http/routes.hh index 187b7e960a8..7ac22d7586f 100644 --- a/http/routes.hh +++ b/http/routes.hh @@ -32,6 +32,8 @@ #include #include "core/future-util.hh" +namespace seastar { + namespace httpd { /** @@ -204,4 +206,6 @@ void verify_param(const httpd::request& req, const sstring& param); } +} + #endif /* ROUTES_HH_ */ diff --git a/http/transformers.cc b/http/transformers.cc index a08991a6da3..781e154cb2e 100644 --- a/http/transformers.cc +++ b/http/transformers.cc @@ -23,6 +23,8 @@ #include "transformers.hh" #include +namespace seastar { + namespace httpd { using namespace std; @@ -38,3 +40,5 @@ void content_replace::transform(sstring& content, const request& req, } } + +} diff --git a/http/transformers.hh b/http/transformers.hh index 52a3488c4b7..7db13ef2f1f 100644 --- a/http/transformers.hh +++ b/http/transformers.hh @@ -25,6 +25,8 @@ #include "handlers.hh" #include "file_handler.hh" +namespace seastar { + namespace httpd { /** @@ -54,4 +56,7 @@ private: }; } + +} + #endif /* TRANSFORMERS_HH_ */ diff --git a/json/formatter.cc b/json/formatter.cc index 4862e1ad3a8..532685402fc 100644 --- a/json/formatter.cc +++ b/json/formatter.cc @@ -23,6 +23,8 @@ #include "json_elements.hh" #include +namespace seastar { + using namespace std; namespace json { @@ -102,3 +104,5 @@ sstring formatter::to_json(unsigned long l) { } } + +} diff --git a/json/formatter.hh b/json/formatter.hh index 4d55e258b7c..4b68343fdc7 100644 --- a/json/formatter.hh +++ b/json/formatter.hh @@ -30,6 +30,8 @@ #include #include "core/sstring.hh" +namespace seastar { + namespace json { struct jsonable; @@ -173,5 +175,7 @@ private: }; +} + } #endif /* FORMATTER_HH_ */ diff --git a/json/json2code.py b/json/json2code.py index ec4f90c2c21..a772ca1ae9a 100755 --- a/json/json2code.py +++ b/json/json2code.py @@ -297,6 +297,7 @@ def create_h_file(data, hfile_name, api_name, init_method, base_api): 'json_elements.hh"', '"http/json_path.hh"']) add_include(hfile, ['', '']) + open_namespace(hfile, "seastar") open_namespace(hfile, "httpd") open_namespace(hfile, api_name) @@ -417,6 +418,7 @@ def create_h_file(data, hfile_name, api_name, init_method, base_api): fprintln(hfile, '});') fprintln(hfile, enum_definitions) + close_namespace(hfile) close_namespace(hfile) close_namespace(hfile) hfile.write("#endif //__JSON_AUTO_GENERATED_HEADERS\n") diff --git a/json/json_elements.cc b/json/json_elements.cc index 2274f78d3da..33dba3d42e0 100644 --- a/json/json_elements.cc +++ b/json/json_elements.cc @@ -25,6 +25,8 @@ #include #include +namespace seastar { + using namespace std; namespace json { @@ -111,3 +113,5 @@ bool json_base::is_verify() const { } } + +} diff --git a/json/json_elements.hh b/json/json_elements.hh index 3841fe67e00..4d529eebc85 100644 --- a/json/json_elements.hh +++ b/json/json_elements.hh @@ -29,6 +29,8 @@ #include "formatter.hh" #include "core/sstring.hh" +namespace seastar { + namespace json { /** @@ -264,4 +266,6 @@ struct json_return_type { } +} + #endif /* JSON_ELEMENTS_HH_ */ diff --git a/net/api.hh b/net/api.hh index dd0b509fd8d..b6a2d8d5f7a 100644 --- a/net/api.hh +++ b/net/api.hh @@ -35,6 +35,8 @@ #include #include +namespace seastar { + static inline bool is_ip_unspecified(ipv4_addr &addr) { return addr.ip == 0; @@ -138,8 +140,6 @@ public: } /* namespace net */ -// TODO: remove from global NS - /// \addtogroup networking-module /// @{ @@ -209,29 +209,27 @@ public: /// \addtogroup networking-module /// @{ -namespace seastar { - /// The seastar socket. /// /// A \c socket that allows a connection to be established between /// two endpoints. class socket { - std::unique_ptr<::net::socket_impl> _si; + std::unique_ptr _si; public: ~socket(); /// \cond internal - explicit socket(std::unique_ptr<::net::socket_impl> si); + explicit socket(std::unique_ptr si); /// \endcond /// Moves a \c seastar::socket object. socket(socket&&) noexcept; /// Move-assigns a \c seastar::socket object. - seastar::socket& operator=(seastar::socket&&) noexcept; + socket& operator=(socket&&) noexcept; /// Attempts to establish the connection. /// /// \return a \ref connected_socket representing the connection. - future connect(socket_address sa, socket_address local = socket_address(::sockaddr_in{AF_INET, INADDR_ANY, {0}}), seastar::transport proto = seastar::transport::TCP); + future connect(socket_address sa, socket_address local = socket_address(::sockaddr_in{AF_INET, INADDR_ANY, {0}}), transport proto = transport::TCP); /// Stops any in-flight connection attempt. /// /// Cancels the connection attempt if it's still in progress, and @@ -239,8 +237,6 @@ public: void shutdown(); }; -} /* namespace seastar */ - /// @} /// \addtogroup networking-module @@ -283,15 +279,17 @@ public: virtual ~network_stack() {} virtual server_socket listen(socket_address sa, listen_options opts) = 0; // FIXME: local parameter assumes ipv4 for now, fix when adding other AF - future connect(socket_address sa, socket_address local = socket_address(::sockaddr_in{AF_INET, INADDR_ANY, {0}}), seastar::transport proto = seastar::transport::TCP) { + future connect(socket_address sa, socket_address local = socket_address(::sockaddr_in{AF_INET, INADDR_ANY, {0}}), transport proto = transport::TCP) { return socket().connect(sa, local, proto); } - virtual seastar::socket socket() = 0; - virtual ::net::udp_channel make_udp_channel(ipv4_addr addr = {}) = 0; + virtual ::seastar::socket socket() = 0; + virtual net::udp_channel make_udp_channel(ipv4_addr addr = {}) = 0; virtual future<> initialize() { return make_ready_future(); } virtual bool has_per_core_namespace() = 0; }; +} + #endif diff --git a/net/arp.cc b/net/arp.cc index 84b74cef490..9b8dc86a234 100644 --- a/net/arp.cc +++ b/net/arp.cc @@ -21,6 +21,8 @@ #include "arp.hh" +namespace seastar { + namespace net { arp_for_protocol::arp_for_protocol(arp& a, uint16_t proto_num) @@ -82,3 +84,5 @@ arp::process_packet(packet p, ethernet_address from) { } } + +} diff --git a/net/arp.hh b/net/arp.hh index 2cf72f1fb8a..d8bad451c13 100644 --- a/net/arp.hh +++ b/net/arp.hh @@ -30,6 +30,8 @@ #include "core/print.hh" #include +namespace seastar { + namespace net { class arp; @@ -293,4 +295,6 @@ arp_for::handle_request(arp_hdr* ah) { } +} + #endif /* ARP_HH_ */ diff --git a/net/byteorder.hh b/net/byteorder.hh index 52f29f76b94..8a89e9c5319 100644 --- a/net/byteorder.hh +++ b/net/byteorder.hh @@ -28,6 +28,8 @@ #include "core/unaligned.hh" +namespace seastar { + inline uint64_t ntohq(uint64_t v) { return __builtin_bswap64(v); } @@ -117,4 +119,6 @@ T hton(const T& x) { } +} + #endif /* BYTEORDER_HH_ */ diff --git a/net/const.hh b/net/const.hh index 0b9dcaead5d..44b166e25d7 100644 --- a/net/const.hh +++ b/net/const.hh @@ -21,6 +21,9 @@ #ifndef CONST_HH_ #define CONST_HH_ + +namespace seastar { + namespace net { enum class ip_protocol_num : uint8_t { @@ -38,4 +41,7 @@ const uint8_t ipv6_hdr_len_min = 40; const uint16_t ip_packet_len_max = 65535; } + +} + #endif diff --git a/net/dhcp.cc b/net/dhcp.cc index 443e5a4feeb..f13409135ef 100644 --- a/net/dhcp.cc +++ b/net/dhcp.cc @@ -29,6 +29,8 @@ #include "udp.hh" #include "stack.hh" +namespace seastar { + using namespace std::literals::chrono_literals; class net::dhcp::impl : public ip_packet_filter { @@ -465,3 +467,5 @@ net::dhcp::result_type net::dhcp::renew(const lease & l, const steady_clock_type net::ip_packet_filter* net::dhcp::get_ipv4_filter() { return _impl.get(); } + +} diff --git a/net/dhcp.hh b/net/dhcp.hh index 9e79a23b261..1f2eaf58b81 100644 --- a/net/dhcp.hh +++ b/net/dhcp.hh @@ -25,6 +25,8 @@ #include "ip.hh" #include "core/reactor.hh" +namespace seastar { + namespace net { /* @@ -80,4 +82,6 @@ private: } +} + #endif /* NET_DHCP_HH_ */ diff --git a/net/dns.cc b/net/dns.cc index 58b51aa755a..716613e951b 100644 --- a/net/dns.cc +++ b/net/dns.cc @@ -33,7 +33,9 @@ #include "core/gate.hh" #include "util/log.hh" -static seastar::logger dns_log("dns_resolver"); +namespace seastar { + +static logger dns_log("dns_resolver"); class ares_error_category : public std::error_category { public: @@ -103,11 +105,11 @@ struct ares_initializer { } }; -class seastar::net::dns_resolver::impl +class net::dns_resolver::impl : public enable_shared_from_this { public: - impl(::network_stack& stack, const options& opts) + impl(network_stack& stack, const options& opts) : _stack(stack) , _timeout(opts.timeout ? *opts.timeout : std::chrono::milliseconds(5000) /* from ares private */) , _timer(std::bind(&impl::poll_sockets, this)) @@ -188,7 +190,7 @@ class seastar::net::dns_resolver::impl ares_set_socket_functions(_channel, &callbacks, this); // just in case you need printf-debug. - // dns_log.set_level(seastar::log_level::trace); + // dns_log.set_level(log_level::trace); } ~impl() { _timer.cancel(); @@ -619,7 +621,7 @@ class seastar::net::dns_resolver::impl e.avail &= ~POLLIN; use(fd); dns_log.trace("Read {}: data unavailable", fd); - f.then_wrapped([me = shared_from_this(), &e, fd](future<::net::udp_datagram> f) { + f.then_wrapped([me = shared_from_this(), &e, fd](future f) { try { auto d = f.get0(); dns_log.trace("Read {} -> {} bytes", fd, d.get_data().len()); @@ -687,10 +689,10 @@ class seastar::net::dns_resolver::impl return -1; } - ::net::packet p; + net::packet p; p.reserve(len); for (int i = 0; i < len; ++i) { - p = ::net::packet(std::move(p), ::net::fragment{reinterpret_cast(vec[i].iov_base), vec[i].iov_len}); + p = net::packet(std::move(p), net::fragment{reinterpret_cast(vec[i].iov_base), vec[i].iov_len}); } auto bytes = p.len(); @@ -771,11 +773,11 @@ class seastar::net::dns_resolver::impl temporary_buffer indata; }; struct udp_entry { - udp_entry(::net::udp_channel c) + udp_entry(net::udp_channel c) : channel(std::move(c)) { } - ::net::udp_channel channel; - std::experimental::optional<::net::udp_datagram> in;; + net::udp_channel channel; + std::experimental::optional in;; socket_address dst; }; struct sock_entry { @@ -808,7 +810,7 @@ class seastar::net::dns_resolver::impl : tcp(tcp_entry{std::move(s)}) , typ(type::tcp) {} - sock_entry(::net::udp_channel c) + sock_entry(net::udp_channel c) : udp(udp_entry{std::move(c)}) , typ(type::udp) {} @@ -835,7 +837,7 @@ class seastar::net::dns_resolver::impl friend struct dns_call; socket_map _sockets; - ::network_stack & _stack; + network_stack & _stack; ares_channel _channel = {}; uint64_t _ops = 0, _calls = 0; @@ -845,97 +847,99 @@ class seastar::net::dns_resolver::impl bool _closed = false; }; -seastar::net::dns_resolver::dns_resolver() +net::dns_resolver::dns_resolver() : dns_resolver(options()) {} -seastar::net::dns_resolver::dns_resolver(const options& opts) +net::dns_resolver::dns_resolver(const options& opts) : dns_resolver(engine().net(), opts) {} -seastar::net::dns_resolver::dns_resolver(network_stack& stack, const options& opts) - : _impl(::make_shared(stack, opts)) +net::dns_resolver::dns_resolver(network_stack& stack, const options& opts) + : _impl(make_shared(stack, opts)) {} -seastar::net::dns_resolver::~dns_resolver() +net::dns_resolver::~dns_resolver() {} -seastar::net::dns_resolver::dns_resolver(dns_resolver&&) noexcept = default; -seastar::net::dns_resolver& seastar::net::dns_resolver::operator=(dns_resolver&&) noexcept = default; +net::dns_resolver::dns_resolver(dns_resolver&&) noexcept = default; +net::dns_resolver& net::dns_resolver::operator=(dns_resolver&&) noexcept = default; -future seastar::net::dns_resolver::get_host_by_name(const sstring& name, opt_family family) { +future net::dns_resolver::get_host_by_name(const sstring& name, opt_family family) { return _impl->get_host_by_name(name, family.value_or(inet_address::family::INET)); } -future seastar::net::dns_resolver::get_host_by_addr(const inet_address& addr) { +future net::dns_resolver::get_host_by_addr(const inet_address& addr) { return _impl->get_host_by_addr(addr); } -future seastar::net::dns_resolver::resolve_name(const sstring& name, opt_family family) { +future net::dns_resolver::resolve_name(const sstring& name, opt_family family) { return _impl->resolve_name(name, family.value_or(inet_address::family::INET)); } -future seastar::net::dns_resolver::resolve_addr(const inet_address& addr) { +future net::dns_resolver::resolve_addr(const inet_address& addr) { return _impl->resolve_addr(addr); } -future<> seastar::net::dns_resolver::close() { +future<> net::dns_resolver::close() { return _impl->close(); } -static seastar::net::dns_resolver& resolver() { - static thread_local seastar::net::dns_resolver resolver; +static net::dns_resolver& resolver() { + static thread_local net::dns_resolver resolver; return resolver; } -future seastar::net::dns::get_host_by_name(const sstring& name, opt_family family) { +future net::dns::get_host_by_name(const sstring& name, opt_family family) { return resolver().get_host_by_name(name, family.value_or(inet_address::family::INET)); } -future seastar::net::dns::get_host_by_addr(const inet_address& addr) { +future net::dns::get_host_by_addr(const inet_address& addr) { return resolver().get_host_by_addr(addr); } -future seastar::net::dns::resolve_name(const sstring& name, opt_family family) { +future net::dns::resolve_name(const sstring& name, opt_family family) { return resolver().resolve_name(name, family.value_or(inet_address::family::INET)); } -future seastar::net::dns::resolve_addr(const inet_address& addr) { +future net::dns::resolve_addr(const inet_address& addr) { return resolver().resolve_addr(addr); } -future seastar::net::inet_address::hostname() const { +future net::inet_address::hostname() const { return dns::resolve_addr(*this); } -future> seastar::net::inet_address::aliases() const { +future> net::inet_address::aliases() const { return dns::get_host_by_addr(*this).then([](hostent e) { return make_ready_future>(std::move(e.names)); }); } -future seastar::net::inet_address::find( +future net::inet_address::find( const sstring& name) { return dns::resolve_name(name); } -future seastar::net::inet_address::find( +future net::inet_address::find( const sstring& name, family f) { return dns::resolve_name(name, f); } -future> seastar::net::inet_address::find_all( +future> net::inet_address::find_all( const sstring& name) { return dns::get_host_by_name(name).then([](hostent e) { - return make_ready_future>(std::move(e.addr_list)); + return make_ready_future>(std::move(e.addr_list)); }); } -future> seastar::net::inet_address::find_all( +future> net::inet_address::find_all( const sstring& name, family f) { return dns::get_host_by_name(name, f).then([](hostent e) { - return make_ready_future>(std::move(e.addr_list)); + return make_ready_future>(std::move(e.addr_list)); }); } +} + diff --git a/net/dns.hh b/net/dns.hh index fdf402736cb..096b035e83f 100644 --- a/net/dns.hh +++ b/net/dns.hh @@ -31,6 +31,8 @@ #include "../core/shared_ptr.hh" #include "inet_address.hh" +namespace seastar { + struct ipv4_addr; class socket_address; @@ -42,7 +44,6 @@ class network_stack; * */ -namespace seastar { namespace net { /** @@ -83,7 +84,7 @@ public: dns_resolver(); dns_resolver(dns_resolver&&) noexcept; explicit dns_resolver(const options&); - explicit dns_resolver(::network_stack&, const options& = {}); + explicit dns_resolver(network_stack&, const options& = {}); ~dns_resolver(); dns_resolver& operator=(dns_resolver&&) noexcept; @@ -112,7 +113,7 @@ public: future<> close(); private: class impl; - ::shared_ptr _impl; + shared_ptr _impl; }; namespace dns { @@ -128,4 +129,5 @@ future resolve_addr(const inet_address&); } } + } diff --git a/net/dpdk.cc b/net/dpdk.cc index fa2937accc1..a5a4a24e5c1 100644 --- a/net/dpdk.cc +++ b/net/dpdk.cc @@ -83,6 +83,8 @@ typedef void *MARKER[0]; /**< generic marker for a point in a structure */ using namespace net; +namespace seastar { + namespace dpdk { /******************* Net device related constatns *****************************/ @@ -2303,4 +2305,6 @@ get_dpdk_net_options_description() return opts; } +} + #endif // HAVE_DPDK diff --git a/net/dpdk.hh b/net/dpdk.hh index 25484f1f543..d9c2630b87c 100644 --- a/net/dpdk.hh +++ b/net/dpdk.hh @@ -28,6 +28,8 @@ #include "net.hh" #include "core/sstring.hh" +namespace seastar { + std::unique_ptr create_dpdk_net_device( uint8_t port_idx = 0, uint8_t num_queues = 1, @@ -43,6 +45,8 @@ namespace dpdk { uint32_t qp_mempool_obj_size(bool hugetlbfs_membackend); } +} + #endif // _SEASTAR_DPDK_DEV_H #endif // HAVE_DPDK diff --git a/net/ethernet.cc b/net/ethernet.cc index 2cedccefe7f..c1dfa3991d0 100644 --- a/net/ethernet.cc +++ b/net/ethernet.cc @@ -23,6 +23,8 @@ #include #include +namespace seastar { + namespace net { std::ostream& operator<<(std::ostream& os, ethernet_address ea) { @@ -50,5 +52,5 @@ ethernet_address parse_ethernet_address(std::string addr) } } - +} diff --git a/net/ethernet.hh b/net/ethernet.hh index 595b80340d3..748cfd64ca0 100644 --- a/net/ethernet.hh +++ b/net/ethernet.hh @@ -26,6 +26,8 @@ #include "byteorder.hh" #include "core/print.hh" +namespace seastar { + namespace net { struct ethernet_address { @@ -90,4 +92,6 @@ struct eth_hdr { ethernet_address parse_ethernet_address(std::string addr); } +} + #endif /* ETHERNET_HH_ */ diff --git a/net/inet_address.cc b/net/inet_address.cc index 807cc3bb055..9ae38d271bb 100644 --- a/net/inet_address.cc +++ b/net/inet_address.cc @@ -26,6 +26,8 @@ #include "socket_defs.hh" #include "dns.hh" +namespace seastar { + seastar::net::inet_address::inet_address() : inet_address(::in_addr{ 0, }) {} @@ -122,3 +124,6 @@ std::ostream& operator<<(std::ostream& os, const socket_address& a) { << ":" << a.u.in.sin_port ; } + +} + diff --git a/net/ip.cc b/net/ip.cc index 9e463eb2232..e676c130cd4 100644 --- a/net/ip.cc +++ b/net/ip.cc @@ -27,6 +27,8 @@ #include "toeplitz.hh" #include "core/metrics.hh" +namespace seastar { + namespace net { std::ostream& operator<<(std::ostream& os, ipv4_address a) { @@ -474,3 +476,5 @@ void icmp::received(packet p, ipaddr from, ipaddr to) { } } + +} diff --git a/net/ip.hh b/net/ip.hh index e9f97a33d1b..cd18b5f2289 100644 --- a/net/ip.hh +++ b/net/ip.hh @@ -43,6 +43,8 @@ #include "net/udp.hh" #include "core/metrics_registration.hh" +namespace seastar { + namespace net { class ipv4; @@ -108,15 +110,19 @@ std::ostream& operator<<(std::ostream& os, ipv4_address a); } +} + namespace std { template <> -struct hash { - size_t operator()(net::ipv4_address a) const { return a.ip; } +struct hash { + size_t operator()(seastar::net::ipv4_address a) const { return a.ip; } }; } +namespace seastar { + namespace net { struct ipv4_traits { @@ -363,7 +369,7 @@ private: timer _frag_timer; circular_buffer _packetq; unsigned _pkt_provider_idx = 0; - seastar::metrics::metric_groups _metrics; + metrics::metric_groups _metrics; private: future<> handle_received_packet(packet p, ethernet_address from); bool forward(forward_hash& out_hash_data, packet& p, size_t off); @@ -400,8 +406,8 @@ public: tcp& get_tcp() { return *_tcp._tcp; } ipv4_udp& get_udp() { return _udp; } void register_l4(proto_type id, ip_protocol* handler); - const ::net::hw_features& hw_features() const { return _netif->hw_features(); } - static bool needs_frag(packet& p, ip_protocol_num proto_num, ::net::hw_features hw_features); + const net::hw_features& hw_features() const { return _netif->hw_features(); } + static bool needs_frag(packet& p, ip_protocol_num proto_num, net::hw_features hw_features); void learn(ethernet_address l2, ipv4_address l3) { _arp.learn(l2, l3); } @@ -469,4 +475,6 @@ void arp_learn(ethernet_address l2, ipv4_address l3); } +} + #endif /* IP_HH_ */ diff --git a/net/ip_checksum.cc b/net/ip_checksum.cc index 3652d063f86..3bee20adeec 100644 --- a/net/ip_checksum.cc +++ b/net/ip_checksum.cc @@ -23,6 +23,8 @@ #include "net.hh" #include +namespace seastar { + namespace net { void checksummer::sum(const char* data, size_t len) { @@ -71,4 +73,6 @@ uint16_t ip_checksum(const void* data, size_t len) { } +} + } diff --git a/net/ip_checksum.hh b/net/ip_checksum.hh index 827f7b24ad5..bf388f8386a 100644 --- a/net/ip_checksum.hh +++ b/net/ip_checksum.hh @@ -27,6 +27,8 @@ #include #include +namespace seastar { + namespace net { uint16_t ip_checksum(const void* data, size_t len); @@ -71,4 +73,6 @@ struct checksummer { } +} + #endif /* IP_CHECKSUM_HH_ */ diff --git a/net/native-stack-impl.hh b/net/native-stack-impl.hh index 2934cd69cac..13167f5e52a 100644 --- a/net/native-stack-impl.hh +++ b/net/native-stack-impl.hh @@ -25,6 +25,8 @@ #include "core/reactor.hh" #include "stack.hh" +namespace seastar { + namespace net { using namespace seastar; @@ -229,6 +231,6 @@ keepalive_params native_connected_socket_impl::get_keepalive_parameter } - +} #endif /* NET_NATIVE_STACK_IMPL_HH_ */ diff --git a/net/native-stack.cc b/net/native-stack.cc index 756a4c0f4ce..05c7430554e 100644 --- a/net/native-stack.cc +++ b/net/native-stack.cc @@ -41,6 +41,8 @@ #include #include +namespace seastar { + namespace net { using namespace seastar; @@ -221,12 +223,12 @@ future<> native_network_stack::run_dhcp(bool is_renew, const dhcp::lease& res) { auto & ns = static_cast(engine().net()); ns.set_ipv4_packet_filter(f); }).then([this, d = std::move(d), is_renew, res]() mutable { - ::net::dhcp::result_type fut = is_renew ? d.renew(res) : d.discover(); + net::dhcp::result_type fut = is_renew ? d.renew(res) : d.discover(); return fut.then([this, is_renew](bool success, const dhcp::lease & res) { return smp::invoke_on_all([] { auto & ns = static_cast(engine().net()); ns.set_ipv4_packet_filter(nullptr); - }).then(std::bind(&::net::native_network_stack::on_dhcp, this, success, res, is_renew)); + }).then(std::bind(&net::native_network_stack::on_dhcp, this, success, res, is_renew)); }).finally([d = std::move(d)] {}); }); } @@ -336,3 +338,5 @@ network_stack_registrator nns_registrator{ }; } + +} diff --git a/net/native-stack.hh b/net/native-stack.hh index 19646a9d68f..c90140832d4 100644 --- a/net/native-stack.hh +++ b/net/native-stack.hh @@ -25,10 +25,14 @@ #include "net/net.hh" #include +namespace seastar { + namespace net { void create_native_stack(boost::program_options::variables_map opts, std::shared_ptr dev); } +} + #endif /* STACK_HH_ */ diff --git a/net/net.cc b/net/net.cc index 554d85923a0..a0ff4fc692e 100644 --- a/net/net.cc +++ b/net/net.cc @@ -28,6 +28,8 @@ #include "core/metrics.hh" #include "inet_address.hh" +namespace seastar { + using std::move; ipv4_addr::ipv4_addr(const std::string &addr) { @@ -46,10 +48,10 @@ ipv4_addr::ipv4_addr(const std::string &addr) { ipv4_addr::ipv4_addr(const std::string &addr, uint16_t port_) : ip(boost::asio::ip::address_v4::from_string(addr).to_ulong()), port(port_) {} -ipv4_addr::ipv4_addr(const seastar::net::inet_address& a, uint16_t port) +ipv4_addr::ipv4_addr(const net::inet_address& a, uint16_t port) : ipv4_addr([&a] { ::in_addr in = a; - return ::net::ntoh(in.s_addr); + return net::ntoh(in.s_addr); }(), port) {} @@ -88,7 +90,7 @@ qp::qp(bool register_copy_stats, , _stats_plugin_name(stats_plugin_name) , _queue_name(std::string("queue") + std::to_string(qid)) { - namespace sm = seastar::metrics; + namespace sm = metrics; _metrics.add_group(_stats_plugin_name, { // @@ -126,7 +128,7 @@ qp::qp(bool register_copy_stats, // // Tx sm::make_gauge(_queue_name + "_tx_packet_queue_last_bunch", _stats.tx.good.last_bunch, - sm::description(seastar::format("Holds a number of packets sent in the bunch. " + sm::description(format("Holds a number of packets sent in the bunch. " "A high value in conjunction with a high value of a {} indicates an efficient Tx packets bulking.", _queue_name + "_tx_packet_queue"))), // Rx sm::make_gauge(_queue_name + "_rx_packet_queue_last_bunch", _stats.rx.good.last_bunch, @@ -137,10 +139,10 @@ qp::qp(bool register_copy_stats, // // Tx sm::make_derive(_queue_name + "_tx_frags", _stats.tx.good.nr_frags, - sm::description(seastar::format("Counts a number of sent fragments. Divide this value by a {} to get an average number of fragments in a Tx packet.", _queue_name + "_tx_packets"))), + sm::description(format("Counts a number of sent fragments. Divide this value by a {} to get an average number of fragments in a Tx packet.", _queue_name + "_tx_packets"))), // Rx sm::make_derive(_queue_name + "_rx_frags", _stats.rx.good.nr_frags, - sm::description(seastar::format("Counts a number of received fragments. Divide this value by a {} to get an average number of fragments in an Rx packet.", _queue_name + "_rx_packets"))), + sm::description(format("Counts a number of received fragments. Divide this value by a {} to get an average number of fragments in an Rx packet.", _queue_name + "_rx_packets"))), }); if (register_copy_stats) { @@ -150,20 +152,20 @@ qp::qp(bool register_copy_stats, // // Tx sm::make_derive(_queue_name + "_tx_copy_bytes", _stats.tx.good.copy_bytes, - sm::description(seastar::format("Counts a number of sent bytes that were handled in a non-zero-copy way. Divide this value by a {} to get a portion of data sent using a non-zero-copy flow.", _queue_name + "_tx_bytes"))), + sm::description(format("Counts a number of sent bytes that were handled in a non-zero-copy way. Divide this value by a {} to get a portion of data sent using a non-zero-copy flow.", _queue_name + "_tx_bytes"))), // Rx sm::make_derive(_queue_name + "_rx_copy_bytes", _stats.rx.good.copy_bytes, - sm::description(seastar::format("Counts a number of received bytes that were handled in a non-zero-copy way. Divide this value by an {} to get a portion of received data handled using a non-zero-copy flow.", _queue_name + "_rx_bytes"))), + sm::description(format("Counts a number of received bytes that were handled in a non-zero-copy way. Divide this value by an {} to get a portion of received data handled using a non-zero-copy flow.", _queue_name + "_rx_bytes"))), // // Non-zero-copy data fragments rate: DERIVE:0:u // // Tx sm::make_derive(_queue_name + "_tx_copy_frags", _stats.tx.good.copy_frags, - sm::description(seastar::format("Counts a number of sent fragments that were handled in a non-zero-copy way. Divide this value by a {} to get a portion of fragments sent using a non-zero-copy flow.", _queue_name + "_tx_frags"))), + sm::description(format("Counts a number of sent fragments that were handled in a non-zero-copy way. Divide this value by a {} to get a portion of fragments sent using a non-zero-copy flow.", _queue_name + "_tx_frags"))), // Rx sm::make_derive(_queue_name + "_rx_copy_frags", _stats.rx.good.copy_frags, - sm::description(seastar::format("Counts a number of received fragments that were handled in a non-zero-copy way. Divide this value by a {} to get a portion of received fragments handled using a non-zero-copy flow.", _queue_name + "_rx_frags"))), + sm::description(format("Counts a number of received fragments that were handled in a non-zero-copy way. Divide this value by a {} to get a portion of received fragments handled using a non-zero-copy flow.", _queue_name + "_rx_frags"))), }); } @@ -331,3 +333,5 @@ future<> interface::dispatch_packet(packet p) { } } + +} diff --git a/net/net.hh b/net/net.hh index 5ee3ebe7e28..c97552754b9 100644 --- a/net/net.hh +++ b/net/net.hh @@ -33,6 +33,8 @@ #include "const.hh" #include +namespace seastar { + namespace net { class packet; @@ -115,14 +117,14 @@ class interface { std::shared_ptr _dev; subscription _rx; ethernet_address _hw_address; - ::net::hw_features _hw_features; + net::hw_features _hw_features; std::vector _pkt_providers; private: future<> dispatch_packet(packet p); public: explicit interface(std::shared_ptr dev); ethernet_address hw_address() { return _hw_address; } - const ::net::hw_features& hw_features() const { return _hw_features; } + const net::hw_features& hw_features() const { return _hw_features; } subscription register_l3(eth_protocol_num proto_num, std::function (packet p, ethernet_address from)> next, std::function forward); @@ -221,7 +223,7 @@ class qp { protected: const std::string _stats_plugin_name; const std::string _queue_name; - seastar::metrics::metric_groups _metrics; + metrics::metric_groups _metrics; qp_stats _stats; public: @@ -267,7 +269,7 @@ public: void l2receive(packet p) { _queues[engine().cpu_id()]->_rx_stream.produce(std::move(p)); } subscription receive(std::function (packet)> next_packet); virtual ethernet_address hw_address() = 0; - virtual ::net::hw_features hw_features() = 0; + virtual net::hw_features hw_features() = 0; virtual const rss_key_type& rss_key() const { return default_rsskey_40bytes; } virtual uint16_t hw_queues_count() { return 1; } virtual future<> link_ready() { return make_ready_future<>(); } @@ -295,4 +297,6 @@ public: } +} + #endif /* NET_HH_ */ diff --git a/net/packet-data-source.hh b/net/packet-data-source.hh index 6b7593f9e8e..a055205b0b2 100644 --- a/net/packet-data-source.hh +++ b/net/packet-data-source.hh @@ -21,6 +21,8 @@ #include "core/reactor.hh" #include "net/packet.hh" +namespace seastar { + namespace net { class packet_data_source final : public data_source_impl { @@ -49,4 +51,6 @@ input_stream as_input_stream(packet&& p) { } +} + #endif diff --git a/net/packet-util.hh b/net/packet-util.hh index 0ca8bee8dd7..96291e74842 100644 --- a/net/packet-util.hh +++ b/net/packet-util.hh @@ -26,6 +26,8 @@ #include #include +namespace seastar { + namespace net { template @@ -153,4 +155,7 @@ public: }; } + +} + #endif diff --git a/net/packet.cc b/net/packet.cc index 090d10175fc..312e070bca8 100644 --- a/net/packet.cc +++ b/net/packet.cc @@ -25,6 +25,8 @@ #include #include +namespace seastar { + namespace net { constexpr size_t packet::internal_data_size; @@ -120,3 +122,5 @@ std::ostream& operator<<(std::ostream& os, const packet& p) { } } + +} diff --git a/net/packet.hh b/net/packet.hh index 1f0380664f2..4e81febfb13 100644 --- a/net/packet.hh +++ b/net/packet.hh @@ -32,6 +32,8 @@ #include #include +namespace seastar { + namespace net { struct fragment { @@ -617,4 +619,6 @@ packet packet::share(size_t offset, size_t len) { } +} + #endif /* PACKET_HH_ */ diff --git a/net/posix-stack.cc b/net/posix-stack.cc index 335cafdcbab..8b4d8c1647b 100644 --- a/net/posix-stack.cc +++ b/net/posix-stack.cc @@ -26,6 +26,8 @@ #include #include +namespace seastar { + namespace net { using namespace seastar; @@ -490,3 +492,5 @@ posix_udp_channel::receive() { } } + +} diff --git a/net/posix-stack.hh b/net/posix-stack.hh index 059ae791b9c..4a2e0db53b7 100644 --- a/net/posix-stack.hh +++ b/net/posix-stack.hh @@ -26,6 +26,8 @@ #include "stack.hh" #include +namespace seastar { + namespace net { using namespace seastar; @@ -101,7 +103,7 @@ public: explicit posix_network_stack(boost::program_options::variables_map opts) : _reuseport(engine().posix_reuseport_available()) {} virtual server_socket listen(socket_address sa, listen_options opts) override; virtual ::seastar::socket socket() override; - virtual ::net::udp_channel make_udp_channel(ipv4_addr addr) override; + virtual net::udp_channel make_udp_channel(ipv4_addr addr) override; static future> create(boost::program_options::variables_map opts) { return make_ready_future>(std::unique_ptr(new posix_network_stack(opts))); } @@ -121,4 +123,6 @@ public: } +} + #endif diff --git a/net/proxy.cc b/net/proxy.cc index d719bbb0b11..32ef9c72aa1 100644 --- a/net/proxy.cc +++ b/net/proxy.cc @@ -19,6 +19,8 @@ #include "proxy.hh" #include +namespace seastar { + namespace net { class proxy_net_device : public qp { @@ -73,3 +75,5 @@ std::unique_ptr create_proxy_net_device(unsigned master_cpu, device* dev) { return std::make_unique(master_cpu, dev); } } + +} diff --git a/net/proxy.hh b/net/proxy.hh index 1fdb24186fe..a3fd86f9b2f 100644 --- a/net/proxy.hh +++ b/net/proxy.hh @@ -22,9 +22,14 @@ #include "net.hh" #include "packet.hh" +namespace seastar { + namespace net { std::unique_ptr create_proxy_net_device(unsigned master_cpu, device* dev); } + +} + #endif diff --git a/net/socket_defs.hh b/net/socket_defs.hh index a274a246e35..0822ee08a1a 100644 --- a/net/socket_defs.hh +++ b/net/socket_defs.hh @@ -25,6 +25,8 @@ #include #include "net/byteorder.hh" +namespace seastar { + struct ipv4_addr; class socket_address { @@ -49,8 +51,6 @@ public: std::ostream& operator<<(std::ostream&, const socket_address&); -namespace seastar { - enum class transport { TCP = IPPROTO_TCP, SCTP = IPPROTO_SCTP @@ -61,10 +61,8 @@ namespace net { class inet_address; } -} - struct listen_options { - seastar::transport proto = seastar::transport::TCP; + transport proto = transport::TCP; bool reuse_address = false; listen_options(bool rua = false) : reuse_address(rua) @@ -80,7 +78,7 @@ struct ipv4_addr { ipv4_addr(uint16_t port) : ip(0), port(port) {} ipv4_addr(const std::string &addr); ipv4_addr(const std::string &addr, uint16_t port); - ipv4_addr(const seastar::net::inet_address&, uint16_t); + ipv4_addr(const net::inet_address&, uint16_t); ipv4_addr(const socket_address &sa) { ip = net::ntoh(sa.u.in.sin_addr.s_addr); @@ -89,3 +87,5 @@ struct ipv4_addr { ipv4_addr(socket_address &&sa) : ipv4_addr(sa) {} }; + +} diff --git a/net/stack.cc b/net/stack.cc index 33a2d0a2a4b..290aabf6483 100644 --- a/net/stack.cc +++ b/net/stack.cc @@ -22,6 +22,8 @@ #include "stack.hh" #include "core/reactor.hh" +namespace seastar { + net::udp_channel::udp_channel() {} @@ -105,22 +107,22 @@ void connected_socket::shutdown_input() { _csi->shutdown_input(); } -seastar::socket::~socket() +socket::~socket() {} -seastar::socket::socket( - std::unique_ptr<::net::socket_impl> si) +socket::socket( + std::unique_ptr si) : _si(std::move(si)) { } -seastar::socket::socket(seastar::socket&&) noexcept = default; -seastar::socket& seastar::socket::operator=(seastar::socket&&) noexcept = default; +socket::socket(socket&&) noexcept = default; +socket& socket::operator=(socket&&) noexcept = default; -future seastar::socket::connect(socket_address sa, socket_address local, transport proto) { +future socket::connect(socket_address sa, socket_address local, transport proto) { return _si->connect(sa, local, proto); } -void seastar::socket::shutdown() { +void socket::shutdown() { _si->shutdown(); } @@ -156,4 +158,4 @@ bool socket_address::operator==(const socket_address& a) const { a.u.in.sin_addr.s_addr); } - +} diff --git a/net/stack.hh b/net/stack.hh index d4299a868f9..c5e5158a227 100644 --- a/net/stack.hh +++ b/net/stack.hh @@ -23,6 +23,8 @@ #include #include "api.hh" +namespace seastar { + namespace net { /// \cond internal @@ -44,7 +46,7 @@ public: class socket_impl { public: virtual ~socket_impl() {} - virtual future connect(socket_address sa, socket_address local, seastar::transport proto = seastar::transport::TCP) = 0; + virtual future connect(socket_address sa, socket_address local, transport proto = transport::TCP) = 0; virtual void shutdown() = 0; }; @@ -69,3 +71,4 @@ public: } +} diff --git a/net/tcp-stack.hh b/net/tcp-stack.hh index 441e9179a83..2b193f90601 100644 --- a/net/tcp-stack.hh +++ b/net/tcp-stack.hh @@ -26,6 +26,8 @@ #include "core/future.hh" +namespace seastar { + class listen_options; class server_socket; class connected_socket; @@ -44,4 +46,6 @@ tcpv4_socket(tcp& tcpv4); } +} + #endif diff --git a/net/tcp.cc b/net/tcp.cc index 91471eab1b3..8d0edcb829c 100644 --- a/net/tcp.cc +++ b/net/tcp.cc @@ -26,6 +26,8 @@ #include "core/future.hh" #include "native-stack-impl.hh" +namespace seastar { + namespace net { void tcp_option::parse(uint8_t* beg1, uint8_t* end1) { @@ -164,3 +166,4 @@ tcpv4_socket(tcp& tcpv4) { } +} diff --git a/net/tcp.hh b/net/tcp.hh index bca50b91f65..fddc98c4f04 100644 --- a/net/tcp.hh +++ b/net/tcp.hh @@ -46,6 +46,8 @@ #define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1 #include +namespace seastar { + using namespace std::chrono_literals; namespace net { @@ -520,7 +522,7 @@ private: return size; } uint16_t local_mss() { - return _tcp.hw_features().mtu - ::net::tcp_hdr_len_min - InetTraits::ip_hdr_len_min; + return _tcp.hw_features().mtu - net::tcp_hdr_len_min - InetTraits::ip_hdr_len_min; } void queue_packet(packet p) { _packetq.emplace_back(typename InetTraits::l4packet{_foreign_ip, std::move(p)}); @@ -631,7 +633,7 @@ private: // queue for packets that do not belong to any tcb circular_buffer _packetq; semaphore _queue_space = {212992}; - seastar::metrics::metric_groups _metrics; + metrics::metric_groups _metrics; public: class connection { lw_shared_ptr _tcb; @@ -712,7 +714,7 @@ public: bool forward(forward_hash& out_hash_data, packet& p, size_t off); listener listen(uint16_t port, size_t queue_length = 100); connection connect(socket_address sa); - const ::net::hw_features& hw_features() const { return _inet._inet.hw_features(); } + const net::hw_features& hw_features() const { return _inet._inet.hw_features(); } future<> poll_tcb(ipaddr to, lw_shared_ptr tcb); void add_connected_tcb(lw_shared_ptr tcbp, uint16_t local_port) { auto it = _listening.find(local_port); @@ -731,7 +733,7 @@ template tcp::tcp(inet_type& inet) : _inet(inet) , _e(_rd()) { - namespace sm = seastar::metrics; + namespace sm = metrics; _metrics.add_group("tcp", { sm::make_derive("linearizations", [] { return tcp_packet_merger::linearizations(); }, @@ -782,7 +784,7 @@ auto tcp::connect(socket_address sa) -> connection { connid id; auto src_ip = _inet._inet.host_address(); auto dst_ip = ipv4_address(sa); - auto dst_port = ::net::ntoh(sa.u.in.sin_port); + auto dst_port = net::ntoh(sa.u.in.sin_port); do { src_port = _port_dist(_e); @@ -1524,9 +1526,9 @@ packet tcp::tcb::get_transmit_packet() { uint32_t len; if (_tcp.hw_features().tx_tso) { // FIXME: Info tap device the size of the splitted packet - len = _tcp.hw_features().max_packet_len - ::net::tcp_hdr_len_min - InetTraits::ip_hdr_len_min; + len = _tcp.hw_features().max_packet_len - net::tcp_hdr_len_min - InetTraits::ip_hdr_len_min; } else { - len = std::min(uint16_t(_tcp.hw_features().mtu - ::net::tcp_hdr_len_min - InetTraits::ip_hdr_len_min), _snd.mss); + len = std::min(uint16_t(_tcp.hw_features().mtu - net::tcp_hdr_len_min - InetTraits::ip_hdr_len_min), _snd.mss); } can_send = std::min(can_send, len); // easy case: one small packet @@ -2077,6 +2079,6 @@ typename tcp::tcb::isn_secret tcp::tcb::_isn_secret; } - +} #endif /* TCP_HH_ */ diff --git a/net/tls.cc b/net/tls.cc index 96f94d98201..8565c7849b8 100644 --- a/net/tls.cc +++ b/net/tls.cc @@ -33,6 +33,8 @@ #include "tls.hh" #include "stack.hh" +namespace seastar { + class net::get_impl { public: static std::unique_ptr get(connected_socket s) { @@ -42,7 +44,7 @@ class net::get_impl { class blob_wrapper: public gnutls_datum_t { public: - blob_wrapper(const seastar::tls::blob& in) + blob_wrapper(const tls::blob& in) : gnutls_datum_t { reinterpret_cast(const_cast(in.data())), unsigned(in.size()) } { @@ -115,7 +117,7 @@ static void gtls_chk(int res) { } } -class seastar::tls::dh_params::impl : gnutlsobj { +class tls::dh_params::impl : gnutlsobj { static gnutls_sec_param_t to_gnutls_level(level l) { switch (l) { case level::LEGACY: return GNUTLS_SEC_PARAM_LEGACY; @@ -170,27 +172,27 @@ class seastar::tls::dh_params::impl : gnutlsobj { gnutls_dh_params_t _params; }; -seastar::tls::dh_params::dh_params(level lvl) : _impl(std::make_unique(lvl)) +tls::dh_params::dh_params(level lvl) : _impl(std::make_unique(lvl)) {} -seastar::tls::dh_params::dh_params(const blob& b, x509_crt_format fmt) +tls::dh_params::dh_params(const blob& b, x509_crt_format fmt) : _impl(std::make_unique(b, fmt)) { } -seastar::tls::dh_params::~dh_params() { +tls::dh_params::~dh_params() { } -seastar::tls::dh_params::dh_params(dh_params&&) noexcept = default; -seastar::tls::dh_params& seastar::tls::dh_params::operator=(dh_params&&) noexcept = default; +tls::dh_params::dh_params(dh_params&&) noexcept = default; +tls::dh_params& tls::dh_params::operator=(dh_params&&) noexcept = default; -future seastar::tls::dh_params::from_file( +future tls::dh_params::from_file( const sstring& filename, x509_crt_format fmt) { return read_fully(filename, "dh parameters").then([fmt](temporary_buffer buf) { return make_ready_future(dh_params(blob(buf.get()), fmt)); }); } -class seastar::tls::x509_cert::impl : gnutlsobj { +class tls::x509_cert::impl : gnutlsobj { public: impl() : _cert([] { @@ -218,22 +220,22 @@ class seastar::tls::x509_cert::impl : gnutlsobj { gnutls_x509_crt_t _cert; }; -seastar::tls::x509_cert::x509_cert(::shared_ptr impl) +tls::x509_cert::x509_cert(shared_ptr impl) : _impl(std::move(impl)) { } -seastar::tls::x509_cert::x509_cert(const blob& b, x509_crt_format fmt) - : x509_cert(::make_shared(b, fmt)) { +tls::x509_cert::x509_cert(const blob& b, x509_crt_format fmt) + : x509_cert(::seastar::make_shared(b, fmt)) { } -future seastar::tls::x509_cert::from_file( +future tls::x509_cert::from_file( const sstring& filename, x509_crt_format fmt) { return read_fully(filename, "x509 certificate").then([fmt](temporary_buffer buf) { return make_ready_future(x509_cert(blob(buf.get()), fmt)); }); } -class seastar::tls::certificate_credentials::impl: public gnutlsobj { +class tls::certificate_credentials::impl: public gnutlsobj { public: impl() : _creds([] { @@ -287,7 +289,7 @@ class seastar::tls::certificate_credentials::impl: public gnutlsobj { _dh_params = std::move(cpy); } future<> set_system_trust() { - return seastar::async([this] { + return async([this] { gtls_chk(gnutls_certificate_set_x509_system_trust(_creds)); _load_system_trust = false; // should only do once, for whatever reason }); @@ -335,53 +337,53 @@ class seastar::tls::certificate_credentials::impl: public gnutlsobj { semaphore _system_trust_sem {1}; }; -seastar::tls::certificate_credentials::certificate_credentials() +tls::certificate_credentials::certificate_credentials() : _impl(std::make_unique()) { } -seastar::tls::certificate_credentials::~certificate_credentials() { +tls::certificate_credentials::~certificate_credentials() { } -seastar::tls::certificate_credentials::certificate_credentials( +tls::certificate_credentials::certificate_credentials( certificate_credentials&&) noexcept = default; -seastar::tls::certificate_credentials& seastar::tls::certificate_credentials::operator=( +tls::certificate_credentials& tls::certificate_credentials::operator=( certificate_credentials&&) noexcept = default; -void seastar::tls::certificate_credentials::set_x509_trust(const blob& b, +void tls::certificate_credentials::set_x509_trust(const blob& b, x509_crt_format fmt) { _impl->set_x509_trust(b, fmt); } -void seastar::tls::certificate_credentials::set_x509_crl(const blob& b, +void tls::certificate_credentials::set_x509_crl(const blob& b, x509_crt_format fmt) { _impl->set_x509_crl(b, fmt); } -void seastar::tls::certificate_credentials::set_x509_key(const blob& cert, +void tls::certificate_credentials::set_x509_key(const blob& cert, const blob& key, x509_crt_format fmt) { _impl->set_x509_key(cert, key, fmt); } -void seastar::tls::certificate_credentials::set_simple_pkcs12(const blob& b, +void tls::certificate_credentials::set_simple_pkcs12(const blob& b, x509_crt_format fmt, const sstring& password) { _impl->set_simple_pkcs12(b, fmt, password); } -future<> seastar::tls::abstract_credentials::set_x509_trust_file( +future<> tls::abstract_credentials::set_x509_trust_file( const sstring& cafile, x509_crt_format fmt) { return read_fully(cafile, "trust file").then([this, fmt](temporary_buffer buf) { set_x509_trust(blob(buf.get(), buf.size()), fmt); }); } -future<> seastar::tls::abstract_credentials::set_x509_crl_file( +future<> tls::abstract_credentials::set_x509_crl_file( const sstring& crlfile, x509_crt_format fmt) { return read_fully(crlfile, "crl file").then([this, fmt](temporary_buffer buf) { set_x509_crl(blob(buf.get(), buf.size()), fmt); }); } -future<> seastar::tls::abstract_credentials::set_x509_key_file( +future<> tls::abstract_credentials::set_x509_key_file( const sstring& cf, const sstring& kf, x509_crt_format fmt) { return read_fully(cf, "certificate file").then([this, fmt, kf](temporary_buffer buf) { return read_fully(kf, "key file").then([this, fmt, buf = std::move(buf)](temporary_buffer buf2) { @@ -390,7 +392,7 @@ future<> seastar::tls::abstract_credentials::set_x509_key_file( }); } -future<> seastar::tls::abstract_credentials::set_simple_pkcs12_file( +future<> tls::abstract_credentials::set_simple_pkcs12_file( const sstring& pkcs12file, x509_crt_format fmt, const sstring& password) { return read_fully(pkcs12file, "pkcs12 file").then([this, fmt, password](temporary_buffer buf) { @@ -398,27 +400,27 @@ future<> seastar::tls::abstract_credentials::set_simple_pkcs12_file( }); } -future<> seastar::tls::certificate_credentials::set_system_trust() { +future<> tls::certificate_credentials::set_system_trust() { return _impl->set_system_trust(); } -void seastar::tls::certificate_credentials::set_priority_string(const sstring& prio) { +void tls::certificate_credentials::set_priority_string(const sstring& prio) { _impl->set_priority_string(prio); } -seastar::tls::server_credentials::server_credentials(::shared_ptr dh) +tls::server_credentials::server_credentials(shared_ptr dh) : server_credentials(*dh) {} -seastar::tls::server_credentials::server_credentials(const dh_params& dh) { +tls::server_credentials::server_credentials(const dh_params& dh) { _impl->dh_params(dh); } -seastar::tls::server_credentials::server_credentials(server_credentials&&) noexcept = default; -seastar::tls::server_credentials& seastar::tls::server_credentials::operator=( +tls::server_credentials::server_credentials(server_credentials&&) noexcept = default; +tls::server_credentials& tls::server_credentials::operator=( server_credentials&&) noexcept = default; -void seastar::tls::server_credentials::set_client_auth(client_auth ca) { +void tls::server_credentials::set_client_auth(client_auth ca) { _impl->set_client_auth(ca); } @@ -429,29 +431,29 @@ static const sstring x509_key_key = "x509_key"; static const sstring pkcs12_key = "pkcs12"; static const sstring system_trust = "system_trust"; -typedef std::basic_string> buffer_type; +typedef std::basic_string> buffer_type; -void seastar::tls::credentials_builder::set_dh_level(dh_params::level level) { +void tls::credentials_builder::set_dh_level(dh_params::level level) { _blobs.emplace(dh_level_key, level); } -void seastar::tls::credentials_builder::set_x509_trust(const blob& b, x509_crt_format fmt) { +void tls::credentials_builder::set_x509_trust(const blob& b, x509_crt_format fmt) { _blobs.emplace(x509_trust_key, std::make_pair(b.to_string(), fmt)); } -void seastar::tls::credentials_builder::set_x509_crl(const blob& b, x509_crt_format fmt) { +void tls::credentials_builder::set_x509_crl(const blob& b, x509_crt_format fmt) { _blobs.emplace(x509_crl_key, std::make_pair(b.to_string(), fmt)); } -void seastar::tls::credentials_builder::set_x509_key(const blob& cert, const blob& key, x509_crt_format fmt) { +void tls::credentials_builder::set_x509_key(const blob& cert, const blob& key, x509_crt_format fmt) { _blobs.emplace(x509_key_key, std::make_tuple(cert.to_string(), key.to_string(), fmt)); } -void seastar::tls::credentials_builder::set_simple_pkcs12(const blob& b, x509_crt_format fmt, const sstring& password) { +void tls::credentials_builder::set_simple_pkcs12(const blob& b, x509_crt_format fmt, const sstring& password) { _blobs.emplace(pkcs12_key, std::make_tuple(b.to_string(), fmt, password)); } -future<> seastar::tls::credentials_builder::set_system_trust() { +future<> tls::credentials_builder::set_system_trust() { // TODO / Caveat: // We cannot actually issue a loading of system trust here, // because we have no actual tls context. @@ -465,15 +467,15 @@ future<> seastar::tls::credentials_builder::set_system_trust() { return make_ready_future(); } -void seastar::tls::credentials_builder::set_client_auth(client_auth auth) { +void tls::credentials_builder::set_client_auth(client_auth auth) { _client_auth = auth; } -void seastar::tls::credentials_builder::set_priority_string(const sstring& prio) { +void tls::credentials_builder::set_priority_string(const sstring& prio) { _priority = prio; } -void seastar::tls::credentials_builder::apply_to(certificate_credentials& creds) const { +void tls::credentials_builder::apply_to(certificate_credentials& creds) const { // Could potentially be templated down, but why bother... { auto tr = _blobs.equal_range(x509_trust_key); @@ -520,23 +522,22 @@ void seastar::tls::credentials_builder::apply_to(certificate_credentials& creds) creds._impl->set_client_auth(_client_auth); } -::shared_ptr seastar::tls::credentials_builder::build_certificate_credentials() const { - auto creds = ::make_shared(); +shared_ptr tls::credentials_builder::build_certificate_credentials() const { + auto creds = make_shared(); apply_to(*creds); return creds; } -::shared_ptr seastar::tls::credentials_builder::build_server_credentials() const { +shared_ptr tls::credentials_builder::build_server_credentials() const { auto i = _blobs.find(dh_level_key); if (i == _blobs.end()) { throw std::invalid_argument("No DH level set"); } - auto creds = ::make_shared(dh_params(boost::any_cast(i->second))); + auto creds = make_shared(dh_params(boost::any_cast(i->second))); apply_to(*creds); return creds; } -namespace seastar { namespace tls { /** @@ -555,8 +556,8 @@ class session : public enable_lw_shared_from_this { CLIENT = GNUTLS_CLIENT, SERVER = GNUTLS_SERVER, }; - session(type t, ::shared_ptr creds, - std::unique_ptr<::net::connected_socket_impl> sock, sstring name = { }) + session(type t, shared_ptr creds, + std::unique_ptr sock, sstring name = { }) : _type(t), _sock(std::move(sock)), _creds(std::move(creds)), _hostname( std::move(name)), _in(_sock->source()), _out(_sock->sink()), _in_sem(1), _out_sem(1), _output_pending( @@ -601,9 +602,9 @@ class session : public enable_lw_shared_from_this { } #endif } - session(type t, ::shared_ptr creds, - ::connected_socket sock, sstring name = { }) - : session(t, std::move(creds), ::net::get_impl::get(std::move(sock)), + session(type t, shared_ptr creds, + connected_socket sock, sstring name = { }) + : session(t, std::move(creds), net::get_impl::get(std::move(sock)), std::move(name)) { } @@ -911,7 +912,7 @@ class session : public enable_lw_shared_from_this { return _out.flush(); } - ::net::connected_socket_impl & socket() const { + net::connected_socket_impl & socket() const { return *_sock; } @@ -919,8 +920,8 @@ class session : public enable_lw_shared_from_this { private: type _type; - std::unique_ptr<::net::connected_socket_impl> _sock; - ::shared_ptr _creds; + std::unique_ptr _sock; + shared_ptr _creds; const sstring _hostname; data_source _in; data_sink _out; @@ -974,7 +975,7 @@ void session::shutdown_with_timer(gnutls_close_request_t how, Func && func) { } } -class tls_connected_socket_impl : public ::net::connected_socket_impl, public session::session_ref { +class tls_connected_socket_impl : public net::connected_socket_impl, public session::session_ref { public: using session_ref::session_ref; @@ -1002,16 +1003,16 @@ class tls_connected_socket_impl : public ::net::connected_socket_impl, public se bool get_keepalive() const override { return _session->socket().get_keepalive(); } - void set_keepalive_parameters(const ::net::keepalive_params& p) override { + void set_keepalive_parameters(const net::keepalive_params& p) override { _session->socket().set_keepalive_parameters(p); } - ::net::keepalive_params get_keepalive_parameters() const override { + net::keepalive_params get_keepalive_parameters() const override { return _session->socket().get_keepalive_parameters(); } }; -class tls_connected_socket_impl::source_impl: public ::data_source_impl, public session::session_ref { +class tls_connected_socket_impl::source_impl: public data_source_impl, public session::session_ref { public: using session_ref::session_ref; private: @@ -1064,13 +1065,13 @@ class tls_connected_socket_impl::source_impl: public ::data_source_impl, public // produced, cannot exist outside the direct life span of // the connected_socket itself. This is consistent with // other sockets in seastar, though I am than less fond of it... -class tls_connected_socket_impl::sink_impl: public ::data_sink_impl, public session::session_ref { +class tls_connected_socket_impl::sink_impl: public data_sink_impl, public session::session_ref { public: using session_ref::session_ref; private: - typedef ::net::fragment* frag_iter; + typedef net::fragment* frag_iter; - future<> put(::net::packet p, frag_iter i, frag_iter e, size_t off = 0) { + future<> put(net::packet p, frag_iter i, frag_iter e, size_t off = 0) { while (i != e) { auto ptr = i->base; auto size = i->size; @@ -1105,7 +1106,7 @@ class tls_connected_socket_impl::sink_impl: public ::data_sink_impl, public sess future<> flush() override { return _session->flush(); } - future<> put(::net::packet p) override { + future<> put(net::packet p) override { auto i = p.fragments().begin(); auto e = p.fragments().end(); return put(std::move(p), i, e); @@ -1117,17 +1118,17 @@ class tls_connected_socket_impl::sink_impl: public ::data_sink_impl, public sess } }; -class server_session : public ::net::server_socket_impl { +class server_session : public net::server_socket_impl { public: - server_session(::shared_ptr creds, ::server_socket sock) + server_session(shared_ptr creds, server_socket sock) : _creds(std::move(creds)), _sock(std::move(sock)) { } future accept() override { // We're not actually doing anything very SSL until we get // an actual connection. Then we create a "server" session // and wrap it up after handshaking. - return _sock.accept().then([this](::connected_socket s, ::socket_address addr) { - return wrap_server(_creds, std::move(s)).then([addr](::connected_socket s) { + return _sock.accept().then([this](connected_socket s, socket_address addr) { + return wrap_server(_creds, std::move(s)).then([addr](connected_socket s) { return make_ready_future(std::move(s), addr); }); }); @@ -1136,20 +1137,20 @@ class server_session : public ::net::server_socket_impl { _sock.abort_accept(); } private: - ::shared_ptr _creds; - ::server_socket _sock; + shared_ptr _creds; + server_socket _sock; }; -class tls_socket_impl : public ::net::socket_impl { - ::shared_ptr _cred; +class tls_socket_impl : public net::socket_impl { + shared_ptr _cred; sstring _name; - seastar::socket _socket; + ::seastar::socket _socket; public: - tls_socket_impl(::shared_ptr cred, sstring name) + tls_socket_impl(shared_ptr cred, sstring name) : _cred(cred), _name(std::move(name)), _socket(engine().net().socket()) { } virtual future connect(socket_address sa, socket_address local, transport proto = transport::TCP) override { - return _socket.connect(sa, local, proto).then([cred = std::move(_cred), name = std::move(_name)](::connected_socket s) mutable { + return _socket.connect(sa, local, proto).then([cred = std::move(_cred), name = std::move(_name)](connected_socket s) mutable { return wrap_client(cred, std::move(s), std::move(name)); }); } @@ -1158,58 +1159,58 @@ class tls_socket_impl : public ::net::socket_impl { } }; -} } -data_source seastar::tls::tls_connected_socket_impl::source() { +data_source tls::tls_connected_socket_impl::source() { return data_source(std::make_unique(_session)); } -data_sink seastar::tls::tls_connected_socket_impl::sink() { +data_sink tls::tls_connected_socket_impl::sink() { return data_sink(std::make_unique(_session)); } -future<::connected_socket> seastar::tls::connect(::shared_ptr cred, socket_address sa, sstring name) { - return engine().connect(sa).then([cred = std::move(cred), name = std::move(name)](::connected_socket s) mutable { +future tls::connect(shared_ptr cred, socket_address sa, sstring name) { + return engine().connect(sa).then([cred = std::move(cred), name = std::move(name)](connected_socket s) mutable { return wrap_client(cred, std::move(s), std::move(name)); }); } -future<::connected_socket> seastar::tls::connect(::shared_ptr cred, socket_address sa, socket_address local, sstring name) { - return engine().connect(sa, local).then([cred = std::move(cred), name = std::move(name)](::connected_socket s) mutable { +future tls::connect(shared_ptr cred, socket_address sa, socket_address local, sstring name) { + return engine().connect(sa, local).then([cred = std::move(cred), name = std::move(name)](connected_socket s) mutable { return wrap_client(cred, std::move(s), std::move(name)); }); } -seastar::socket seastar::tls::socket(::shared_ptr cred, sstring name) { - return seastar::socket(std::make_unique(std::move(cred), std::move(name))); +socket tls::socket(shared_ptr cred, sstring name) { + return ::seastar::socket(std::make_unique(std::move(cred), std::move(name))); } -future<::connected_socket> seastar::tls::wrap_client(::shared_ptr cred, ::connected_socket&& s, sstring name) { +future tls::wrap_client(shared_ptr cred, connected_socket&& s, sstring name) { auto sess = make_lw_shared(session::type::CLIENT, std::move(cred), std::move(s), std::move(name)); auto f = sess->handshake(); return f.then([sess = std::move(sess)]() mutable { - ::connected_socket ssls(std::make_unique(std::move(sess))); - return make_ready_future<::connected_socket>(std::move(ssls)); + connected_socket ssls(std::make_unique(std::move(sess))); + return make_ready_future(std::move(ssls)); }); } -future<::connected_socket> seastar::tls::wrap_server(::shared_ptr cred, ::connected_socket&& s) { +future tls::wrap_server(shared_ptr cred, connected_socket&& s) { auto sess = make_lw_shared(session::type::SERVER, std::move(cred), std::move(s)); auto f = sess->handshake(); return f.then([sess = std::move(sess)]() mutable { - ::connected_socket ssls(std::make_unique(std::move(sess))); - return make_ready_future<::connected_socket>(std::move(ssls)); + connected_socket ssls(std::make_unique(std::move(sess))); + return make_ready_future(std::move(ssls)); }); } -::server_socket seastar::tls::listen(::shared_ptr creds, ::socket_address sa, ::listen_options opts) { +server_socket tls::listen(shared_ptr creds, socket_address sa, listen_options opts) { return listen(std::move(creds), engine().listen(sa, opts)); } -::server_socket seastar::tls::listen(::shared_ptr creds, ::server_socket ss) { - ::server_socket ssls(std::make_unique(creds, std::move(ss))); - return ::server_socket(std::move(ssls)); +server_socket tls::listen(shared_ptr creds, server_socket ss) { + server_socket ssls(std::make_unique(creds, std::move(ss))); + return server_socket(std::move(ssls)); } +} diff --git a/net/tls.hh b/net/tls.hh index 4a5e614e565..43d7214acb5 100644 --- a/net/tls.hh +++ b/net/tls.hh @@ -26,6 +26,8 @@ #include "core/future.hh" #include "core/sstring.hh" +namespace seastar { + class connected_socket; /** @@ -38,7 +40,6 @@ class connected_socket; * with OpenSSL or similar. * */ -namespace seastar { namespace tls { enum class x509_crt_format { DER, @@ -92,8 +93,8 @@ namespace tls { static future from_file(const sstring&, x509_crt_format); private: class impl; - x509_cert(::shared_ptr); - ::shared_ptr _impl; + x509_cert(shared_ptr); + shared_ptr _impl; }; class abstract_credentials { @@ -178,7 +179,7 @@ namespace tls { */ class server_credentials : public certificate_credentials { public: - server_credentials(::shared_ptr); + server_credentials(shared_ptr); server_credentials(const dh_params&); server_credentials(server_credentials&&) noexcept; @@ -215,8 +216,8 @@ namespace tls { void apply_to(certificate_credentials&) const; - ::shared_ptr build_certificate_credentials() const; - ::shared_ptr build_server_credentials() const; + shared_ptr build_certificate_credentials() const; + shared_ptr build_server_credentials() const; private: std::multimap _blobs; @@ -233,8 +234,8 @@ namespace tls { * \param name An optional expected server name for the remote end point */ /// @{ - future<::connected_socket> connect(::shared_ptr, ::socket_address, sstring name = {}); - future<::connected_socket> connect(::shared_ptr, ::socket_address, ::socket_address local, sstring name = {}); + future connect(shared_ptr, socket_address, sstring name = {}); + future connect(shared_ptr, socket_address, socket_address local, sstring name = {}); /// @} /** @@ -246,13 +247,13 @@ namespace tls { * \param name An optional expected server name for the remote end point */ /// @{ - ::seastar::socket socket(::shared_ptr, sstring name = {}); + ::seastar::socket socket(shared_ptr, sstring name = {}); /// @} /** Wraps an existing connection in SSL/TLS. */ /// @{ - future<::connected_socket> wrap_client(::shared_ptr, ::connected_socket&&, sstring name = {}); - future<::connected_socket> wrap_server(::shared_ptr, ::connected_socket&&); + future wrap_client(shared_ptr, connected_socket&&, sstring name = {}); + future wrap_server(shared_ptr, connected_socket&&); /// @} /** @@ -262,9 +263,10 @@ namespace tls { * for the server and optionally trust/crl data. */ /// @{ - ::server_socket listen(::shared_ptr, ::socket_address sa, ::listen_options opts = listen_options()); + server_socket listen(shared_ptr, socket_address sa, listen_options opts = listen_options()); // Wraps an existing server socket in SSL - ::server_socket listen(::shared_ptr, ::server_socket); + server_socket listen(shared_ptr, server_socket); /// @} } } + diff --git a/net/toeplitz.hh b/net/toeplitz.hh index 2c0670a3a2d..a162426d67e 100644 --- a/net/toeplitz.hh +++ b/net/toeplitz.hh @@ -46,6 +46,8 @@ #include +namespace seastar { + using rss_key_type = std::vector; // Mellanox Linux's driver key @@ -90,4 +92,7 @@ toeplitz_hash(const rss_key_type& key, const T& data) } return (hash); } + +} + #endif diff --git a/net/udp.cc b/net/udp.cc index 9cfaf0f1d37..06f4092676e 100644 --- a/net/udp.cc +++ b/net/udp.cc @@ -22,6 +22,8 @@ #include "ip.hh" #include "stack.hh" +namespace seastar { + using namespace net; namespace net { @@ -221,3 +223,6 @@ ipv4_udp::make_channel(ipv4_addr addr) { } } /* namespace net */ + +} + diff --git a/net/udp.hh b/net/udp.hh index 608cf56cc8c..aad8d90ce8a 100644 --- a/net/udp.hh +++ b/net/udp.hh @@ -31,6 +31,8 @@ #include "const.hh" #include "net.hh" +namespace seastar { + namespace net { struct udp_hdr { @@ -56,4 +58,6 @@ struct udp_channel_state { } +} + #endif diff --git a/net/virtio.cc b/net/virtio.cc index b5d5d7786ac..b1d6264e079 100644 --- a/net/virtio.cc +++ b/net/virtio.cc @@ -45,6 +45,8 @@ #include #endif +namespace seastar { + using namespace net; namespace virtio { @@ -1017,6 +1019,8 @@ std::unique_ptr create_virtio_net_device(boost::program_options::va return std::make_unique(opts); } +} + // Locks the shared object in memory and forces on-load function resolution. // Needed if the function passed to enable_interrupt() is run at interrupt // time. diff --git a/net/virtio.hh b/net/virtio.hh index 7ee661e12ff..f074b0905e9 100644 --- a/net/virtio.hh +++ b/net/virtio.hh @@ -26,7 +26,11 @@ #include "net.hh" #include "core/sstring.hh" +namespace seastar { + std::unique_ptr create_virtio_net_device(boost::program_options::variables_map opts = boost::program_options::variables_map()); boost::program_options::options_description get_virtio_net_options_description(); +} + #endif /* VIRTIO_HH_ */ diff --git a/net/xenfront.cc b/net/xenfront.cc index 8b4cb3100b9..c40d0af62b3 100644 --- a/net/xenfront.cc +++ b/net/xenfront.cc @@ -49,6 +49,8 @@ #include "xenfront.hh" #include +namespace seastar { + using namespace net; namespace xen { @@ -456,3 +458,5 @@ std::unique_ptr create_xenfront_net_device(boost::program_options:: } } + +} diff --git a/net/xenfront.hh b/net/xenfront.hh index 31ae845db4f..bbd65231bcd 100644 --- a/net/xenfront.hh +++ b/net/xenfront.hh @@ -28,6 +28,8 @@ #include "core/xen/gntalloc.hh" #include "core/queue.hh" +namespace seastar { + namespace xen { std::unique_ptr create_xenfront_net_device(boost::program_options::variables_map opts, bool userspace); @@ -152,4 +154,6 @@ private: } +} + #endif /* XENFRONT_HH_ */ diff --git a/rpc/lz4_compressor.cc b/rpc/lz4_compressor.cc index b6b83b229e0..a647b2d16cc 100644 --- a/rpc/lz4_compressor.cc +++ b/rpc/lz4_compressor.cc @@ -22,6 +22,8 @@ #include "lz4_compressor.hh" #include "core/byteorder.hh" +namespace seastar { + namespace rpc { const sstring lz4_compressor::factory::_name = "LZ4"; @@ -87,3 +89,5 @@ rcv_buf lz4_compressor::decompress(rcv_buf data) { } } + +} diff --git a/rpc/lz4_compressor.hh b/rpc/lz4_compressor.hh index a7314c0e31e..d3fdd525cfc 100644 --- a/rpc/lz4_compressor.hh +++ b/rpc/lz4_compressor.hh @@ -25,6 +25,8 @@ #include "rpc/rpc_types.hh" #include +namespace seastar { + namespace rpc { class lz4_compressor : public compressor { public: @@ -46,3 +48,5 @@ namespace rpc { rcv_buf decompress(rcv_buf data) override; }; } + +} diff --git a/rpc/multi_algo_compressor_factory.hh b/rpc/multi_algo_compressor_factory.hh index 93b39947f57..bc95ffde10f 100644 --- a/rpc/multi_algo_compressor_factory.hh +++ b/rpc/multi_algo_compressor_factory.hh @@ -26,6 +26,8 @@ #include "core/sstring.hh" #include "rpc_types.hh" +namespace seastar { + namespace rpc { // This is meta compressor factory. It gets an array of regular factories that @@ -74,3 +76,5 @@ public: }; } + +} diff --git a/rpc/rpc.cc b/rpc/rpc.cc index 6e5a46fc41b..895c0dca867 100644 --- a/rpc/rpc.cc +++ b/rpc/rpc.cc @@ -1,5 +1,7 @@ #include "rpc.hh" +namespace seastar { + namespace rpc { no_wait_type no_wait; @@ -28,3 +30,5 @@ namespace rpc { } } } + +} diff --git a/rpc/rpc.hh b/rpc/rpc.hh index 9ff77ee5f4a..31cfcfc65dc 100644 --- a/rpc/rpc.hh +++ b/rpc/rpc.hh @@ -34,6 +34,8 @@ #include "rpc/rpc_types.hh" #include "core/byteorder.hh" +namespace seastar { + namespace rpc { using id_type = int64_t; @@ -345,7 +347,7 @@ public: rpc_semaphore _resources_available; std::unordered_set> _conns; promise<> _ss_stopped; - seastar::gate _reply_gate; + gate _reply_gate; server_options _options; public: server(protocol& proto, ipv4_addr addr, resource_limits memory_limit = resource_limits()); @@ -370,14 +372,14 @@ public: f(*c); } } - seastar::gate& reply_gate() { + gate& reply_gate() { return _reply_gate; } friend connection; }; class client : public protocol::connection { - ::seastar::socket _socket; + socket _socket; id_type _message_id = 1; struct reply_handler_base { timer t; @@ -443,8 +445,8 @@ public: * @param local the local address of this client * @param socket the socket object use to connect to the remote address */ - client(protocol& proto, seastar::socket socket, ipv4_addr addr, ipv4_addr local = ipv4_addr()); - client(protocol& proto, client_options options, seastar::socket socket, ipv4_addr addr, ipv4_addr local = ipv4_addr()); + client(protocol& proto, socket socket, ipv4_addr addr, ipv4_addr local = ipv4_addr()); + client(protocol& proto, client_options options, socket socket, ipv4_addr addr, ipv4_addr local = ipv4_addr()); stats get_stats() const { stats res = this->_stats; @@ -547,4 +549,6 @@ private: }; } +} + #include "rpc_impl.hh" diff --git a/rpc/rpc_impl.hh b/rpc/rpc_impl.hh index 0d95a1a270a..56dfd22b25d 100644 --- a/rpc/rpc_impl.hh +++ b/rpc/rpc_impl.hh @@ -32,6 +32,8 @@ #include #include "net/packet-data-source.hh" +namespace seastar { + namespace rpc { enum class exception_type : uint32_t { @@ -203,19 +205,19 @@ inline void do_marshall(Serializer& serializer, Output& out, const T&... args) { (void)std::initializer_list{(marshall_one(serializer, out, args), 1)...}; } -static inline seastar::memory_output_stream make_serializer_stream(snd_buf& output) { +static inline memory_output_stream make_serializer_stream(snd_buf& output) { auto* b = boost::get>(&output.bufs); if (b) { - return seastar::memory_output_stream(seastar::memory_output_stream::simple(b->get_write(), b->size())); + return memory_output_stream(memory_output_stream::simple(b->get_write(), b->size())); } else { auto& ar = boost::get>>(output.bufs); - return seastar::memory_output_stream(seastar::memory_output_stream::fragmented(ar.begin(), output.size)); + return memory_output_stream(memory_output_stream::fragmented(ar.begin(), output.size)); } } template inline snd_buf marshall(Serializer& serializer, size_t head_space, const T&... args) { - seastar::measuring_output_stream measure; + measuring_output_stream measure; do_marshall(serializer, measure, args...); snd_buf ret(measure.size() + head_space); auto out = make_serializer_stream(ret); @@ -428,7 +430,7 @@ inline future<> reply(wait_type, future&& ret, int64_t msg_id, lw_s if (!client->error()) { snd_buf data; try { - data = ::apply(marshall, + data = apply(marshall, std::tuple_cat(std::make_tuple(std::ref(client->serializer()), 12), std::move(ret.get()))); } catch (std::exception& ex) { uint32_t len = std::strlen(ex.what()); @@ -496,13 +498,13 @@ auto recv_helper(signature sig, Func&& func, WantClientInfo wci // note: apply is executed asynchronously with regards to networking so we cannot chain futures here by doing "return apply()" auto f = client->wait_for_resources(memory_consumed, timeout).then([client, timeout, msg_id, data = std::move(data), &func] (auto permit) mutable { try { - seastar::with_gate(client->get_server().reply_gate(), [client, timeout, msg_id, data = std::move(data), permit = std::move(permit), &func] () mutable { + with_gate(client->get_server().reply_gate(), [client, timeout, msg_id, data = std::move(data), permit = std::move(permit), &func] () mutable { auto args = unmarshall(client->serializer(), std::move(data)); return apply(func, client->info(), timeout, WantClientInfo(), WantTimePoint(), signature(), std::move(args)).then_wrapped([client, timeout, msg_id, permit = std::move(permit)] (futurize_t ret) mutable { return reply(wait_style(), std::move(ret), msg_id, client, timeout).then([permit = std::move(permit)] {}); }); }); - } catch (seastar::gate_closed_exception&) {/* ignore */ } + } catch (gate_closed_exception&) {/* ignore */ } }); if (timeout) { @@ -968,10 +970,10 @@ future<> protocol::server::connection::process() { write_le(p + 4, uint32_t(8)); write_le(p + 8, uint64_t(type)); try { - seastar::with_gate(this->_server._reply_gate, [this, timeout, msg_id, data = std::move(data), permit = std::move(permit)] () mutable { + with_gate(this->_server._reply_gate, [this, timeout, msg_id, data = std::move(data), permit = std::move(permit)] () mutable { return this->respond(-msg_id, std::move(data), timeout).then([c = this->shared_from_this(), permit = std::move(permit)] {}); }); - } catch(seastar::gate_closed_exception&) {/* ignore */} + } catch(gate_closed_exception&) {/* ignore */} }); } } @@ -1042,7 +1044,7 @@ protocol::client::read_response_frame_compressed(input_stre } template -protocol::client::client(protocol& proto, client_options ops, seastar::socket socket, ipv4_addr addr, ipv4_addr local) +protocol::client::client(protocol& proto, client_options ops, socket socket, ipv4_addr addr, ipv4_addr local) : protocol::connection(proto), _socket(std::move(socket)), _server_addr(addr), _options(ops) { _socket.connect(addr, local).then([this, ops = std::move(ops)] (connected_socket fd) { fd.set_nodelay(true); @@ -1115,8 +1117,10 @@ protocol::client::client(protocol& pro {} template -protocol::client::client(protocol& proto, seastar::socket socket, ipv4_addr addr, ipv4_addr local) +protocol::client::client(protocol& proto, socket socket, ipv4_addr addr, ipv4_addr local) : client(proto, client_options{}, std::move(socket), addr, local) {} } + +} diff --git a/rpc/rpc_types.hh b/rpc/rpc_types.hh index 476da957dfb..df5605ca0df 100644 --- a/rpc/rpc_types.hh +++ b/rpc/rpc_types.hh @@ -32,6 +32,8 @@ #include "core/simple-stream.hh" #include "core/lowres_clock.hh" +namespace seastar { + namespace rpc { using rpc_clock_type = lowres_clock; @@ -180,13 +182,13 @@ struct snd_buf { temporary_buffer& front(); }; -static inline seastar::memory_input_stream make_deserializer_stream(rcv_buf& input) { +static inline memory_input_stream make_deserializer_stream(rcv_buf& input) { auto* b = boost::get>(&input.bufs); if (b) { - return seastar::memory_input_stream(seastar::memory_input_stream::simple(b->begin(), b->size())); + return memory_input_stream(memory_input_stream::simple(b->begin(), b->size())); } else { auto& ar = boost::get>>(input.bufs); - return seastar::memory_input_stream(seastar::memory_input_stream::fragmented(ar.begin(), input.size)); + return memory_input_stream(memory_input_stream::fragmented(ar.begin(), input.size)); } } @@ -210,3 +212,6 @@ public: }; } // namespace rpc + +} + diff --git a/tests/alloc_test.cc b/tests/alloc_test.cc index 7118eec3ed0..3e7bb1a3255 100644 --- a/tests/alloc_test.cc +++ b/tests/alloc_test.cc @@ -24,7 +24,7 @@ #include "core/reactor.hh" #include - +using namespace seastar; SEASTAR_TEST_CASE(alloc_almost_all_and_realloc_it_with_a_smaller_size) { #ifndef DEFAULT_ALLOCATOR diff --git a/tests/allocator_test.cc b/tests/allocator_test.cc index be563b80fa8..7701935a22b 100644 --- a/tests/allocator_test.cc +++ b/tests/allocator_test.cc @@ -31,6 +31,8 @@ #include #include +using namespace seastar; + template void test_aligned_allocator() { using aptr = std::unique_ptr; diff --git a/tests/blkdiscard_test.cc b/tests/blkdiscard_test.cc index e42e7cf3fb6..8d0d17c0558 100644 --- a/tests/blkdiscard_test.cc +++ b/tests/blkdiscard_test.cc @@ -25,6 +25,8 @@ #include "core/file.hh" #include "core/reactor.hh" +using namespace seastar; + namespace bpo = boost::program_options; struct file_test { diff --git a/tests/checked_ptr_test.cc b/tests/checked_ptr_test.cc index 3e78c0fa971..43aa378df2f 100644 --- a/tests/checked_ptr_test.cc +++ b/tests/checked_ptr_test.cc @@ -26,6 +26,8 @@ #include "core/checked_ptr.hh" #include "core/weak_ptr.hh" +using namespace seastar; + struct my_st : public weakly_referencable { my_st(int a_) : a(a_) {} int a; diff --git a/tests/chunked_fifo_test.cc b/tests/chunked_fifo_test.cc index ef349e46b19..8acac062a8d 100644 --- a/tests/chunked_fifo_test.cc +++ b/tests/chunked_fifo_test.cc @@ -29,6 +29,8 @@ #include #include "core/circular_buffer.hh" +using namespace seastar; + BOOST_AUTO_TEST_CASE(chunked_fifo_small) { // Check all the methods of chunked_fifo but with a trivial type (int) and // only a few elements - and in particular a single chunk is enough. diff --git a/tests/circular_buffer_test.cc b/tests/circular_buffer_test.cc index a52bee8f3d5..d8fe6ab40ec 100644 --- a/tests/circular_buffer_test.cc +++ b/tests/circular_buffer_test.cc @@ -28,6 +28,8 @@ #include #include "core/circular_buffer.hh" +using namespace seastar; + BOOST_AUTO_TEST_CASE(test_erasing) { circular_buffer buf; diff --git a/tests/connect_test.cc b/tests/connect_test.cc index 20905fb7761..d1672fb52c6 100644 --- a/tests/connect_test.cc +++ b/tests/connect_test.cc @@ -4,6 +4,7 @@ #include +using namespace seastar; using namespace net; SEASTAR_TEST_CASE(test_connection_attempt_is_shutdown) { diff --git a/tests/defer_test.cc b/tests/defer_test.cc index dac5a14594e..1f21c2d917d 100644 --- a/tests/defer_test.cc +++ b/tests/defer_test.cc @@ -24,6 +24,8 @@ #include #include "util/defer.hh" +using namespace seastar; + BOOST_AUTO_TEST_CASE(test_defer_does_not_run_when_canceled) { bool ran = false; { diff --git a/tests/directory_test.cc b/tests/directory_test.cc index e031acbef34..cc6d71d20d3 100644 --- a/tests/directory_test.cc +++ b/tests/directory_test.cc @@ -25,6 +25,8 @@ #include "core/print.hh" #include "core/shared_ptr.hh" +using namespace seastar; + int main(int ac, char** av) { class lister { file _f; diff --git a/tests/distributed_test.cc b/tests/distributed_test.cc index e18eb39387a..b9ad65f57dd 100644 --- a/tests/distributed_test.cc +++ b/tests/distributed_test.cc @@ -25,6 +25,8 @@ #include "core/future-util.hh" #include "core/sleep.hh" +using namespace seastar; + struct async : public seastar::async_sharded_service { thread_local static bool deleted; ~async() { diff --git a/tests/echotest.cc b/tests/echotest.cc index 5232985663f..47b97de7cec 100644 --- a/tests/echotest.cc +++ b/tests/echotest.cc @@ -28,6 +28,7 @@ #include #include +using namespace seastar; using namespace net; void dump_packet(const packet& p) { diff --git a/tests/execution_stage_test.cc b/tests/execution_stage_test.cc index 3ae81ad42ee..fd4aad39a50 100644 --- a/tests/execution_stage_test.cc +++ b/tests/execution_stage_test.cc @@ -27,6 +27,8 @@ #include "test-utils.hh" #include "core/execution_stage.hh" +using namespace seastar; + static std::random_device rd; SEASTAR_TEST_CASE(test_create_stage_from_lvalue_function_object) { diff --git a/tests/fair_queue_test.cc b/tests/fair_queue_test.cc index fff687438e9..da759965653 100644 --- a/tests/fair_queue_test.cc +++ b/tests/fair_queue_test.cc @@ -33,6 +33,7 @@ #include #include +using namespace seastar; using namespace std::chrono_literals; struct test_env { diff --git a/tests/fileiotest.cc b/tests/fileiotest.cc index 64638867f0a..c87030a9848 100644 --- a/tests/fileiotest.cc +++ b/tests/fileiotest.cc @@ -25,6 +25,8 @@ #include "core/file.hh" #include "core/reactor.hh" +using namespace seastar; + struct file_test { file_test(file&& f) : f(std::move(f)) {} file f; diff --git a/tests/foreign_ptr_test.cc b/tests/foreign_ptr_test.cc index 15ba68a0e34..661e5f2565e 100644 --- a/tests/foreign_ptr_test.cc +++ b/tests/foreign_ptr_test.cc @@ -25,6 +25,8 @@ #include "core/shared_ptr.hh" #include "core/thread.hh" +using namespace seastar; + SEASTAR_TEST_CASE(make_foreign_ptr_from_lw_shared_ptr) { auto p = make_foreign(make_lw_shared("foo")); BOOST_REQUIRE(p->size() == 3); diff --git a/tests/fstream_test.cc b/tests/fstream_test.cc index 8782ea3c772..042900e6cfd 100644 --- a/tests/fstream_test.cc +++ b/tests/fstream_test.cc @@ -36,6 +36,8 @@ #include #include "mock_file.hh" +using namespace seastar; + struct writer { output_stream out; writer(file f) : out(make_file_output_stream(std::move(f))) {} diff --git a/tests/futures_test.cc b/tests/futures_test.cc index db0b19198b1..dbec85c6d37 100644 --- a/tests/futures_test.cc +++ b/tests/futures_test.cc @@ -29,6 +29,7 @@ #include "core/thread.hh" #include +using namespace seastar; using namespace std::chrono_literals; class expected_exception : std::runtime_error { diff --git a/tests/httpd.cc b/tests/httpd.cc index 911361983ef..b3e9db81938 100644 --- a/tests/httpd.cc +++ b/tests/httpd.cc @@ -13,6 +13,7 @@ #include "core/future-util.hh" #include "tests/test-utils.hh" +using namespace seastar; using namespace httpd; class handl : public httpd::handler_base { diff --git a/tests/ip_test.cc b/tests/ip_test.cc index 56fe6677e63..b1a7eff245c 100644 --- a/tests/ip_test.cc +++ b/tests/ip_test.cc @@ -25,6 +25,7 @@ #include "core/reactor.hh" #include "net/virtio.hh" +using namespace seastar; using namespace net; int main(int ac, char** av) { diff --git a/tests/l3_test.cc b/tests/l3_test.cc index e7116b6f55e..031c8a43582 100644 --- a/tests/l3_test.cc +++ b/tests/l3_test.cc @@ -23,6 +23,7 @@ #include "core/reactor.hh" #include "net/virtio.hh" +using namespace seastar; using namespace net; void dump_arp_packets(l3_protocol& proto) { diff --git a/tests/linecount.cc b/tests/linecount.cc index 6d7f2d999e5..7bebeee1bb2 100644 --- a/tests/linecount.cc +++ b/tests/linecount.cc @@ -28,6 +28,8 @@ #include "core/reactor.hh" #include +using namespace seastar; + struct reader { public: reader(file f) : is(make_file_input_stream(std::move(f))) {} diff --git a/tests/loopback_socket.hh b/tests/loopback_socket.hh index ae0715a945a..a15e76c6194 100644 --- a/tests/loopback_socket.hh +++ b/tests/loopback_socket.hh @@ -30,6 +30,8 @@ #include "core/do_with.hh" #include "net/stack.hh" +namespace seastar { + class loopback_buffer { bool _aborted = false; queue> _q{1}; @@ -184,3 +186,5 @@ public: _b2->shutdown(); } }; + +} diff --git a/tests/memcached/test_ascii_parser.cc b/tests/memcached/test_ascii_parser.cc index 770ab590d73..4c27291fdf9 100644 --- a/tests/memcached/test_ascii_parser.cc +++ b/tests/memcached/test_ascii_parser.cc @@ -27,6 +27,7 @@ #include "apps/memcached/ascii.hh" #include "core/future-util.hh" +using namespace seastar; using namespace net; using namespace memcache; diff --git a/tests/mock_file.hh b/tests/mock_file.hh index 59f56de281d..248e4b43c32 100644 --- a/tests/mock_file.hh +++ b/tests/mock_file.hh @@ -26,6 +26,8 @@ #include "test-utils.hh" #include "core/file.hh" +namespace seastar { + class mock_read_only_file final : public file_impl { bool _closed = false; uint64_t _total_file_size; @@ -107,3 +109,5 @@ public: return make_ready_future>(temporary_buffer(length)); } }; + +} diff --git a/tests/output_stream_test.cc b/tests/output_stream_test.cc index cdfb9e5f172..e2e439501a8 100644 --- a/tests/output_stream_test.cc +++ b/tests/output_stream_test.cc @@ -29,6 +29,7 @@ #include "test-utils.hh" #include +using namespace seastar; using namespace net; static sstring to_sstring(const packet& p) { diff --git a/tests/packet_test.cc b/tests/packet_test.cc index 20adcfadf21..30961542102 100644 --- a/tests/packet_test.cc +++ b/tests/packet_test.cc @@ -26,6 +26,7 @@ #include "net/packet.hh" #include +using namespace seastar; using namespace net; BOOST_AUTO_TEST_CASE(test_headers_are_contiguous) { diff --git a/tests/perf/perf_fstream.cc b/tests/perf/perf_fstream.cc index 4d545ce3b15..19fc83187e7 100644 --- a/tests/perf/perf_fstream.cc +++ b/tests/perf/perf_fstream.cc @@ -24,6 +24,7 @@ #include "../../core/file.hh" #include "../../core/app-template.hh" +using namespace seastar; using namespace std::chrono_literals; int main(int ac, char** av) { diff --git a/tests/rpc.cc b/tests/rpc.cc index 5ca51b296f2..3bbf1a03262 100644 --- a/tests/rpc.cc +++ b/tests/rpc.cc @@ -25,6 +25,8 @@ #include "core/sleep.hh" #include "rpc/lz4_compressor.hh" +using namespace seastar; + struct serializer { }; diff --git a/tests/shared_ptr_test.cc b/tests/shared_ptr_test.cc index bf0450aaf63..98e447c388b 100644 --- a/tests/shared_ptr_test.cc +++ b/tests/shared_ptr_test.cc @@ -28,6 +28,8 @@ #include "core/sstring.hh" #include "core/shared_ptr.hh" +using namespace seastar; + struct expected_exception : public std::exception {}; struct A { diff --git a/tests/slab_test.cc b/tests/slab_test.cc index 94b4dd4e9ac..3efad73769e 100644 --- a/tests/slab_test.cc +++ b/tests/slab_test.cc @@ -25,6 +25,8 @@ #include #include "core/slab.hh" +using namespace seastar; + static constexpr size_t max_object_size = 1024*1024; class item : public slab_item_base { diff --git a/tests/smp_test.cc b/tests/smp_test.cc index b922496c876..7a374e59941 100644 --- a/tests/smp_test.cc +++ b/tests/smp_test.cc @@ -23,6 +23,8 @@ #include "core/app-template.hh" #include "core/print.hh" +using namespace seastar; + future test_smp_call() { return smp::submit_to(1, [] { return make_ready_future(3); diff --git a/tests/sstring_test.cc b/tests/sstring_test.cc index 9fdd59f6365..0dac2f28512 100644 --- a/tests/sstring_test.cc +++ b/tests/sstring_test.cc @@ -25,6 +25,8 @@ #include "core/sstring.hh" #include +using namespace seastar; + BOOST_AUTO_TEST_CASE(test_equality) { BOOST_REQUIRE_EQUAL(sstring("aaa"), sstring("aaa")); } diff --git a/tests/tcp_sctp_client.cc b/tests/tcp_sctp_client.cc index a06d54ce6f1..6c675cc791c 100644 --- a/tests/tcp_sctp_client.cc +++ b/tests/tcp_sctp_client.cc @@ -23,8 +23,8 @@ #include "core/future-util.hh" #include "core/distributed.hh" -using namespace net; using namespace seastar; +using namespace net; using namespace std::chrono_literals; static int rx_msg_size = 4 * 1024; diff --git a/tests/tcp_test.cc b/tests/tcp_test.cc index e31dd58d6e3..8c7df5d7d5c 100644 --- a/tests/tcp_test.cc +++ b/tests/tcp_test.cc @@ -23,6 +23,7 @@ #include "net/virtio.hh" #include "net/tcp.hh" +using namespace seastar; using namespace net; struct tcp_test { diff --git a/tests/test-utils.cc b/tests/test-utils.cc index 9f118ee4e73..958b86ed056 100644 --- a/tests/test-utils.cc +++ b/tests/test-utils.cc @@ -33,6 +33,8 @@ #include "core/app-template.hh" #include +namespace seastar { + void seastar_test::run() { // HACK: please see https://github.com/cloudius-systems/seastar/issues/10 BOOST_REQUIRE(true); @@ -76,6 +78,8 @@ bool init_unit_test_suite() { return true; } +} + int main(int ac, char** av) { - return ::boost::unit_test::unit_test_main(&init_unit_test_suite, ac, av); + return ::boost::unit_test::unit_test_main(&seastar::init_unit_test_suite, ac, av); } diff --git a/tests/test-utils.hh b/tests/test-utils.hh index 22c6bf582bb..92b12a61a0d 100644 --- a/tests/test-utils.hh +++ b/tests/test-utils.hh @@ -28,6 +28,8 @@ #include "core/future.hh" #include "test_runner.hh" +namespace seastar { + class seastar_test { public: seastar_test(); @@ -47,3 +49,5 @@ public: static name name ## _instance; \ future<> name::run_test_case() + +} diff --git a/tests/test_runner.cc b/tests/test_runner.cc index 319d1f507e1..6b9b8bcf154 100644 --- a/tests/test_runner.cc +++ b/tests/test_runner.cc @@ -26,6 +26,8 @@ #include "core/reactor.hh" #include "test_runner.hh" +namespace seastar { + static test_runner instance; struct stop_execution : public std::exception {}; @@ -93,3 +95,5 @@ test_runner::run_sync(std::function()> task) { test_runner& global_test_runner() { return instance; } + +} diff --git a/tests/test_runner.hh b/tests/test_runner.hh index 818e817f427..55f6c4391af 100644 --- a/tests/test_runner.hh +++ b/tests/test_runner.hh @@ -28,6 +28,8 @@ #include "core/posix.hh" #include "exchanger.hh" +namespace seastar { + class posix_thread; class test_runner { @@ -43,3 +45,5 @@ public: }; test_runner& global_test_runner(); + +} diff --git a/tests/timertest.cc b/tests/timertest.cc index 0bf0041bc57..676a77004e8 100644 --- a/tests/timertest.cc +++ b/tests/timertest.cc @@ -24,6 +24,7 @@ #include "core/print.hh" #include +using namespace seastar; using namespace std::chrono_literals; #define BUG() do { \ diff --git a/tests/udp_client.cc b/tests/udp_client.cc index 57c6b5a5dd5..5f01d0cf7dc 100644 --- a/tests/udp_client.cc +++ b/tests/udp_client.cc @@ -24,6 +24,7 @@ #include "core/reactor.hh" #include "net/api.hh" +using namespace seastar; using namespace net; using namespace std::chrono_literals; diff --git a/tests/udp_server.cc b/tests/udp_server.cc index 527816eea5f..6586577f064 100644 --- a/tests/udp_server.cc +++ b/tests/udp_server.cc @@ -23,6 +23,7 @@ #include "core/app-template.hh" #include "core/future-util.hh" +using namespace seastar; using namespace net; using namespace std::chrono_literals; diff --git a/tests/udp_zero_copy.cc b/tests/udp_zero_copy.cc index 016df8b276e..f4ed0a66621 100644 --- a/tests/udp_zero_copy.cc +++ b/tests/udp_zero_copy.cc @@ -28,6 +28,7 @@ #include #include +using namespace seastar; using namespace net; using namespace std::chrono_literals; namespace bpo = boost::program_options; diff --git a/tests/unwind_test.cc b/tests/unwind_test.cc index 0f6eccd37eb..b79a3e3b477 100644 --- a/tests/unwind_test.cc +++ b/tests/unwind_test.cc @@ -27,6 +27,8 @@ #include "core/posix.hh" #include "util/backtrace.hh" +using namespace seastar; + void foo() { throw std::runtime_error("foo"); } diff --git a/tests/weak_ptr_test.cc b/tests/weak_ptr_test.cc index 7a6c224c4eb..04e4a26da69 100644 --- a/tests/weak_ptr_test.cc +++ b/tests/weak_ptr_test.cc @@ -25,6 +25,8 @@ #include #include "core/weak_ptr.hh" +using namespace seastar; + class myclass : public weakly_referencable {}; BOOST_AUTO_TEST_CASE(test_weak_ptr_is_empty_when_default_initialized) { diff --git a/util/backtrace.hh b/util/backtrace.hh index a04a4ef0cf9..6c9838ea58d 100644 --- a/util/backtrace.hh +++ b/util/backtrace.hh @@ -26,6 +26,8 @@ #include #include +namespace seastar { + // Invokes func for each frame passing return address as argument. template void backtrace(Func&& func) noexcept(noexcept(func(0))) { @@ -69,15 +71,21 @@ public: } }; +} + namespace std { template<> -struct hash<::saved_backtrace> { - size_t operator()(const ::saved_backtrace& b) const { +struct hash { + size_t operator()(const seastar::saved_backtrace& b) const { return b.hash(); } }; } +namespace seastar { + saved_backtrace current_backtrace(); + +} diff --git a/util/bool_class.hh b/util/bool_class.hh index c1000ab0fac..6acadb0fd54 100644 --- a/util/bool_class.hh +++ b/util/bool_class.hh @@ -23,6 +23,8 @@ #include +namespace seastar { + /// \addtogroup utilities /// @{ @@ -104,3 +106,5 @@ template const bool_class bool_class::no { false }; /// @} + +} diff --git a/util/conversions.cc b/util/conversions.cc index 11042d836bf..a41aa949e64 100644 --- a/util/conversions.cc +++ b/util/conversions.cc @@ -26,6 +26,8 @@ #include "core/print.hh" #include +namespace seastar { + size_t parse_memory_size(std::string s) { size_t factor = 1; if (s.size()) { @@ -41,5 +43,6 @@ size_t parse_memory_size(std::string s) { return boost::lexical_cast(s) * factor; } +} #endif /* CONVERSIONS_CC_ */ diff --git a/util/conversions.hh b/util/conversions.hh index 960085d5577..d3989e260fd 100644 --- a/util/conversions.hh +++ b/util/conversions.hh @@ -26,6 +26,8 @@ #include #include +namespace seastar { + // Convert a string to a memory size, allowing binary SI // suffixes (intentionally, even though SI suffixes are // decimal, to follow existing usage). @@ -44,4 +46,6 @@ static inline std::vector string2vector(std::string str) { return v; } +} + #endif /* CONVERSIONS_HH_ */ diff --git a/util/defer.hh b/util/defer.hh index 60b9b87a862..758b4be8278 100644 --- a/util/defer.hh +++ b/util/defer.hh @@ -22,6 +22,8 @@ #ifndef UTIL_DEFER_HH_ #define UTIL_DEFER_HH_ +namespace seastar { + template class deferred_action { Func _func; @@ -51,4 +53,6 @@ defer(Func&& func) { return deferred_action(std::forward(func)); } +} + #endif /* UTIL_DEFER_HH_ */ diff --git a/util/function_input_iterator.hh b/util/function_input_iterator.hh index 4ffbebca2b8..bdf38e0237b 100644 --- a/util/function_input_iterator.hh +++ b/util/function_input_iterator.hh @@ -22,6 +22,8 @@ #ifndef UTIL_FUNCTION_INPUT_ITERATOR_HH_ #define UTIL_FUNCTION_INPUT_ITERATOR_HH_ +namespace seastar { + template struct function_input_iterator { Function _func; @@ -68,4 +70,6 @@ make_function_input_iterator(Function&& func) { return function_input_iterator(func, State{}); } +} + #endif /* UTIL_FUNCTION_INPUT_ITERATOR_HH_ */ diff --git a/util/indirect.hh b/util/indirect.hh index ac317ada5eb..e544a5f1a1b 100644 --- a/util/indirect.hh +++ b/util/indirect.hh @@ -23,6 +23,8 @@ #include +namespace seastar { + // This header defines functors for comparing and hashing pointers by pointed-to values instead of pointer addresses. // // Examples: @@ -68,3 +70,5 @@ struct indirect_hash { return 0; } }; + +} diff --git a/util/is_smart_ptr.hh b/util/is_smart_ptr.hh index 9a45bc15731..68fb9b9611d 100644 --- a/util/is_smart_ptr.hh +++ b/util/is_smart_ptr.hh @@ -23,8 +23,12 @@ #include // for std::unique_ptr +namespace seastar { + template struct is_smart_ptr : std::false_type {}; template struct is_smart_ptr> : std::true_type {}; + +} diff --git a/util/print_safe.hh b/util/print_safe.hh index 129997997c5..488180c81c2 100644 --- a/util/print_safe.hh +++ b/util/print_safe.hh @@ -23,6 +23,8 @@ #include +namespace seastar { + // // Collection of async-signal safe printing functions. // @@ -107,3 +109,5 @@ void print_decimal_safe(Integral n) noexcept { auto len = convert_decimal_safe(buf, i, n); print_safe(buf, len); } + +} diff --git a/util/spinlock.hh b/util/spinlock.hh index 2c504b5476c..715bab4a932 100644 --- a/util/spinlock.hh +++ b/util/spinlock.hh @@ -24,6 +24,8 @@ #include #include +namespace seastar { + namespace util { // Spin lock implementation. @@ -47,3 +49,5 @@ public: }; } + +} diff --git a/util/transform_iterator.hh b/util/transform_iterator.hh index e726c1c29ed..e7abfabb811 100644 --- a/util/transform_iterator.hh +++ b/util/transform_iterator.hh @@ -22,6 +22,8 @@ #ifndef UTIL_TRANSFORM_ITERATOR_HH_ #define UTIL_TRANSFORM_ITERATOR_HH_ +namespace seastar { + template class transform_iterator { Iterator _i; @@ -53,4 +55,6 @@ make_transform_iterator(Iterator i, Func f) { return transform_iterator(i, f); } +} + #endif /* UTIL_TRANSFORM_ITERATOR_HH_ */