From 87f10dad540971c4aa22d892c676dce590ca189a Mon Sep 17 00:00:00 2001 From: Amlal Date: Sat, 9 Aug 2025 21:54:20 +0200 Subject: feat: move network.hpp to net/ and working on url.hpp Signed-off-by: Amlal --- dev/lib/except/error.hpp | 2 +- dev/lib/fix/network.hpp | 117 ----------------------------------------- dev/lib/fix/parser.hpp | 6 +-- dev/lib/memory/tracked_ptr.hpp | 2 +- dev/lib/net/network.hpp | 117 +++++++++++++++++++++++++++++++++++++++++ dev/lib/net/url.hpp | 8 +++ dev/lib/utility/cgi.hpp | 22 ++++---- dev/lib/utility/embfs.hpp | 8 +-- 8 files changed, 145 insertions(+), 137 deletions(-) delete mode 100644 dev/lib/fix/network.hpp create mode 100644 dev/lib/net/network.hpp create mode 100644 dev/lib/net/url.hpp (limited to 'dev') diff --git a/dev/lib/except/error.hpp b/dev/lib/except/error.hpp index 6e75f16..486d2e6 100644 --- a/dev/lib/except/error.hpp +++ b/dev/lib/except/error.hpp @@ -14,7 +14,7 @@ namespace snu::except using runtime_error = std::runtime_error; using fix_error = runtime_error; using math_error = runtime_error; - using cgi_error = runtime_error; + using cgi_error = runtime_error; } // namespace snu::except #endif // _SNU_ERR_HPP \ No newline at end of file diff --git a/dev/lib/fix/network.hpp b/dev/lib/fix/network.hpp deleted file mode 100644 index edd4c26..0000000 --- a/dev/lib/fix/network.hpp +++ /dev/null @@ -1,117 +0,0 @@ -/* - * File: fix/network.hpp - * Purpose: Financial Information Exchange in C++ - * Author: Amlal El Mahrouss (founder@snu.systems) - * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp. - */ - -#ifndef _SNU_FIX_NETWORK_HPP -#define _SNU_FIX_NETWORK_HPP - -#include -#include -#include -#include - -#define SNU_MODEM : protected snu::fix::basic_delivery_modem - -namespace snu::fix -{ - class basic_delivery_modem; - - typedef int32_t delivery_socket_type; - - /// @brief a delivery modem is a container which establishes a comm. channel between the FIX session and application. - class basic_delivery_modem - { - public: - explicit basic_delivery_modem() = default; - virtual ~basic_delivery_modem() = default; - - basic_delivery_modem& operator=(const basic_delivery_modem&) = default; - basic_delivery_modem(const basic_delivery_modem&) = default; - - public: - static constexpr auto local_address = "127.0.0.1"; - static constexpr auto backlog_count = 18U; - - public: - delivery_socket_type fd_{}; - - template - bool receive(T& out, std::size_t len) noexcept - { - static_assert(std::is_pointer::value, "T is not a pointer!"); - - if (!out) - return false; - - if (!len) - return false; - - auto ret = ::recv(fd_, out, len, MSG_WAITALL); - - return ret > 0; - } - - template - bool transmit(T& out, std::size_t len) noexcept - { - static_assert(std::is_pointer::value, "T is not a pointer!"); - - if (!out) - return false; - - if (!len) - return false; - - auto ret = ::send(fd_, out, len, 0); - - return ret > 0; - } - - template - bool construct(const char* addr = basic_delivery_modem::local_address, const bool& is_server = false) noexcept - { - static_assert(AF != 0, "AF is zero"); - static_assert(Kind != 0, "Kind is zero"); - static_assert(IPProto != 0, "IPProto is zero"); - - fd_ = ::socket(AF, Kind, IPProto); - - if (fd_ < 1) - return false; - - struct sockaddr_in addr_ - { - }; - - addr_.sin_addr.s_addr = ::inet_addr(addr); - addr_.sin_port = Port; - - if (!is_server) - { - auto ret = ::connect(fd_, (struct sockaddr*)&addr_, sizeof(decltype(addr_))); - return ret == 0; - } - - ::listen(fd_, basic_delivery_modem::backlog_count); - - return true; - } - - bool destroy() noexcept - { - if (!fd_) - return false; - - ::shutdown(fd_, SHUT_RDWR); - - fd_ = 0U; - - return true; - } - }; -} // namespace snu::fix - -#endif // ifndef _SNU_FIX_NETWORK_HPP \ No newline at end of file diff --git a/dev/lib/fix/parser.hpp b/dev/lib/fix/parser.hpp index 5701783..f0f7141 100644 --- a/dev/lib/fix/parser.hpp +++ b/dev/lib/fix/parser.hpp @@ -27,7 +27,7 @@ namespace snu::fix struct basic_range; template - struct basic_range_data; + class basic_range_data; /// @brief Buffer+Length structure template @@ -65,7 +65,7 @@ namespace snu::fix bool is_valid() { - return bytes_ && length_ > 0; + return this->bytes_ && this->length_ > 0; } operator bool() @@ -98,7 +98,7 @@ namespace snu::fix static inline const char_type* begin = detail::begin_fix(); explicit basic_range_data() = default; - ~basic_range_data() = default; + ~basic_range_data() = default; basic_range_data& operator=(const basic_range_data&) = default; basic_range_data(const basic_range_data&) = default; diff --git a/dev/lib/memory/tracked_ptr.hpp b/dev/lib/memory/tracked_ptr.hpp index 2607b5b..c767b67 100644 --- a/dev/lib/memory/tracked_ptr.hpp +++ b/dev/lib/memory/tracked_ptr.hpp @@ -128,7 +128,7 @@ namespace snu::memory this->reset(); } - tracked_ptr(const tracked_ptr&) = delete; + tracked_ptr(const tracked_ptr&) = delete; tracked_ptr& operator=(const tracked_ptr&) = delete; public: diff --git a/dev/lib/net/network.hpp b/dev/lib/net/network.hpp new file mode 100644 index 0000000..22cc5b2 --- /dev/null +++ b/dev/lib/net/network.hpp @@ -0,0 +1,117 @@ +/* + * File: net/network.hpp + * Purpose: Modem concept in modern C++ + * Author: Amlal El Mahrouss (founder@snu.systems) + * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp. + */ + +#ifndef _SNU_NET_NETWORK_HPP +#define _SNU_NET_NETWORK_HPP + +#include +#include +#include +#include + +#define SNU_MODEM : protected snu::net::basic_delivery_modem + +namespace snu::net +{ + class basic_delivery_modem; + + typedef int64_t socket_type; + + /// @brief Delivery modem concept, a container to read and write on a network stream. + class basic_delivery_modem + { + public: + explicit basic_delivery_modem() = default; + virtual ~basic_delivery_modem() = default; + + basic_delivery_modem& operator=(const basic_delivery_modem&) = default; + basic_delivery_modem(const basic_delivery_modem&) = default; + + public: + static constexpr auto local_address = "127.0.0.1"; + static constexpr auto backlog_count = 18U; + + public: + socket_type fd_{}; + + template + bool receive(T& out, std::size_t len) noexcept + { + static_assert(std::is_pointer::value, "T is not a pointer!"); + + if (!out) + return false; + + if (!len) + return false; + + auto ret = ::recv(fd_, out, len, MSG_WAITALL); + + return ret > 0; + } + + template + bool transmit(T& out, std::size_t len) noexcept + { + static_assert(std::is_pointer::value, "T is not a pointer!"); + + if (!out) + return false; + + if (!len) + return false; + + auto ret = ::send(fd_, out, len, 0); + + return ret > 0; + } + + template + bool construct(const char* addr = basic_delivery_modem::local_address, const bool& is_server = false) noexcept + { + static_assert(AF != 0, "AF is zero"); + static_assert(Kind != 0, "Kind is zero"); + static_assert(IPProto != 0, "IPProto is zero"); + + fd_ = ::socket(AF, Kind, IPProto); + + if (fd_ < 1) + return false; + + struct sockaddr_in addr_ + { + }; + + addr_.sin_addr.s_addr = ::inet_addr(addr); + addr_.sin_port = Port; + + if (!is_server) + { + auto ret = ::connect(fd_, (struct sockaddr*)&addr_, sizeof(decltype(addr_))); + return ret == 0; + } + + ::listen(fd_, basic_delivery_modem::backlog_count); + + return true; + } + + bool destroy() noexcept + { + if (!fd_) + return false; + + ::shutdown(fd_, SHUT_RDWR); + + fd_ = 0U; + + return true; + } + }; +} // namespace snu::net + +#endif // ifndef _SNU_NET_NETWORK_HPP \ No newline at end of file diff --git a/dev/lib/net/url.hpp b/dev/lib/net/url.hpp new file mode 100644 index 0000000..6c4dc36 --- /dev/null +++ b/dev/lib/net/url.hpp @@ -0,0 +1,8 @@ +/* + * File: net/url.hpp + * Purpose: URL container in modern C++ + * Author: Amlal El Mahrouss (founder@snu.systems) + * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp. + */ + +#pragma once diff --git a/dev/lib/utility/cgi.hpp b/dev/lib/utility/cgi.hpp index 8e2170e..57625b8 100644 --- a/dev/lib/utility/cgi.hpp +++ b/dev/lib/utility/cgi.hpp @@ -32,35 +32,35 @@ namespace snu public: explicit basic_writer() = default; - ~basic_writer() = default; + ~basic_writer() = default; basic_writer& operator=(const basic_writer&) = default; basic_writer(const basic_writer&) = default; public: - basic_writer& binary(const std::basic_stringstream& ss_html) + basic_writer& binary(const std::basic_stringstream& ss_in) { - return this->eval_("application/octet-stream", ss_html); + return this->eval_("application/octet-stream", ss_in); } - basic_writer& html(const std::basic_stringstream& ss_html) + basic_writer& html(const std::basic_stringstream& ss_in) { - return this->eval_("text/html", ss_html); + return this->eval_("text/html", ss_in); } - basic_writer& xml(const std::basic_stringstream& ss_html) + basic_writer& xml(const std::basic_stringstream& ss_in) { - return this->eval_("application/xml", ss_html); + return this->eval_("application/xml", ss_in); } - basic_writer& json(const std::basic_stringstream& ss_html) + basic_writer& json(const std::basic_stringstream& ss_in) { - return this->eval_("application/json", ss_html); + return this->eval_("application/json", ss_in); } - basic_writer& js(const std::basic_stringstream& ss_html) + basic_writer& js(const std::basic_stringstream& ss_in) { - return this->eval_("text/javascript", ss_html); + return this->eval_("text/javascript", ss_in); } }; } // namespace cgi diff --git a/dev/lib/utility/embfs.hpp b/dev/lib/utility/embfs.hpp index fea379c..3acc867 100644 --- a/dev/lib/utility/embfs.hpp +++ b/dev/lib/utility/embfs.hpp @@ -23,10 +23,10 @@ namespace snu::embfs inline constexpr const size_t _superblock_name_len = 16; inline constexpr const size_t _superblock_reserve_len = 462; - - inline constexpr const size_t _inode_name_len = 128; - inline constexpr const size_t _inode_arr_len = 12; - inline constexpr const size_t _inode_lookup_len = 8; + + inline constexpr const size_t _inode_name_len = 128; + inline constexpr const size_t _inode_arr_len = 12; + inline constexpr const size_t _inode_lookup_len = 8; #ifdef EMBFS_28BIT_LBA typedef std::uint32_t lba_t; -- cgit v1.2.3