diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-11-19 03:42:46 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-19 03:42:46 +0100 |
| commit | 3bc2fca2c9beff13586b8bf3089ce439acb09de1 (patch) | |
| tree | 4cf13eb975ef8a133ca0b28de29814c94f7daccc | |
| parent | c9fd682f3662e0eec09de49a36a4ea199656da34 (diff) | |
| parent | b0292253ca9732b228ef505e3e719ae05c07c10c (diff) | |
Merge pull request #12 from amlel-el-mahrouss/develop
New OCL Distrib helpers.
| -rw-r--r-- | .gitignore | 8 | ||||
| -rw-r--r-- | dev/lib/fix/fix.hpp | 5 | ||||
| -rw-r--r-- | dev/lib/memory/allocator_system.hpp | 10 | ||||
| -rw-r--r-- | dev/lib/memory/tracked_ptr.hpp | 8 | ||||
| -rw-r--r-- | dev/lib/net/modem.hpp | 29 | ||||
| -rw-r--r-- | dev/lib/net/url.hpp | 22 | ||||
| -rw-r--r-- | dev/tests/network_basic/net_test.cc | 4 | ||||
| -rwxr-xr-x | make_dist_linux.sh | 17 | ||||
| -rwxr-xr-x | make_dist_osx.sh | 17 | ||||
| -rw-r--r-- | tools/.gitkeep | 0 | ||||
| -rwxr-xr-x | tools/hpptest.py | 2 |
11 files changed, 94 insertions, 28 deletions
@@ -7,12 +7,20 @@ *.o *.obj +dist/* + docs/html docs/latex build*/ build/ +*.aux +*.fdb_latex* +*.fls +*.log +*.gz + .idea # Precompiled Headers diff --git a/dev/lib/fix/fix.hpp b/dev/lib/fix/fix.hpp index 67376e3..d8a3e89 100644 --- a/dev/lib/fix/fix.hpp +++ b/dev/lib/fix/fix.hpp @@ -205,11 +205,14 @@ namespace ocl::fix { if (!basic_range.is_valid()) { - handler.template error<true>("Invalid FIX packet"); + handler.template error<true>("Invalid FIX packet."); } } using fix_tag_type = std::uint32_t; + + using range_data = basic_range_data<char>; + using visitor = basic_visitor<char>; } // namespace ocl::fix #endif // ifndef _OCL_FIX_PARSER_HPP
\ No newline at end of file diff --git a/dev/lib/memory/allocator_system.hpp b/dev/lib/memory/allocator_system.hpp index 1873064..81cd34f 100644 --- a/dev/lib/memory/allocator_system.hpp +++ b/dev/lib/memory/allocator_system.hpp @@ -40,8 +40,8 @@ namespace ocl template <typename ret_type, typename allocator_new, typename allocator_delete> class allocator_system { - allocator_new alloc_; - allocator_delete del_; + allocator_new m_alloc_{}; + allocator_delete m_free_{}; public: allocator_system() = default; @@ -52,18 +52,18 @@ namespace ocl ret_type* claim() noexcept { - return alloc_(); + return m_alloc_(); } template <typename... var_type> auto construct(var_type... args) -> std::shared_ptr<ret_type> { - return std::shared_ptr<ret_type>(alloc_.template var_alloc<var_type...>(args...), allocator_delete{}); + return std::shared_ptr<ret_type>(m_alloc_.template var_alloc<var_type...>(args...), allocator_delete{}); } void unclaim(ret_type* ptr) { - del_(ptr); + m_free_(ptr); } }; diff --git a/dev/lib/memory/tracked_ptr.hpp b/dev/lib/memory/tracked_ptr.hpp index 61daada..bf557d8 100644 --- a/dev/lib/memory/tracked_ptr.hpp +++ b/dev/lib/memory/tracked_ptr.hpp @@ -140,7 +140,7 @@ namespace ocl::memory this->reset(); } - tracked_ptr(const tracked_ptr&) = delete; + tracked_ptr(const tracked_ptr&) = delete; tracked_ptr& operator=(const tracked_ptr&) = delete; public: @@ -224,12 +224,12 @@ namespace ocl::memory } /// @brief a Must Pass function is a standard way to verify a container' validity, inspired from NeKernel/VMKernel. - template <typename T> - inline void must_pass(tracked_ptr<T>& ptr) noexcept + template <typename T, typename error_handler> + inline void must_pass(tracked_ptr<T>& ptr, error_handler handler) { if (ptr.manager().allocator().allocated_count_ < ptr.manager().allocator().deallocated_count_) { - ::kill(::getpid(), SIGTRAP); + handler.template error<true>("Invalid TrackedPtr detected: Deallocated count exceeds allocated count."); } } } // namespace ocl::memory diff --git a/dev/lib/net/modem.hpp b/dev/lib/net/modem.hpp index 7c07191..5bcf3fd 100644 --- a/dev/lib/net/modem.hpp +++ b/dev/lib/net/modem.hpp @@ -16,16 +16,18 @@ #include <string> #include <cstddef> -#define OCL_MODEM_INTERFACE : public ocl::net::basic_modem +#define OCL_MODEM_INTERFACE : public ocl::net::modem namespace ocl::net { - class basic_modem; - - typedef int64_t socket_type; + class modem; + using socket_type = int64_t; + + /// ============================================================================= /// @brief Modem container concept, a container to read and write on a network stream. - class basic_modem + /// ============================================================================= + class modem final { private: socket_type fd_{}; @@ -35,20 +37,25 @@ namespace ocl::net public: const bool& bad{bad_}; - explicit basic_modem() = default; + explicit modem() = default; - virtual ~basic_modem() + ~modem() { this->destroy(); } - basic_modem& operator=(const basic_modem&) = delete; - basic_modem(const basic_modem&) = delete; + modem& operator=(const modem&) = delete; + modem(const modem&) = delete; static constexpr auto local_address_ip4 = "127.0.0.1"; static constexpr auto local_address_ip6 = "::1"; static constexpr const auto backlog_count = 5U; + /// ============================================================================= + /// @brief Check if the modem is valid. + /// @return true if valid, false otherwise. + /// ============================================================================= + bool is_valid() const noexcept { return this->fd_ != -1 && !this->bad_; @@ -107,7 +114,7 @@ namespace ocl::net } template <int32_t af, int32_t kind, int32_t port> - bool construct(const char* addr = basic_modem::local_address_ip4, const bool& is_server = false) noexcept + bool construct(const char* addr = modem::local_address_ip4, const bool& is_server = false) noexcept { static_assert(af != 0, "Address family is zero"); static_assert(kind != 0, "Kind is zero"); @@ -139,7 +146,7 @@ namespace ocl::net bad_ = ret == -1; - ::listen(fd_, basic_modem::backlog_count); + ::listen(fd_, modem::backlog_count); return bad_ == false; } diff --git a/dev/lib/net/url.hpp b/dev/lib/net/url.hpp index b77e790..e4eca2a 100644 --- a/dev/lib/net/url.hpp +++ b/dev/lib/net/url.hpp @@ -33,6 +33,7 @@ namespace ocl::net { url_protocol m_protocol_{url_protocol::invalid}; std::basic_stringstream<char_type> m_ss_{}; + std::basic_string<char_type> m_port_{""}; public: explicit basic_url(const std::basic_string<char_type>& protocol) @@ -65,6 +66,12 @@ namespace ocl::net if (in.empty()) return *this; + if (in.starts_with(":")) + { + m_port_ = in.substr(1); + return *this; + } + m_ss_ += in; return *this; } @@ -81,14 +88,21 @@ namespace ocl::net } public: - bool protocol_exists() + auto protocol() const noexcept { - return this->m_protocol_ != url_protocol::bad || this->m_protocol_ != url_protocol::invalid; + return this->m_protocol_; } - bool is_valid() + auto port() const noexcept { - return m_ss_.size() > 0 && this->protocol_exists(); + return this->m_port_; + } + + auto is_valid() const noexcept + { + return m_ss_.size() > 0 && this->m_protocol_ != url_protocol::bad || this->m_protocol_ != url_protocol::invalid; } }; + + using url = basic_url<char>; } // namespace ocl::net diff --git a/dev/tests/network_basic/net_test.cc b/dev/tests/network_basic/net_test.cc index f8b9f2d..65da7fd 100644 --- a/dev/tests/network_basic/net_test.cc +++ b/dev/tests/network_basic/net_test.cc @@ -12,8 +12,8 @@ TEST(NetworkTest, BasicNetworkUsage) { - ocl::net::basic_modem modem; - modem.construct<AF_INET, SOCK_STREAM, 8000>(ocl::net::basic_modem::local_address_ip4, true); + ocl::net::modem modem; + modem.construct<AF_INET, SOCK_STREAM, 8000>(ocl::net::modem::local_address_ip4, true); EXPECT_TRUE(modem.is_valid()); diff --git a/make_dist_linux.sh b/make_dist_linux.sh new file mode 100755 index 0000000..221b5f4 --- /dev/null +++ b/make_dist_linux.sh @@ -0,0 +1,17 @@ +#! /bin/sh + +outputDir=dist/lib/ + +mkdir -p $outputDir + +for f in dev/lib/*/*.hpp; do +baseName=`echo $f | cut -d "." -f 1` +echo "RUN:" cp --parents $f.hpp $outputDir$baseName +cp --parents $f.hpp $outputDir$baseName +done + +for f in tools/*.py; do +baseName=`echo $f | cut -d "." -f 1` +echo "RUN:" ditto $baseName.py $outputDir$baseName +ditto $baseName.py $outputDir$baseName +done diff --git a/make_dist_osx.sh b/make_dist_osx.sh new file mode 100755 index 0000000..9d91de3 --- /dev/null +++ b/make_dist_osx.sh @@ -0,0 +1,17 @@ +#! /bin/sh + +outputDir=dist/ + +mkdir -p $outputDir + +for f in dev/lib/*/*.hpp; do +baseName=`echo $f | cut -d "." -f 1` +echo "RUN:" ditto $baseName.hpp $outputDir$baseName +ditto $baseName.hpp $outputDir$baseName +done + +for f in tools/*.py; do +baseName=`echo $f | cut -d "." -f 1` +echo "RUN:" ditto $baseName.py $outputDir$baseName +ditto $baseName.py $outputDir$baseName +done diff --git a/tools/.gitkeep b/tools/.gitkeep deleted file mode 100644 index e69de29..0000000 --- a/tools/.gitkeep +++ /dev/null diff --git a/tools/hpptest.py b/tools/hpptest.py index dbed143..218255d 100755 --- a/tools/hpptest.py +++ b/tools/hpptest.py @@ -7,5 +7,5 @@ if __name__ == '__main__': if len(sys.argv) == 3: ret = os.system(f"clang++ -I./dev/ -I{sys.argv[2]} -std=c++20 -DOCL_HPPTEST '-DOCL_HPPTEST_ASSERT(x)=static_assert(x, #x)' {sys.argv[1]}") if ret == 0: - print("[TEST] HEADER COMPILATION PASSES") + print("[HPPTEST] HPPTEST PASSES.") |
