diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 53b37a7..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: C/C++ CI - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - build: - - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - name: get mkn - run: git clone https://github.com/dekken/maiken -b master --depth 10 --recursive - - - name: build mkn - run: cd maiken && make nix && cp mkn .. && cd .. - - - name: mkn - run: KLOG=3 ./mkn - diff --git a/.github/workflows/build_nix.yml b/.github/workflows/build_nix.yml new file mode 100644 index 0000000..325be0b --- /dev/null +++ b/.github/workflows/build_nix.yml @@ -0,0 +1,19 @@ +name: ubuntu-latest + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: "Build/Test" # contains slash so use quotes otherwise UB + run: | + wget https://github.com/PhilipDeegan/mkn/releases/download/latest/mkn_nix + chmod +x mkn_nix + KLOG=3 ./mkn_nix clean build run -dtOp test -a "-std=c++17 -fPIC" -l -pthread diff --git a/.github/workflows/build_osx.yml b/.github/workflows/build_osx.yml new file mode 100644 index 0000000..4f2369e --- /dev/null +++ b/.github/workflows/build_osx.yml @@ -0,0 +1,22 @@ +name: macos-latest + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + runs-on: macos-latest + steps: + - uses: actions/checkout@v2 + + - name: "Build/Test" # contains slash so use quotes otherwise UB + env: + MKN_LIB_LINK_LIB: 1 + run: | + brew install openssl + wget https://github.com/PhilipDeegan/mkn/releases/download/latest/mkn_osx + chmod +x mkn_osx + KLOG=3 ./mkn_osx clean build run -dtOp test -a "-std=c++17 -fPIC" -b /usr/local/opt/openssl@3/include -B /usr/local/opt/openssl@3/lib diff --git a/.github/workflows/build_win.yml b/.github/workflows/build_win.yml new file mode 100644 index 0000000..c6766eb --- /dev/null +++ b/.github/workflows/build_win.yml @@ -0,0 +1,34 @@ +name: windows-latest + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + runs-on: windows-latest + steps: + - uses: actions/checkout@v2 + + - uses: actions/setup-python@v2 + with: + python-version: '3.9.6' # 3.10 is possibly too new + + - name: "Build/Test" + shell: cmd + env: + MKN_CL_PREFERRED: 1 + run: | # /bin/link interferes with cl/link.exe + bash -c "rm /bin/link" + call "C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Auxiliary/Build/vcvars64.bat" + + bash -c "python3 -m pip install wheel --upgrade" + bash -c "python3 -m pip install conan --upgrade" + bash -c "mkdir -p /c/Users/runneradmin/.conan && cp remotes.json /c/Users/runneradmin/.conan/remotes.json" + + bash -c "curl -Lo mkn.exe https://github.com/PhilipDeegan/mkn/releases/download/latest/mkn.exe" + bash -c 'KLOG=3 ./mkn clean build -dtKOp test -a "-EHsc -std:c++17"' + + diff --git a/README.noformat b/README.noformat index fd07dfd..39514ee 100644 --- a/README.noformat +++ b/README.noformat @@ -19,21 +19,21 @@ mkn command for compiling with windows looks like Switches - OSX is considered BSD for swiches unless otherwise noted -Key __KUL_TCP_BIND_SOCKTOPTS__ +Key __MKN_RAM_TCP_BIND_SOCKTOPTS__ Type text Default SO_REUSEADDR OS nix/bsd Description Socket options to use on bind -Key _KUL_HTTPS_CLIENT_METHOD_ +Key _MKN_RAM_HTTPS_CLIENT_METHOD_ Type text Default TLS_client_method OS nix/bsd Description Method to tell SSL server what method is wanted -Key _KUL_HTTPS_SERVER_METHOD_ +Key _MKN_RAM_HTTPS_SERVER_METHOD_ Type text Default TLS_server_method OS nix/bsd @@ -41,12 +41,12 @@ Description Method to tell SSL client is in use -Key _KUL_HTTPS_METHOD_ +Key _MKN_RAM_HTTPS_METHOD_ Type text Default TLS OS nix/bsd Description - Convenience macro, if _KUL_HTTPS_CLIENT_METHOD_ and _KUL_HTTPS_SERVER_METHOD_ are not defined, it is used as the prefix for both i.e.: - -D_KUL_HTTPS_METHOD_=TLS - -D_KUL_HTTPS_METHOD_=TLSv1_2 + Convenience macro, if _MKN_RAM_HTTPS_CLIENT_METHOD_ and _MKN_RAM_HTTPS_SERVER_METHOD_ are not defined, it is used as the prefix for both i.e.: + -D_MKN_RAM_HTTPS_METHOD_=TLS + -D_MKN_RAM_HTTPS_METHOD_=TLSv1_2 diff --git a/appveyor.yml b/appveyor.yml index 5e73aa7..5cb6a9b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -13,11 +13,13 @@ cache: build_script: - SET PATH=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\bin\Hostx64\x64;C:\Program Files\Git\usr\bin;%PATH% - call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat" - - curl -Lo mkn.exe https://github.com/Dekken/maiken/raw/binaries/win10_x64/mkn.exe + - curl -Lo mkn.exe https://github.com/PhilipDeegan/maiken/releases/download/latest/mkn.exe - SET MKN_CL_PREFERRED=1 - SET KLOG=3 - rm "C:\Program Files\Git\usr\bin\link.exe" # messes with msvc link.exe - SET PYTHON=C:\Python37-x64\python.exe - - C:\Python37-x64\Scripts\pip install conan flawfinder + - C:\Python37-x64\Scripts\pip install wheel --upgrade + - C:\Python37-x64\Scripts\pip install conan flawfinder --upgrade + - bash -c "mkdir -p /c/Users/appveyor/.conan && cp remotes.json /c/Users/appveyor/.conan/remotes.json" - mkn clean build -dtKOp usage -a "-EHsc -std:c++17" - - C:\Python37-x64\python C:\Python37-x64\Scripts\flawfinder . + - C:\Python37-x64\Scripts\flawfinder.exe . diff --git a/conanfile.txt b/conanfile.txt index 6e06d3e..94815ef 100644 --- a/conanfile.txt +++ b/conanfile.txt @@ -1,2 +1,2 @@ [requires] -OpenSSL/1.1.0g@conan/stable \ No newline at end of file +OpenSSL/1.1.0k@conan/stable diff --git a/inc/kul/asio/fcgi.hpp b/inc/mkn/ram/asio/fcgi.hpp similarity index 83% rename from inc/kul/asio/fcgi.hpp rename to inc/mkn/ram/asio/fcgi.hpp index a0a699f..c96df95 100644 --- a/inc/kul/asio/fcgi.hpp +++ b/inc/mkn/ram/asio/fcgi.hpp @@ -28,22 +28,23 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _KUL_ASIO_FCGI_HPP_ -#define _KUL_ASIO_FCGI_HPP_ +#ifndef _MKN_RAM_ASIO_FCGI_HPP_ +#define _MKN_RAM_ASIO_FCGI_HPP_ #include -#include "kul/fcgi/def.hpp" -#include "kul/tcp.hpp" -#include "kul/threads.hpp" +#include "mkn/kul/threads.hpp" +#include "mkn/ram/fcgi/def.hpp" +#include "mkn/ram/tcp.hpp" -namespace kul { +namespace mkn { +namespace ram { namespace asio { namespace fcgi { -class Exception : public kul::Exception { +class Exception : public mkn::kul::Exception { public: - Exception(const char* f, const uint16_t& l, const std::string& s) : kul::Exception(f, l, s) {} + Exception(const char* f, const uint16_t& l, const std::string& s) : mkn::kul::Exception(f, l, s) {} }; class Server; @@ -74,34 +75,34 @@ class FCGI_Message { FCGI_Message() {} }; -class Server : public kul::tcp::SocketServer { +class Server : public mkn::ram::tcp::SocketServer { protected: - int fdSize = _KUL_TCP_READ_BUFFER_; + int fdSize = _MKN_RAM_TCP_READ_BUFFER_; uint8_t m_acceptThreads, m_workerThreads; - kul::Mutex m_actex, m_mutex, m_butex, m_mapex; - kul::ChroncurrentThreadPool<> m_acceptPool; - kul::ChroncurrentThreadPool<> m_workerPool; + mkn::kul::Mutex m_actex, m_mutex, m_butex, m_mapex; + mkn::kul::ChroncurrentThreadPool<> m_acceptPool; + mkn::kul::ChroncurrentThreadPool<> m_workerPool; std::unordered_map> msgs; std::unordered_map> inBuffers; protected: uint8_t* getOrCreateBufferFor(const int& fd) { - kul::ScopeLock lock(m_butex); + mkn::kul::ScopeLock lock(m_butex); if (!inBuffers.count(fd)) inBuffers.insert(std::make_pair(fd, std::unique_ptr(new uint8_t[fdSize]))); return inBuffers[fd].get(); } FCGI_Message& createFCGI_Message(const int& fd) { - kul::ScopeLock lock(m_mapex); + mkn::kul::ScopeLock lock(m_mapex); msgs[fd] = std::make_unique(); return *msgs[fd]; } int accept(const uint16_t& fd) override { - kul::ScopeLock lock(m_actex); + mkn::kul::ScopeLock lock(m_actex); return ::accept(lisock, (struct sockaddr*)&cli_addr[fd], &clilen); } @@ -134,12 +135,12 @@ class Server : public kul::tcp::SocketServer { void operateAccept(const size_t& threadID) { std::map fds; fds.insert(std::make_pair(0, 0)); - for (size_t i = threadID; i < _KUL_TCP_MAX_CLIENT_; i += m_acceptThreads) + for (size_t i = threadID; i < _MKN_RAM_TCP_MAX_CLIENT_; i += m_acceptThreads) fds.insert(std::make_pair(i, 0)); while (s) try { - kul::ScopeLock lock(m_mutex); + mkn::kul::ScopeLock lock(m_mutex); loop(fds); - } catch (const kul::tcp::Exception& e1) { + } catch (const mkn::ram::tcp::Exception& e1) { KERR << e1.stack(); } catch (const std::exception& e1) { KERR << e1.what(); @@ -161,11 +162,11 @@ class Server : public kul::tcp::SocketServer { closeFDs(*fds, del); } } - void errorBuffer(const kul::Exception& e) { KERR << e.stack(); }; + void errorBuffer(const mkn::kul::Exception& e) { KERR << e.stack(); }; public: Server(const uint16_t& port, const uint8_t& acceptThreads = 1, const uint8_t& workerThreads = 1) - : kul::tcp::SocketServer(port), + : mkn::ram::tcp::SocketServer(port), m_acceptThreads(acceptThreads), m_workerThreads(workerThreads), m_acceptPool(acceptThreads), @@ -180,7 +181,7 @@ class Server : public kul::tcp::SocketServer { m_workerPool.stop(); } - void start() KTHROW(kul::tcp::Exception) override; + void start() KTHROW(mkn::ram::tcp::Exception) override; void join() { if (!started()) start(); @@ -188,7 +189,7 @@ class Server : public kul::tcp::SocketServer { m_workerPool.join(); } void stop() override { - kul::tcp::SocketServer::stop(); + mkn::ram::tcp::SocketServer::stop(); m_acceptPool.stop(); m_workerPool.stop(); } @@ -200,6 +201,7 @@ class Server : public kul::tcp::SocketServer { } // namespace fcgi } // namespace asio -} // END NAMESPACE kul +} // namespace ram +} // namespace mkn -#endif /* _KUL_ASIO_FCGI_HPP_ */ +#endif /* _MKN_RAM_ASIO_FCGI_HPP_ */ diff --git a/inc/kul/fcgi/def.hpp b/inc/mkn/ram/fcgi/def.hpp similarity index 100% rename from inc/kul/fcgi/def.hpp rename to inc/mkn/ram/fcgi/def.hpp diff --git a/inc/kul/html/def.hpp b/inc/mkn/ram/html/def.hpp similarity index 79% rename from inc/kul/html/def.hpp rename to inc/mkn/ram/html/def.hpp index 329372b..b68e5a4 100644 --- a/inc/kul/html/def.hpp +++ b/inc/mkn/ram/html/def.hpp @@ -28,17 +28,17 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _KUL_HTML_DEF_HPP_ -#define _KUL_HTML_DEF_HPP_ +#ifndef _MKN_RAM_HTML_DEF_HPP_ +#define _MKN_RAM_HTML_DEF_HPP_ -#ifdef _KUL_HTML_FORMAT_ -#define _KUL_HTML_FORMATED_ 1 // boolean for pretty priting HTML +#ifdef _MKN_RAM_HTML_FORMAT_ +#define _MKN_RAM_HTML_FORMATED_ 1 // boolean for pretty priting HTML #else -#define _KUL_HTML_FORMATED_ 0 -#endif /* _KUL_HTML_FORMAT_ */ +#define _MKN_RAM_HTML_FORMATED_ 0 +#endif /* _MKN_RAM_HTML_FORMAT_ */ -#ifndef _KUL_HTML_DOC_TYPE_ -#define _KUL_HTML_DOC_TYPE_ "" -#endif /* _KUL_HTML_DOC_TYPE_ */ +#ifndef _MKN_RAM_HTML_DOC_TYPE_ +#define _MKN_RAM_HTML_DOC_TYPE_ "" +#endif /* _MKN_RAM_HTML_DOC_TYPE_ */ -#endif /* _KUL_HTML_DEF_HPP_ */ +#endif /* _MKN_RAM_HTML_DEF_HPP_ */ diff --git a/inc/kul/html/page.hpp b/inc/mkn/ram/html/page.hpp similarity index 90% rename from inc/kul/html/page.hpp rename to inc/mkn/ram/html/page.hpp index 52acbf9..345e6df 100644 --- a/inc/kul/html/page.hpp +++ b/inc/mkn/ram/html/page.hpp @@ -28,12 +28,13 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _KUL_HTML_PAGE_HPP_ -#define _KUL_HTML_PAGE_HPP_ +#ifndef _MKN_RAM_HTML_PAGE_HPP_ +#define _MKN_RAM_HTML_PAGE_HPP_ -#include "kul/html/tag.hpp" +#include "mkn/ram/html/tag.hpp" -namespace kul { +namespace mkn { +namespace ram { namespace html4 { namespace tag { @@ -80,8 +81,8 @@ class Page { } virtual const std::string* render() { std::stringstream ss; -#if defined(_KUL_HTML_DOC_TYPE_) - ss << _KUL_HTML_DOC_TYPE_ << "\n"; +#if defined(_MKN_RAM_HTML_DOC_TYPE_) + ss << _MKN_RAM_HTML_DOC_TYPE_ << "\n"; #endif ss << ""; ss << *h->render(); @@ -92,7 +93,8 @@ class Page { } }; -} // END NAMESPACE html4 -} // END NAMESPACE kul +} // namespace html4 +} // namespace ram +} // namespace mkn -#endif /* _KUL_HTML_PAGE_HPP_ */ \ No newline at end of file +#endif /* _MKN_RAM_HTML_PAGE_HPP_ */ \ No newline at end of file diff --git a/inc/kul/html/tag.hpp b/inc/mkn/ram/html/tag.hpp similarity index 84% rename from inc/kul/html/tag.hpp rename to inc/mkn/ram/html/tag.hpp index c548e63..e38144b 100644 --- a/inc/kul/html/tag.hpp +++ b/inc/mkn/ram/html/tag.hpp @@ -28,17 +28,18 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _KUL_HTML_TAG_HPP_ -#define _KUL_HTML_TAG_HPP_ +#ifndef _MKN_RAM_HTML_TAG_HPP_ +#define _MKN_RAM_HTML_TAG_HPP_ -#include "kul/except.hpp" -#include "kul/log.hpp" -#include "kul/map.hpp" -#include "kul/string.hpp" +#include "mkn/kul/log.hpp" +#include "mkn/kul/map.hpp" +#include "mkn/kul/except.hpp" +#include "mkn/kul/string.hpp" -#include "kul/html/def.hpp" +#include "mkn/ram/html/def.hpp" -namespace kul { +namespace mkn { +namespace ram { class HTML { private: @@ -77,12 +78,12 @@ class Tag { Tag() {} Tag(const std::string& v) : v(v) {} - virtual const std::string* render(uint16_t tab = _KUL_HTML_FORMATED_) { + virtual const std::string* render(uint16_t tab = _MKN_RAM_HTML_FORMATED_) { std::stringstream ss; -#ifdef _KUL_HTML_FORMAT_ +#ifdef _MKN_RAM_HTML_FORMAT_ ss << "\n"; for (int i = 0; i < tab; i++) ss << "\t"; -#endif /* _KUL_HTML_FORMAT_ */ +#endif /* _MKN_RAM_HTML_FORMAT_ */ ss << "<" << tag(); for (const auto& p : atts) { ss << " " << p.first; @@ -97,18 +98,18 @@ class Tag { if (tags.size()) for (const auto& t : tags) ss << *t->render( -#ifdef _KUL_HTML_FORMAT_ +#ifdef _MKN_RAM_HTML_FORMAT_ tab -#endif /* _KUL_HTML_FORMAT_ */ +#endif /* _MKN_RAM_HTML_FORMAT_ */ ); -#ifdef _KUL_HTML_FORMAT_ +#ifdef _MKN_RAM_HTML_FORMAT_ if (tags.size()) ss << "\n"; if (tags.size()) for (int i = 0; i < tab - 1; i++) ss << "\t"; -#endif /* _KUL_HTML_FORMAT_ */ +#endif /* _MKN_RAM_HTML_FORMAT_ */ if (tags.size() || v.size()) ss << ""; - // #ifdef _KUL_HTML_FORMAT_ - // #endif /* _KUL_HTML_FORMAT_ */ + // #ifdef _MKN_RAM_HTML_FORMAT_ + // #endif /* _MKN_RAM_HTML_FORMAT_ */ str = std::make_unique(ss.str()); return str.get(); } @@ -131,9 +132,9 @@ class Tag { namespace tag { -class Exception : public kul::Exception { +class Exception : public mkn::kul::Exception { public: - Exception(const char* f, const uint16_t& l, const std::string& s) : kul::Exception(f, l, s) {} + Exception(const char* f, const uint16_t& l, const std::string& s) : mkn::kul::Exception(f, l, s) {} }; class Named : public Tag { @@ -286,7 +287,7 @@ class Table : public Tag { cols.push_back(tc); return *tc.get(); } - virtual const std::string* render(uint16_t tab = _KUL_HTML_FORMATED_) { + virtual const std::string* render(uint16_t tab = _MKN_RAM_HTML_FORMATED_) { if (sh) { std::shared_ptr row = std::make_shared(); for (auto& h : cols) row->add(h); @@ -303,45 +304,46 @@ class Table : public Tag { } }; -} // END NAMESPACE tag +} // namespace tag class Text : public Tag { public: Text(const std::string& n) : Tag(n) {} - virtual const std::string* render(uint16_t tab = _KUL_HTML_FORMATED_) { + virtual const std::string* render(uint16_t tab = _MKN_RAM_HTML_FORMATED_) { std::stringstream ss; -#ifdef _KUL_HTML_FORMAT_ +#ifdef _MKN_RAM_HTML_FORMAT_ ss << "\n"; for (uint16_t i = 0; i < tab; i++) ss << "\t"; -#endif /* _KUL_HTML_FORMAT_ */ +#endif /* _MKN_RAM_HTML_FORMAT_ */ ss << v; str = std::make_unique(ss.str()); return str.get(); } }; namespace esc { -class Text : public kul::html4::Text { +class Text : public mkn::ram::html4::Text { public: - Text(const std::string& n) : kul::html4::Text(n) { kul::HTML::ESC(v); } - virtual const std::string* render(uint16_t tab = _KUL_HTML_FORMATED_) { - return kul::html4::Text::render(tab); + Text(const std::string& n) : mkn::ram::html4::Text(n) { mkn::ram::HTML::ESC(v); } + virtual const std::string* render(uint16_t tab = _MKN_RAM_HTML_FORMATED_) { + return mkn::ram::html4::Text::render(tab); } }; } // namespace esc -} // END NAMESPACE html4 -} // END NAMESPACE kul +} // namespace html4 +} // namespace ram +} // namespace mkn -inline kul::html4::Tag& kul::html4::Tag::br() { +inline mkn::ram::html4::Tag& mkn::ram::html4::Tag::br() { tags.push_back(std::make_shared("br")); return *this; } -inline kul::html4::Tag& kul::html4::Tag::esc(const std::string& t) { +inline mkn::ram::html4::Tag& mkn::ram::html4::Tag::esc(const std::string& t) { tags.push_back(std::make_shared(t)); return *this; } -inline kul::html4::Tag& kul::html4::Tag::text(const std::string& t) { +inline mkn::ram::html4::Tag& mkn::ram::html4::Tag::text(const std::string& t) { tags.push_back(std::make_shared(t)); return *this; } -#endif /* _KUL_HTML_TAG_HPP_ */ \ No newline at end of file +#endif /* _MKN_RAM_HTML_TAG_HPP_ */ \ No newline at end of file diff --git a/inc/kul/html4.hpp b/inc/mkn/ram/html4.hpp similarity index 84% rename from inc/kul/html4.hpp rename to inc/mkn/ram/html4.hpp index 8835624..0f95d4d 100644 --- a/inc/kul/html4.hpp +++ b/inc/mkn/ram/html4.hpp @@ -28,20 +28,22 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _KUL_HTML4_HPP_ -#define _KUL_HTML4_HPP_ +#ifndef _MKN_RAM_HTML4_HPP_ +#define _MKN_RAM_HTML4_HPP_ -#include "kul/html/page.hpp" +#include "mkn/ram/html/page.hpp" -namespace kul { +namespace mkn { +namespace ram { namespace html4 { -class Exception : public kul::Exception { +class Exception : public mkn::kul::Exception { public: - Exception(const char* f, const uint16_t& l, const std::string& s) : kul::Exception(f, l, s) {} + Exception(const char* f, const uint16_t& l, const std::string& s) : mkn::kul::Exception(f, l, s) {} }; -} // END NAMESPACE html4 -} // END NAMESPACE kul +} // namespace html4 +} // namespace ram +} // namespace mkn -#endif /* _KUL_HTML_HPP_ */ \ No newline at end of file +#endif /* _MKN_RAM_HTML_HPP_ */ \ No newline at end of file diff --git a/inc/kul/http.hpp b/inc/mkn/ram/http.hpp similarity index 85% rename from inc/kul/http.hpp rename to inc/mkn/ram/http.hpp index 3a61783..97684c1 100644 --- a/inc/kul/http.hpp +++ b/inc/mkn/ram/http.hpp @@ -32,22 +32,23 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // MAY REQUIRE: runas admin - netsh http add urlacl url=http://localhost:666/ // user=EVERYONE listen=yes delegate=no // -#ifndef _KUL_HTTP_HPP_ -#define _KUL_HTTP_HPP_ +#ifndef _MKN_RAM_HTTP_HPP_ +#define _MKN_RAM_HTTP_HPP_ -#include "kul/map.hpp" -#include "kul/string.hpp" -#include "kul/tcp.hpp" +#include "mkn/kul/map.hpp" +#include "mkn/kul/string.hpp" +#include "mkn/ram/tcp.hpp" -namespace kul { +namespace mkn { +namespace ram { namespace http { typedef std::unordered_map Headers; -class Exception : public kul::Exception { +class Exception : public mkn::kul::Exception { public: - Exception(const char* f, const uint16_t& l, const std::string& s) : kul::Exception(f, l, s) {} + Exception(const char* f, const uint16_t& l, const std::string& s) : mkn::kul::Exception(f, l, s) {} }; class Cookie { @@ -110,14 +111,14 @@ class KUL_PUBLISH _1_1Response : public Message { uint16_t _s = 200; std::string r = "OK"; Headers hs; - kul::hash::map::S2T cs; + mkn::kul::hash::map::S2T cs; public: _1_1Response() {} _1_1Response(const std::string& b) { body(b); } virtual ~_1_1Response() {} void cookie(const std::string& k, const Cookie& c) { cs.insert(k, c); } - const kul::hash::map::S2T& cookies() const { return cs; } + const mkn::kul::hash::map::S2T& cookies() const { return cs; } const std::string& reason() const { return r; } void reason(const std::string& r) { this->r = r; } const uint16_t& status() const { return _s; } @@ -139,7 +140,7 @@ class KUL_PUBLISH _1_1Response : public Message { return *this; } virtual _1_1Response& withDefaultHeaders() { - if (!header("Date")) header("Date", kul::DateTime::NOW()); + if (!header("Date")) header("Date", mkn::kul::DateTime::NOW()); if (!header("Connection")) header("Connection", "close"); if (!header("Content-Type")) header("Content-Type", "text/html"); if (!header("Content-Length")) header("Content-Length", std::to_string(body().size())); @@ -157,14 +158,14 @@ class KUL_PUBLISH A1_1Request : public Message { protected: uint16_t _port; std::string _ip, _host, _path; - kul::hash::map::S2S cs, atts; + mkn::kul::hash::map::S2S cs, atts; std::function m_func; virtual void handleResponse(const _1_1Response& s) { if (m_func) m_func(s); else - std::cerr << "kul::http::A1_1Request::handleResponse - no response defined" << std::endl; + std::cerr << "mkn::ram::http::A1_1Request::handleResponse - no response defined" << std::endl; } public: @@ -175,13 +176,13 @@ class KUL_PUBLISH A1_1Request : public Message { virtual std::string method() const = 0; virtual std::string toString() const = 0; void cookie(const std::string& k, const std::string& v) { this->cs.insert(k, v); } - const kul::hash::map::S2S& cookies() const { return cs; } + const mkn::kul::hash::map::S2S& cookies() const { return cs; } A1_1Request& attribute(const std::string& k, const std::string& v) { atts[k] = v; return *this; } - const kul::hash::map::S2S& attributes() const { return atts; } - virtual void send() KTHROW(kul::http::Exception); + const mkn::kul::hash::map::S2S& attributes() const { return atts; } + virtual void send() KTHROW(mkn::ram::http::Exception); const std::string& host() const { return _host; } const std::string& path() const { return _path; } const std::string& ip() const { return _ip; } @@ -226,18 +227,18 @@ class KUL_PUBLISH _1_1PostRequest : public A1_1Request { }; using Post = _1_1PostRequest; -class KUL_PUBLISH AServer : public kul::tcp::SocketServer { +class KUL_PUBLISH AServer : public mkn::ram::tcp::SocketServer { protected: std::function<_1_1Response(const A1_1Request&)> m_func; - void asAttributes(std::string a, kul::hash::map::S2S& atts) { + void asAttributes(std::string a, mkn::kul::hash::map::S2S& atts) { if (a.size() > 0) { if (a[0] == '?') a = a.substr(1); std::vector bits; - kul::String::SPLIT(a, '&', bits); + mkn::kul::String::SPLIT(a, '&', bits); for (const std::string& p : bits) { if (p.find("=") != std::string::npos) { - std::vector bits = kul::String::SPLIT(p, '='); + std::vector bits = mkn::kul::String::SPLIT(p, '='); atts[bits[0]] = bits[1]; } else atts[p] = ""; @@ -252,7 +253,7 @@ class KUL_PUBLISH AServer : public kul::tcp::SocketServer { int& e); public: - AServer(const uint16_t& p) : kul::tcp::SocketServer(p) {} + AServer(const uint16_t& p) : mkn::ram::tcp::SocketServer(p) {} virtual ~AServer() {} AServer& withResponse(const std::function<_1_1Response(const A1_1Request&)>& func) { @@ -262,17 +263,18 @@ class KUL_PUBLISH AServer : public kul::tcp::SocketServer { virtual _1_1Response respond(const A1_1Request& req) { if (m_func) return m_func(req); - KEXCEPTION("kul::http::AServer::respond - no response defined"); + KEXCEPTION("mkn::ram::http::AServer::respond - no response defined"); }; }; -} // END NAMESPACE http -} // END NAMESPACE kul +} // namespace http +} // namespace ram +} // namespace mkn #if defined(_WIN32) -#include "kul/os/win/http.hpp" +#include "mkn/ram/os/win/http.hpp" #else -#include "kul/os/nixish/http.hpp" +#include "mkn/ram/os/nixish/http.hpp" #endif -#endif /* _KUL_HTTP_HPP_ */ +#endif /* _MKN_RAM_HTTP_HPP_ */ diff --git a/inc/kul/http/def.hpp b/inc/mkn/ram/http/def.hpp similarity index 76% rename from inc/kul/http/def.hpp rename to inc/mkn/ram/http/def.hpp index 2c63217..668022b 100644 --- a/inc/kul/http/def.hpp +++ b/inc/mkn/ram/http/def.hpp @@ -28,15 +28,15 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _KUL_HTTP_DEF_HPP_ -#define _KUL_HTTP_DEF_HPP_ +#ifndef _MKN_RAM_HTTP_DEF_HPP_ +#define _MKN_RAM_HTTP_DEF_HPP_ -#ifndef _KUL_HTTP_SESSION_TTL_ -#define _KUL_HTTP_SESSION_TTL_ 600 // seconds -#endif /* _KUL_HTTP_SESSION_TTL_ */ +#ifndef _MKN_RAM_HTTP_SESSION_TTL_ +#define _MKN_RAM_HTTP_SESSION_TTL_ 600 // seconds +#endif /* _MKN_RAM_HTTP_SESSION_TTL_ */ -#ifndef _KUL_HTTP_SESSION_CHECK_ -#define _KUL_HTTP_SESSION_CHECK_ 10000 // milliseconds to sleep between checks -#endif /* _KUL_HTTP_SESSION_CHECK_ */ +#ifndef _MKN_RAM_HTTP_SESSION_CHECK_ +#define _MKN_RAM_HTTP_SESSION_CHECK_ 10000 // milliseconds to sleep between checks +#endif /* _MKN_RAM_HTTP_SESSION_CHECK_ */ -#endif /* _KUL_HTTP_DEF_HPP_ */ +#endif /* _MKN_RAM_HTTP_DEF_HPP_ */ diff --git a/inc/kul/http/session.hpp b/inc/mkn/ram/http/session.hpp similarity index 79% rename from inc/kul/http/session.hpp rename to inc/mkn/ram/http/session.hpp index 73dc1de..1a44bee 100644 --- a/inc/kul/http/session.hpp +++ b/inc/mkn/ram/http/session.hpp @@ -28,15 +28,16 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _KUL_HTTP_SESSION_HPP_ -#define _KUL_HTTP_SESSION_HPP_ +#ifndef _MKN_RAM_HTTP_SESSION_HPP_ +#define _MKN_RAM_HTTP_SESSION_HPP_ -#include "kul/http.hpp" -#include "kul/http/def.hpp" -#include "kul/threads.hpp" -#include "kul/time.hpp" +#include "mkn/ram/http.hpp" +#include "mkn/ram/http/def.hpp" +#include "mkn/kul/threads.hpp" +#include "mkn/kul/time.hpp" -namespace kul { +namespace mkn { +namespace ram { namespace http { template @@ -52,7 +53,7 @@ class Session { void refresh() { if (c != MAX) this->c = std::time(0); } - const bool expired() const { return c < (std::time(0) - _KUL_HTTP_SESSION_TTL_); } + const bool expired() const { return c < (std::time(0) - _MKN_RAM_HTTP_SESSION_TTL_); } void invalidate() { c = MAX; } template friend class SessionServer; @@ -61,18 +62,18 @@ class Session { template class SessionServer { protected: - kul::Mutex mutex; - kul::Thread th1; - kul::hash::map::S2T> sss; + mkn::kul::Mutex mutex; + mkn::kul::Thread th1; + mkn::kul::hash::map::S2T> sss; virtual void operator()() { while (true) { - kul::this_thread::sleep(_KUL_HTTP_SESSION_CHECK_); + mkn::kul::this_thread::sleep(_MKN_RAM_HTTP_SESSION_CHECK_); { auto copy = sss; std::vector erase; for (const auto& p : copy) if (p.second->expired()) erase.push_back(p.first); - kul::ScopeLock lock(mutex); + mkn::kul::ScopeLock lock(mutex); for (const std::string& e : erase) sss.erase(e); } } @@ -85,13 +86,13 @@ class SessionServer { } S* get(const std::string& id) { S* s = 0; - kul::ScopeLock lock(mutex); + mkn::kul::ScopeLock lock(mutex); if (sss.count(id)) s = (*sss.find(id)).second.get(); if (s && !s->expired()) s->c -= 5; return s; } bool has(const std::string& id) { - kul::ScopeLock lock(mutex); + mkn::kul::ScopeLock lock(mutex); if (sss.count(id)) { S& s = *(*sss.find(id)).second.get(); if (!s.expired()) s.c -= 5; @@ -99,23 +100,24 @@ class SessionServer { return sss.count(id); } S& add(const std::string& id, const std::shared_ptr& s) { - kul::ScopeLock lock(mutex); + mkn::kul::ScopeLock lock(mutex); sss.insert(id, s); return *s.get(); } S& add(const std::string& id) { return add(id, std::make_shared()); } void refresh(const std::string& id) { S* s = 0; - kul::ScopeLock lock(mutex); + mkn::kul::ScopeLock lock(mutex); if (sss.count(id)) s = (*sss.find(id)).second.get(); if (s && !s->expired()) (*sss.find(id)).second->refresh(); } void shutdown() { - kul::ScopeLock lock(mutex); + mkn::kul::ScopeLock lock(mutex); th1.interrupt(); } - friend class kul::Thread; + friend class mkn::kul::Thread; }; } // namespace http -} // namespace kul -#endif /* _KUL_HTTP_SESSION_HPP_ */ +} // namespace ram +} // namespace mkn +#endif /* _MKN_RAM_HTTP_SESSION_HPP_ */ diff --git a/inc/kul/https.hpp b/inc/mkn/ram/https.hpp similarity index 76% rename from inc/kul/https.hpp rename to inc/mkn/ram/https.hpp index 457160d..08c9ec8 100644 --- a/inc/kul/https.hpp +++ b/inc/mkn/ram/https.hpp @@ -28,13 +28,28 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _KUL_HTTPS_HPP_ -#define _KUL_HTTPS_HPP_ +#ifndef _MKN_RAM_HTTPS_HPP_ +#define _MKN_RAM_HTTPS_HPP_ + +#include "mkn/kul/except.hpp" + +namespace mkn { +namespace ram { +namespace https { +class Exception : public mkn::kul::Exception { + public: + Exception(const char* f, const uint16_t& l, const std::string& s) : mkn::kul::Exception(f, l, s) {} +}; +} // namespace https +} // namespace ram +} // namespace mkn #if defined(_WIN32) -#include "kul/os/win/https.hpp" +#include "mkn/ram/os/win/https.hpp" #else -#include "kul/os/nixish/https.hpp" +#include "mkn/ram/os/nixish/https.hpp" #endif -#endif //_KUL_INCLUDE_HTTPS_HPP_ + + +#endif //_MKN_RAM_INCLUDE_HTTPS_HPP_ diff --git a/inc/mkn/ram/mpi.hpp b/inc/mkn/ram/mpi.hpp new file mode 100644 index 0000000..5081bbf --- /dev/null +++ b/inc/mkn/ram/mpi.hpp @@ -0,0 +1,177 @@ + +/** +Copyright (c) 2013, Philip Deegan. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Philip Deegan nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#ifndef _MKN_RAM_MPI_HPP_ +#define _MKN_RAM_MPI_HPP_ + +#include "mkn/kul/dbg.hpp" +#include "mpi.h" + +namespace mkn { +namespace mpi { + +class Exception : public mkn::kul::Exception { + public: + Exception(const char* f, const uint16_t& l, const std::string& s) : mkn::kul::Exception(f, l, s) {} +}; + +template +std::vector collect(Data const& data, int mpi_size = 0); + +std::size_t max(std::size_t const local, int mpi_size = 0); + +int size(); + +template +auto getDataType() { + if constexpr (std::is_same_v) + return MPI_DOUBLE; + else if constexpr (std::is_same_v) + return MPI_FLOAT; + else if constexpr (std::is_same_v) + return MPI_INT; + else if constexpr (std::is_same_v) + return MPI_UNSIGNED; + else if constexpr (std::is_same_v) + return MPI_UNSIGNED_SHORT; + else if constexpr (std::is_same_v) + return MPI_UINT64_T; + else if constexpr (std::is_same_v) + return MPI_CHAR; + else + throw std::runtime_error(std::string("Unhandled MPI data type collection: ") + + typeid(Data).name()); +} + +template +void _collect(Data const* const sendbuf, std::vector& rcvBuff, + std::size_t const sendcount = 1, std::size_t const recvcount = 1) { + auto mpi_type = getDataType(); + MPI_Allgather( // MPI_Allgather + sendbuf, // void *sendbuf, + sendcount, // int sendcount, + mpi_type, // MPI_Datatype sendtype, + rcvBuff.data(), // void *recvbuf, + recvcount, // int recvcount, + mpi_type, // MPI_Datatype recvtype, + MPI_COMM_WORLD // MPI_Comm comm + ); +} + +template +void _collect_vector(SendBuff const& sendBuff, RcvBuff& rcvBuff, std::vector const& recvcounts, + std::vector const& displs, int const mpi_size) { + std::vector displs(mpi_size); + for (int i = 0, offset = 0; i < mpi_size; i++) { + displs[i] = offset; + offset += recvcounts[i]; + } + + auto mpi_type = getDataType(); + MPI_Allgatherv( // MPI_Allgatherv + sendBuff.data(), // void *sendbuf, + sendBuff.size(), // int sendcount, + mpi_type, // MPI_Datatype sendtype, + rcvBuff.data(), // void *recvbuf, + recvcounts.data(), // int *recvcounts, + displs.data(), // int *displs, + mpi_type, // MPI_Datatype recvtype, + MPI_COMM_WORLD // MPI_Comm comm + ); +} + +template +std::vector collectVector(Vector const& sendBuff, int mpi_size = 0) { + if (mpi_size == 0) MPI_Comm_size(MPI_COMM_WORLD, &mpi_size); + + std::vector const perMPISize = collect(static_cast(sendBuff.size()), mpi_size); + std::vector const displs = core::displacementFrom(perMPISize); + std::vector rcvBuff(std::accumulate(perMPISize.begin(), perMPISize.end(), 0)); + _collect_vector(sendBuff, rcvBuff, perMPISize, displs, mpi_size); + + std::size_t offset = 0; + std::vector collected; + for (int i = 0; i < mpi_size; i++) { + collected.emplace_back(&rcvBuff[offset], &rcvBuff[offset] + perMPISize[i]); + offset += perMPISize[i]; + } + return collected; +} + +template +SpanSet collectSpanSet(Vector const& sendBuff, int mpi_size = 0) { + if (mpi_size == 0) MPI_Comm_size(MPI_COMM_WORLD, &mpi_size); + + SpanSet rcvBuff{collect(static_cast(sendBuff.size()), mpi_size)}; + _collect_vector(sendBuff, rcvBuff, rcvBuff.sizes(), rcvBuff.displs(), mpi_size); + + return rcvBuff; +} + +template +auto collectArrays(Array const& arr, int mpi_size) { + if (mpi_size == 0) MPI_Comm_size(MPI_COMM_WORLD, &mpi_size); + + std::vector datas(arr.size() * mpi_size); + _collect(arr.data(), datas, arr.size(), arr.size()); + + std::vector values(mpi_size); + for (int i = 0; i < mpi_size; i++) std::memcpy(&values[i], &datas[arr.size() * i], arr.size()); + + return values; +} + +template +SpanSet collect_raw(std::vector const& data, int mpi_size) { + if (mpi_size == 0) MPI_Comm_size(MPI_COMM_WORLD, &mpi_size); + + return collectSpanSet(data, mpi_size); +} + +template +std::vector collect(Data const& data, int mpi_size) { + if (mpi_size == 0) MPI_Comm_size(MPI_COMM_WORLD, &mpi_size); + + if constexpr (std::is_same_v or core::is_std_vector_v) + return collectVector(data, mpi_size); + else if constexpr (core::is_std_array_v) + return collectArrays(data, mpi_size); + else { + std::vector values(mpi_size); + _collect(&data, values); + return values; + } +} + +} // namespace mpi +} // namespace mkn + +#endif //_MKN_RAM_MPI_HPP_ diff --git a/os/nixish/inc/kul/http.hpp b/inc/mkn/ram/os/nixish/http.hpp similarity index 78% rename from os/nixish/inc/kul/http.hpp rename to inc/mkn/ram/os/nixish/http.hpp index f7b9edf..8402e18 100644 --- a/os/nixish/inc/kul/http.hpp +++ b/inc/mkn/ram/os/nixish/http.hpp @@ -28,22 +28,23 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _KUL_HTTP_HPP_ -#define _KUL_HTTP_HPP_ +#ifndef _MKN_RAM_OS_NIXISH_HTTP_HPP_ +#define _MKN_RAM_OS_NIXISH_HTTP_HPP_ #include -#include "kul/http.hpp" -#include "kul/http/def.hpp" -#include "kul/tcp.hpp" -#include "kul/threads.hpp" +#include "mkn/kul/threads.hpp" -namespace kul { +#include "mkn/ram/tcp.hpp" +#include "mkn/ram/http/def.hpp" + +namespace mkn { +namespace ram { namespace http { -class Server : public kul::http::AServer { +class Server : public mkn::ram::http::AServer { private: - int fdSize = _KUL_TCP_READ_BUFFER_; + int fdSize = _MKN_RAM_TCP_READ_BUFFER_; std::unordered_map> inBuffers; protected: @@ -60,12 +61,12 @@ class Server : public kul::http::AServer { virtual ~Server() {} }; -class MultiServer : public kul::http::Server { +class MultiServer : public mkn::ram::http::Server { protected: uint8_t _acceptThreads, _workerThreads; - kul::Mutex m_mutex; - ConcurrentThreadPool<> _acceptPool; - ConcurrentThreadPool<> _workerPool; + mkn::kul::Mutex m_mutex; + mkn::kul::ConcurrentThreadPool<> _acceptPool; + mkn::kul::ConcurrentThreadPool<> _workerPool; virtual void handleBuffer(std::map &fds, int const& fd, char *in, int const& read, int &e) override { @@ -77,23 +78,23 @@ class MultiServer : public kul::http::Server { void operateBuffer(std::map *fds, int const& fd, char *in, int const& read, int &e) { - kul::http::Server::handleBuffer(*fds, fd, in, read, e); + mkn::ram::http::Server::handleBuffer(*fds, fd, in, read, e); if (e <= 0) { std::vector del{fd}; closeFDs(*fds, del); } } - virtual void errorBuffer(const kul::Exception &e) { KERR << e.stack(); }; + virtual void errorBuffer( mkn::kul::Exception const& e) { KERR << e.stack(); }; void operateAccept(size_t const& threadID) { std::map fds; fds.insert(std::make_pair(0, 0)); - for (size_t i = threadID; i < _KUL_TCP_MAX_CLIENT_; i += _acceptThreads) + for (size_t i = threadID; i < _MKN_RAM_TCP_MAX_CLIENT_; i += _acceptThreads) fds.insert(std::make_pair(i, 0)); while (s) try { - kul::ScopeLock lock(m_mutex); + mkn::kul::ScopeLock lock(m_mutex); loop(fds); - } catch (const kul::tcp::Exception &e1) { + } catch (const mkn::ram::tcp::Exception &e1) { KERR << e1.stack(); } catch (const std::exception &e1) { KERR << e1.what(); @@ -113,14 +114,14 @@ class MultiServer : public kul::http::Server { : Server(p), _acceptThreads(acceptThreads), _workerThreads(workerThreads) {} ~MultiServer() { KUL_DBG_FUNC_ENTER } - virtual void start() KTHROW(kul::tcp::Exception) override; + virtual void start() KTHROW(mkn::ram::tcp::Exception) override; virtual void join() { _acceptPool.join(); _workerPool.join(); } virtual void stop() override { - kul::http::Server::stop(); + mkn::ram::http::Server::stop(); _acceptPool.stop(); _workerPool.stop(); } @@ -128,9 +129,10 @@ class MultiServer : public kul::http::Server { _acceptPool.interrupt(); _workerPool.interrupt(); } - const std::exception_ptr &exception() { return _acceptPool.exception(); } + auto& exception() const { return _acceptPool.exception(); } }; } // namespace http -} // namespace kul +} // namespace ram +} // namespace mkn -#endif /* _KUL_HTTP_HPP_ */ +#endif /* _MKN_RAM_OS_NIXISH_HTTP_HPP_ */ diff --git a/inc/kul/os/nixish/https.hpp b/inc/mkn/ram/os/nixish/https.hpp similarity index 70% rename from inc/kul/os/nixish/https.hpp rename to inc/mkn/ram/os/nixish/https.hpp index 3173f53..7b4df43 100644 --- a/inc/kul/os/nixish/https.hpp +++ b/inc/mkn/ram/os/nixish/https.hpp @@ -28,8 +28,8 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _KUL_OS_NIXISH_HTTPS_HPP_ -#define _KUL_OS_NIXISH_HTTPS_HPP_ +#ifndef _MKN_RAM_OS_NIXISH_HTTPS_HPP_ +#define _MKN_RAM_OS_NIXISH_HTTPS_HPP_ #include #include @@ -40,47 +40,49 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#include "kul/http.hpp" -#define KUL_HTTPS_METHOD_APPENDER2(x, y) x##y -#define KUL_HTTPS_METHOD_APPENDER(x, y) KUL_HTTPS_METHOD_APPENDER2(x, y) +#include "mkn/ram/http.hpp" -#if !defined(_KUL_HTTPS_CLIENT_METHOD_) && !defined(_KUL_HTTPS_SERVER_METHOD_) +#define MKN_RAM_HTTPS_METHOD_APPENDER2(x, y) x##y +#define MKN_RAM_HTTPS_METHOD_APPENDER(x, y) MKN_RAM_HTTPS_METHOD_APPENDER2(x, y) -#ifndef _KUL_HTTPS_METHOD_ +#if !defined(_MKN_RAM_HTTPS_CLIENT_METHOD_) && !defined(_MKN_RAM_HTTPS_SERVER_METHOD_) + +#ifndef _MKN_RAM_HTTPS_METHOD_ #if OPENSSL_VERSION_NUMBER < 0x10100000L -#define _KUL_HTTPS_METHOD_ DTLS +#define _MKN_RAM_HTTPS_METHOD_ DTLS #else -#define _KUL_HTTPS_METHOD_ TLS +#define _MKN_RAM_HTTPS_METHOD_ TLS #endif /* OPENSSL_VERSION_NUMBER < 0x10100000L */ -#endif /* _KUL_HTTPS_METHOD_ */ +#endif /* _MKN_RAM_HTTPS_METHOD_ */ -#define _KUL_HTTPS_CLIENT_METHOD_ KUL_HTTPS_METHOD_APPENDER(_KUL_HTTPS_METHOD_, _client_method) -#define _KUL_HTTPS_SERVER_METHOD_ KUL_HTTPS_METHOD_APPENDER(_KUL_HTTPS_METHOD_, _server_method) +#define _MKN_RAM_HTTPS_CLIENT_METHOD_ MKN_RAM_HTTPS_METHOD_APPENDER(_MKN_RAM_HTTPS_METHOD_, _client_method) +#define _MKN_RAM_HTTPS_SERVER_METHOD_ MKN_RAM_HTTPS_METHOD_APPENDER(_MKN_RAM_HTTPS_METHOD_, _server_method) #else -#ifndef _KUL_HTTPS_CLIENT_METHOD_ -#define _KUL_HTTPS_CLIENT_METHOD_ TLS_client_method -#endif /* _KUL_HTTPS_CLIENT_METHOD_ */ -#ifndef _KUL_HTTPS_SERVER_METHOD_ -#define _KUL_HTTPS_SERVER_METHOD_ TLS_server_method -#endif /* _KUL_HTTPS_SERVER_METHOD_ */ +#ifndef _MKN_RAM_HTTPS_CLIENT_METHOD_ +#define _MKN_RAM_HTTPS_CLIENT_METHOD_ TLS_client_method +#endif /* _MKN_RAM_HTTPS_CLIENT_METHOD_ */ +#ifndef _MKN_RAM_HTTPS_SERVER_METHOD_ +#define _MKN_RAM_HTTPS_SERVER_METHOD_ TLS_server_method +#endif /* _MKN_RAM_HTTPS_SERVER_METHOD_ */ #endif /* defined xyz */ -namespace kul { +namespace mkn { +namespace ram { namespace https { -class Server : public kul::http::Server { +class Server : public mkn::ram::http::Server { protected: X509 *cc = {0}; - SSL *ssl_clients[_KUL_TCP_MAX_CLIENT_] = {0}; + SSL *ssl_clients[_MKN_RAM_TCP_MAX_CLIENT_] = {0}; SSL_CTX *ctx = {0}; - kul::File crt, key; + mkn::kul::File crt, key; const std::string cs; - virtual void loop(std::map &fds) KTHROW(kul::tcp::Exception) override; + virtual void loop(std::map &fds) KTHROW(mkn::ram::tcp::Exception) override; virtual bool receive(std::map &fds, int const& fd) override; @@ -88,36 +90,36 @@ class Server : public kul::http::Server { int &e) override; public: - Server(const short &p, const kul::File &c, const kul::File &k, std::string const& cs = "") - : kul::http::Server(p), crt(c), key(k), cs(cs) {} - Server(const kul::File &c, const kul::File &k, std::string const& cs = "") - : kul::https::Server(443, c, k, cs) {} + Server(const short &p, const mkn::kul::File &c, const mkn::kul::File &k, std::string const& cs = "") + : mkn::ram::http::Server(p), crt(c), key(k), cs(cs) {} + Server(const mkn::kul::File &c, const mkn::kul::File &k, std::string const& cs = "") + : mkn::ram::https::Server(443, c, k, cs) {} virtual ~Server() { if (s) stop(); } - void setChain(const kul::File &f); + void setChain(const mkn::kul::File &f); Server &init(); virtual void stop() override; }; -class MultiServer : public kul::https::Server { +class MultiServer : public mkn::ram::https::Server { protected: uint8_t _acceptThreads, _workerThreads; std::mutex m_mutex; - ChroncurrentThreadPool<> _acceptPool; - ChroncurrentThreadPool<> _workerPool; + mkn::kul::ChroncurrentThreadPool<> _acceptPool; + mkn::kul::ChroncurrentThreadPool<> _workerPool; void operateAccept(size_t const& threadID) { KUL_DBG_FUNC_ENTER std::map fds; fds.insert(std::make_pair(0, 0)); - for (size_t i = threadID; i < _KUL_TCP_MAX_CLIENT_; i += _acceptThreads) + for (size_t i = threadID; i < _MKN_RAM_TCP_MAX_CLIENT_; i += _acceptThreads) fds.insert(std::make_pair(i, 0)); while (s) try { - // kul::ScopeLock lock(m_mutex); + // mkn::kul::ScopeLock lock(m_mutex); std::lock_guard lock(m_mutex); loop(fds); - } catch (const kul::tcp::Exception &e1) { + } catch (const mkn::ram::tcp::Exception &e1) { KERR << e1.stack(); } catch (const std::exception &e1) { KERR << e1.what(); @@ -140,7 +142,7 @@ class MultiServer : public kul::https::Server { void operateBuffer(std::map *fds, int const& fd, char *in, int const& read, int &e) { KUL_DBG_FUNC_ENTER - kul::https::Server::handleBuffer(*fds, fd, in, read, e); + mkn::ram::https::Server::handleBuffer(*fds, fd, in, read, e); if (e <= 0) { getpeername(m_fds[fd].fd, (struct sockaddr *)&cli_addr, (socklen_t *)&clilen); KOUT(DBG) << "DISCO " @@ -151,12 +153,12 @@ class MultiServer : public kul::https::Server { closeFDs(*fds, del); } } - virtual void errorBuffer(const kul::Exception &e) { KERR << e.stack(); }; + virtual void errorBuffer(const mkn::kul::Exception &e) { KERR << e.stack(); }; public: MultiServer(const short &p, const uint8_t &acceptThreads, const uint8_t &workerThreads, - const kul::File &c, const kul::File &k, std::string const& cs = "") - : kul::https::Server(p, c, k, cs), + const mkn::kul::File &c, const mkn::kul::File &k, std::string const& cs = "") + : mkn::ram::https::Server(p, c, k, cs), _acceptThreads(acceptThreads), _workerThreads(workerThreads), _acceptPool(acceptThreads), @@ -165,8 +167,8 @@ class MultiServer : public kul::https::Server { KEXCEPTION("MultiServer cannot have less than one threads for accepting"); if (workerThreads < 1) KEXCEPTION("MultiServer cannot have less than one threads for working"); } - MultiServer(const uint8_t &acceptThreads, const uint8_t &workerThreads, const kul::File &c, - const kul::File &k, std::string const& cs = "") + MultiServer(const uint8_t &acceptThreads, const uint8_t &workerThreads, const mkn::kul::File &c, + const mkn::kul::File &k, std::string const& cs = "") : MultiServer(443, acceptThreads, workerThreads, c, k, cs) {} virtual ~MultiServer() { @@ -174,14 +176,14 @@ class MultiServer : public kul::https::Server { _workerPool.stop(); } - virtual void start() KTHROW(kul::tcp::Exception) override; + virtual void start() KTHROW(mkn::ram::tcp::Exception) override; virtual void join() { _acceptPool.join(); _workerPool.join(); } virtual void stop() override { - kul::https::Server::stop(); + mkn::ram::https::Server::stop(); _acceptPool.stop(); _workerPool.stop(); } @@ -204,7 +206,7 @@ class SSLReqHelper { SSL_library_init(); SSL_load_error_strings(); OpenSSL_add_all_algorithms(); - ctx = SSL_CTX_new(_KUL_HTTPS_CLIENT_METHOD_()); + ctx = SSL_CTX_new(_MKN_RAM_HTTPS_CLIENT_METHOD_()); if (ctx == NULL) { ERR_print_errors_fp(stderr); abort(); @@ -236,7 +238,7 @@ class _1_1GetRequest : public http::_1_1GetRequest, https::A1_1Request { _1_1GetRequest(std::string const& host, std::string const& path = "", uint16_t const& port = 443) : http::_1_1GetRequest(host, path, port) {} virtual ~_1_1GetRequest() {} - virtual void send() KTHROW(kul::http::Exception) override; + virtual void send() KTHROW(mkn::ram::http::Exception) override; }; using Get = _1_1GetRequest; @@ -244,9 +246,10 @@ class _1_1PostRequest : public http::_1_1PostRequest, https::A1_1Request { public: _1_1PostRequest(std::string const& host, std::string const& path = "", uint16_t const& port = 443) : http::_1_1PostRequest(host, path, port) {} - virtual void send() KTHROW(kul::http::Exception) override; + virtual void send() KTHROW(mkn::ram::http::Exception) override; }; using Post = _1_1PostRequest; } // namespace https -} // namespace kul -#endif //_KUL_INCLUDE_HTTPS_HPP_ +} // namespace ram +} // namespace mkn +#endif //_MKN_RAM_INCLUDE_HTTPS_HPP_ diff --git a/inc/kul/os/nixish/tcp.hpp b/inc/mkn/ram/os/nixish/tcp.hpp similarity index 86% rename from inc/kul/os/nixish/tcp.hpp rename to inc/mkn/ram/os/nixish/tcp.hpp index 6346564..431d819 100644 --- a/inc/kul/os/nixish/tcp.hpp +++ b/inc/mkn/ram/os/nixish/tcp.hpp @@ -28,8 +28,8 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _KUL_OS_NIXISH_TCP_HPP_ -#define _KUL_OS_NIXISH_TCP_HPP_ +#ifndef _MKN_RAM_OS_NIXISH_TCP_HPP_ +#define _MKN_RAM_OS_NIXISH_TCP_HPP_ #include #include @@ -44,16 +44,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#include "kul/byte.hpp" -#include "kul/log.hpp" -#include "kul/tcp/def.hpp" -#include "kul/time.hpp" +#include "mkn/kul/byte.hpp" +#include "mkn/kul/log.hpp" +#include "mkn/ram/tcp/def.hpp" +#include "mkn/kul/time.hpp" -#ifndef __KUL_TCP_BIND_SOCKTOPTS__ -#define __KUL_TCP_BIND_SOCKTOPTS__ SO_REUSEADDR -#endif //__KUL_TCP_BIND_SOCKTOPTS__ +#ifndef __MKN_RAM_TCP_BIND_SOCKTOPTS__ +#define __MKN_RAM_TCP_BIND_SOCKTOPTS__ SO_REUSEADDR +#endif //__MKN_RAM_TCP_BIND_SOCKTOPTS__ -namespace kul { +namespace mkn { +namespace ram { namespace tcp { template @@ -84,7 +85,7 @@ class Socket : public ASocket { bool more = false; return read(data, len, more); } - virtual size_t read(T *data, size_t const& len, bool &more) KTHROW(kul::tcp::Exception) override { + virtual size_t read(T *data, size_t const& len, bool &more) KTHROW(mkn::ram::tcp::Exception) override { KUL_DBG_FUNC_ENTER struct timeval tv; fd_set fds; @@ -166,7 +167,7 @@ class Socket : public ASocket { servAddr.sin_family = AF_INET; int16_t e = 0; servAddr.sin_port = - !kul::byte::isBigEndian() ? htons(port) : kul::byte::LittleEndian::UINT32(port); + !kul::byte::isBigEndian() ? htons(port) : mkn::kul::byte::LittleEndian::UINT32(port); if (host == "localhost" || host == "127.0.0.1") { servAddr.sin_addr.s_addr = INADDR_ANY; e = ::connect(sck, (struct sockaddr *)&servAddr, sizeof(servAddr)); @@ -203,9 +204,9 @@ class SocketServer : public ASocketServer { bool s = 0; int lisock = 0, nfds = 12; int64_t _started; - struct pollfd m_fds[_KUL_TCP_MAX_CLIENT_]; + struct pollfd m_fds[_MKN_RAM_TCP_MAX_CLIENT_]; socklen_t clilen; - struct sockaddr_in serv_addr, cli_addr[_KUL_TCP_MAX_CLIENT_]; + struct sockaddr_in serv_addr, cli_addr[_MKN_RAM_TCP_MAX_CLIENT_]; virtual bool handle(T *const in, size_t const& inLen, T *const out, size_t &outLen) { // default overridable function @@ -220,10 +221,10 @@ class SocketServer : public ASocketServer { size_t size = 0; int64_t val = 0; while (1) { - val = ::recv(m_fds[fd].fd, in + size, _KUL_TCP_READ_BUFFER_ - (size + 1), + val = ::recv(m_fds[fd].fd, in + size, _MKN_RAM_TCP_READ_BUFFER_ - (size + 1), MSG_PEEK | MSG_DONTWAIT); if (val < 0) break; - size += ::recv(m_fds[fd].fd, in + size, _KUL_TCP_READ_BUFFER_ - (size + 1), opts); + size += ::recv(m_fds[fd].fd, in + size, _MKN_RAM_TCP_READ_BUFFER_ - (size + 1), opts); } return size; } @@ -233,8 +234,8 @@ class SocketServer : public ASocketServer { virtual bool receive(std::map &fds, int const& fd) { (void)fds; KUL_DBG_FUNC_ENTER - T in[_KUL_TCP_READ_BUFFER_]; - bzero(in, _KUL_TCP_READ_BUFFER_); + T in[_MKN_RAM_TCP_READ_BUFFER_]; + bzero(in, _MKN_RAM_TCP_READ_BUFFER_); int16_t e = 0, read = readFrom(fd, in); if (read < 0 && errno != EWOULDBLOCK) KEXCEPTION("Socket Server error on recv - fd(" + std::to_string(fd) + @@ -249,12 +250,12 @@ class SocketServer : public ASocketServer { bool cl = 1; in[read] = '\0'; try { - T out[_KUL_TCP_READ_BUFFER_]; - bzero(out, _KUL_TCP_READ_BUFFER_); + T out[_MKN_RAM_TCP_READ_BUFFER_]; + bzero(out, _MKN_RAM_TCP_READ_BUFFER_); size_t outLen; cl = handle(in, read, out, outLen); e = writeTo(fd, out, outLen); - } catch (const kul::tcp::Exception &e1) { + } catch (const mkn::ram::tcp::Exception &e1) { KERR << e1.stack(); e = -1; } @@ -275,7 +276,7 @@ class SocketServer : public ASocketServer { virtual void closeFDs(std::map &fds, std::vector &del) { closeFDsNoCompress(fds, del); } - virtual void loop(std::map &fds) KTHROW(kul::tcp::Exception) { + virtual void loop(std::map &fds) KTHROW(mkn::ram::tcp::Exception) { // KUL_DBG_FUNC_ENTER auto ret = poll(); if (!s) return; @@ -315,7 +316,7 @@ class SocketServer : public ASocketServer { virtual int poll(int timeout = 10) { auto p = ::poll(m_fds, nfds, timeout); if (errno == 11) { - kul::this_thread::sleep(timeout); + mkn::kul::this_thread::sleep(timeout); return 0; } else if (errno == 2 || errno == 17 || errno == 32) { // skip @@ -341,14 +342,14 @@ class SocketServer : public ASocketServer { } public: - SocketServer(uint16_t const& p, bool _bind = 1) : kul::tcp::ASocketServer(p) { - if (_bind) bind(__KUL_TCP_BIND_SOCKTOPTS__); + SocketServer(uint16_t const& p, bool _bind = 1) : mkn::ram::tcp::ASocketServer(p) { + if (_bind) bind(__MKN_RAM_TCP_BIND_SOCKTOPTS__); memset(m_fds, 0, sizeof(m_fds)); } ~SocketServer() { - for (int i = 0; i < _KUL_TCP_MAX_CLIENT_; i++) ::close(m_fds[i].fd); + for (int i = 0; i < _MKN_RAM_TCP_MAX_CLIENT_; i++) ::close(m_fds[i].fd); } - virtual void bind(int sockOpt = __KUL_TCP_BIND_SOCKTOPTS__) KTHROW(kul::Exception) { + virtual void bind(int sockOpt = __MKN_RAM_TCP_BIND_SOCKTOPTS__) KTHROW(kul::Exception) { lisock = socket(AF_INET, SOCK_STREAM, 0); int iso = 1; int rc = setsockopt(lisock, SOL_SOCKET, sockOpt, (char *)&iso, sizeof(iso)); @@ -368,16 +369,16 @@ class SocketServer : public ASocketServer { serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = INADDR_ANY; serv_addr.sin_port = !kul::byte::isBigEndian() ? htons(this->port()) - : kul::byte::LittleEndian::UINT32(this->port()); + : mkn::kul::byte::LittleEndian::UINT32(this->port()); int16_t e = 0; if ((e = ::bind(lisock, (struct sockaddr *)&serv_addr, sizeof(serv_addr))) < 0) { KERR << std::to_string(errno) << " - " << std::string(strerror(errno)); KEXCEPTION("Socket Server error on binding, errno: " + std::to_string(errno)); } } - virtual void start() KTHROW(kul::tcp::Exception) { + virtual void start() KTHROW(mkn::ram::tcp::Exception) { KUL_DBG_FUNC_ENTER - _started = kul::Now::MILLIS(); + _started = mkn::kul::Now::MILLIS(); auto ret = listen(lisock, 256); if (ret < 0) KEXCEPTION("Socket Server error on listen"); clilen = sizeof(cli_addr[0]); @@ -386,10 +387,10 @@ class SocketServer : public ASocketServer { m_fds[0].events = POLLIN; //|POLLPRI; nfds = lisock + 1; std::map fds; - for (size_t i = 0; i < _KUL_TCP_MAX_CLIENT_; i++) fds.insert(std::make_pair(i, 0)); + for (size_t i = 0; i < _MKN_RAM_TCP_MAX_CLIENT_; i++) fds.insert(std::make_pair(i, 0)); try { while (s) loop(fds); - } catch (const kul::tcp::Exception &e1) { + } catch (const mkn::ram::tcp::Exception &e1) { KERR << e1.stack(); } catch (const std::exception &e1) { KERR << e1.what(); @@ -401,12 +402,13 @@ class SocketServer : public ASocketServer { KUL_DBG_FUNC_ENTER s = 0; ::close(lisock); - for (int i = 0; i < _KUL_TCP_MAX_CLIENT_; i++) + for (int i = 0; i < _MKN_RAM_TCP_MAX_CLIENT_; i++) if (i != lisock) shutdown(i, SHUT_RDWR); } }; -} // END NAMESPACE tcp -} // END NAMESPACE kul +} // namespace tcp +} // namespace ram +} // namespace mkn -#endif //_KUL_OS_NIXISH_TCP_HPP_ +#endif //_MKN_RAM_OS_NIXISH_TCP_HPP_ diff --git a/inc/kul/os/win/http.hpp b/inc/mkn/ram/os/win/http.hpp similarity index 80% rename from inc/kul/os/win/http.hpp rename to inc/mkn/ram/os/win/http.hpp index e766596..29395ae 100644 --- a/inc/kul/os/win/http.hpp +++ b/inc/mkn/ram/os/win/http.hpp @@ -32,15 +32,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // MAY REQUIRE: runas admin - netsh http add urlacl url=http://localhost:666/ // user=EVERYONE listen=yes delegate=no // -#ifndef _KUL_OS_WIN_HTTP_HPP_ -#define _KUL_OS_WIN_HTTP_HPP_ +#ifndef _MKN_RAM_OS_WIN_HTTP_HPP_ +#define _MKN_RAM_OS_WIN_HTTP_HPP_ #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif -#include "kul/log.hpp" -#include "kul/threads.hpp" +#include "mkn/kul/log.hpp" +#include "mkn/kul/threads.hpp" #ifndef UNICODE #define UNICODE @@ -59,12 +59,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #pragma comment(lib, "httpapi.lib") #pragma comment(lib, "ws2_32.lib") -namespace kul { +namespace mkn { +namespace ram { namespace http { -class Server : public kul::http::AServer { +class Server : public mkn::ram::http::AServer { private: - int fdSize = _KUL_TCP_READ_BUFFER_; + int fdSize = _MKN_RAM_TCP_READ_BUFFER_; std::unordered_map> inBuffers; protected: @@ -81,12 +82,12 @@ class Server : public kul::http::AServer { virtual ~Server() {} }; -class KUL_PUBLISH MultiServer : public kul::http::Server { +class KUL_PUBLISH MultiServer : public mkn::ram::http::Server { protected: uint8_t _acceptThreads, _workerThreads; - kul::Mutex m_mutex; - ChroncurrentThreadPool<> _acceptPool; - ChroncurrentThreadPool<> _workerPool; + mkn::kul::Mutex m_mutex; + mkn::kul::ChroncurrentThreadPool<> _acceptPool; + mkn::kul::ChroncurrentThreadPool<> _workerPool; virtual void handleBuffer(std::map& fds, const int& fd, char* in, const int& read, int& e) override { @@ -98,23 +99,23 @@ class KUL_PUBLISH MultiServer : public kul::http::Server { void operateBuffer(std::map* fds, const int& fd, char* in, const int& read, int& e) { - kul::http::Server::handleBuffer(*fds, fd, in, read, e); + mkn::ram::http::Server::handleBuffer(*fds, fd, in, read, e); if (e < 0) { std::vector del{fd}; // closeFDs(*fds, del); } } - virtual void errorBuffer(const kul::Exception& e) { KERR << e.stack(); }; + virtual void errorBuffer(const mkn::kul::Exception& e) { KERR << e.stack(); }; void operateAccept(const size_t& threadID) { std::map fds; fds.insert(std::make_pair(0, 0)); - for (int i = threadID; i < _KUL_TCP_MAX_CLIENT_; i += _acceptThreads) + for (int i = threadID; i < _MKN_RAM_TCP_MAX_CLIENT_; i += _acceptThreads) fds.insert(std::make_pair(i, 0)); while (s) try { - kul::ScopeLock lock(m_mutex); + mkn::kul::ScopeLock lock(m_mutex); loop(fds); - } catch (const kul::tcp::Exception& e1) { + } catch (const mkn::ram::tcp::Exception& e1) { KERR << e1.stack(); } catch (const std::exception& e1) { KERR << e1.what(); @@ -128,14 +129,14 @@ class KUL_PUBLISH MultiServer : public kul::http::Server { const uint8_t& workerThreads = 1) : Server(p), _acceptThreads(acceptThreads), _workerThreads(workerThreads) {} - virtual void start() KTHROW(kul::tcp::Exception) override; + virtual void start() KTHROW(mkn::ram::tcp::Exception) override; virtual void join() { _acceptPool.join(); _workerPool.join(); } virtual void stop() override { - kul::http::Server::stop(); + mkn::ram::http::Server::stop(); _acceptPool.stop(); _workerPool.stop(); } @@ -146,7 +147,8 @@ class KUL_PUBLISH MultiServer : public kul::http::Server { const std::exception_ptr& exception() { return _acceptPool.exception(); } }; -} // END NAMESPACE http -} // END NAMESPACE kul +} // namespace http +} // namespace ram +} // namespace mkn -#endif /* _KUL_OS_WIN_HTTP_HPP_ */ +#endif /* _MKN_RAM_OS_WIN_HTTP_HPP_ */ diff --git a/inc/kul/os/win/https.hpp b/inc/mkn/ram/os/win/https.hpp similarity index 68% rename from inc/kul/os/win/https.hpp rename to inc/mkn/ram/os/win/https.hpp index d348b04..e636d27 100644 --- a/inc/kul/os/win/https.hpp +++ b/inc/mkn/ram/os/win/https.hpp @@ -28,8 +28,8 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _KUL_OS_WIN_HTTPS_HPP_ -#define _KUL_OS_WIN_HTTPS_HPP_ +#ifndef _MKN_RAM_OS_WIN_HTTPS_HPP_ +#define _MKN_RAM_OS_WIN_HTTPS_HPP_ #include #include @@ -39,43 +39,44 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#include "kul/http.hpp" +#include "mkn/ram/http.hpp" -#define KUL_HTTPS_METHOD_APPENDER2(x, y) x##y -#define KUL_HTTPS_METHOD_APPENDER(x, y) KUL_HTTPS_METHOD_APPENDER2(x, y) +#define MKN_RAM_HTTPS_METHOD_APPENDER2(x, y) x##y +#define MKN_RAM_HTTPS_METHOD_APPENDER(x, y) MKN_RAM_HTTPS_METHOD_APPENDER2(x, y) -#if !defined(_KUL_HTTPS_CLIENT_METHOD_) && !defined(_KUL_HTTPS_SERVER_METHOD_) +#if !defined(_MKN_RAM_HTTPS_CLIENT_METHOD_) && !defined(_MKN_RAM_HTTPS_SERVER_METHOD_) -#ifndef _KUL_HTTPS_METHOD_ -#define _KUL_HTTPS_METHOD_ TLS -#endif /* _KUL_HTTPS_METHOD_ */ +#ifndef _MKN_RAM_HTTPS_METHOD_ +#define _MKN_RAM_HTTPS_METHOD_ TLS +#endif /* _MKN_RAM_HTTPS_METHOD_ */ -#define _KUL_HTTPS_CLIENT_METHOD_ KUL_HTTPS_METHOD_APPENDER(_KUL_HTTPS_METHOD_, _client_method) -#define _KUL_HTTPS_SERVER_METHOD_ KUL_HTTPS_METHOD_APPENDER(_KUL_HTTPS_METHOD_, _server_method) +#define _MKN_RAM_HTTPS_CLIENT_METHOD_ MKN_RAM_HTTPS_METHOD_APPENDER(_MKN_RAM_HTTPS_METHOD_, _client_method) +#define _MKN_RAM_HTTPS_SERVER_METHOD_ MKN_RAM_HTTPS_METHOD_APPENDER(_MKN_RAM_HTTPS_METHOD_, _server_method) #else -#ifndef _KUL_HTTPS_CLIENT_METHOD_ -#define _KUL_HTTPS_CLIENT_METHOD_ TLS_client_method -#endif /* _KUL_HTTPS_CLIENT_METHOD_ */ -#ifndef _KUL_HTTPS_SERVER_METHOD_ -#define _KUL_HTTPS_SERVER_METHOD_ TLS_server_method -#endif /* _KUL_HTTPS_SERVER_METHOD_ */ +#ifndef _MKN_RAM_HTTPS_CLIENT_METHOD_ +#define _MKN_RAM_HTTPS_CLIENT_METHOD_ TLS_client_method +#endif /* _MKN_RAM_HTTPS_CLIENT_METHOD_ */ +#ifndef _MKN_RAM_HTTPS_SERVER_METHOD_ +#define _MKN_RAM_HTTPS_SERVER_METHOD_ TLS_server_method +#endif /* _MKN_RAM_HTTPS_SERVER_METHOD_ */ #endif /* defined xyz */ -namespace kul { +namespace mkn { +namespace ram { namespace https { -class Server : public kul::http::Server { +class Server : public mkn::ram::http::Server { protected: X509* cc = {0}; - SSL* ssl_clients[_KUL_TCP_MAX_CLIENT_] = {0}; + SSL* ssl_clients[_MKN_RAM_TCP_MAX_CLIENT_] = {0}; SSL_CTX* ctx = {0}; - kul::File crt, key; + mkn::kul::File crt, key; const std::string cs; - virtual KUL_PUBLISH void loop(std::map& fds) KTHROW(kul::tcp::Exception) override; + virtual KUL_PUBLISH void loop(std::map& fds) KTHROW(mkn::ram::tcp::Exception) override; virtual KUL_PUBLISH bool receive(std::map& fds, const int& fd) override; @@ -83,34 +84,34 @@ class Server : public kul::http::Server { const int& read, int& e); public: - Server(const short& p, const kul::File& c, const kul::File& k, const std::string& cs = "") - : kul::http::Server(p), crt(c), key(k), cs(cs) {} - Server(const kul::File& c, const kul::File& k, const std::string& cs = "") - : kul::https::Server(443, c, k, cs) {} + Server(const short& p, const mkn::kul::File& c, const mkn::kul::File& k, const std::string& cs = "") + : mkn::ram::http::Server(p), crt(c), key(k), cs(cs) {} + Server(mkn::kul::File const& c, mkn::kul::File const& k, std::string const& cs = "") + : mkn::ram::https::Server(443, c, k, cs) {} virtual ~Server() { if (s) stop(); } - KUL_PUBLISH void setChain(const kul::File& f); + KUL_PUBLISH void setChain(const mkn::kul::File& f); KUL_PUBLISH Server& init(); KUL_PUBLISH virtual void stop() override; }; -class KUL_PUBLISH MultiServer : public kul::https::Server { +class KUL_PUBLISH MultiServer : public mkn::ram::https::Server { protected: uint8_t _acceptThreads, _workerThreads; - kul::Mutex m_mutex; - ChroncurrentThreadPool<> _acceptPool; - ChroncurrentThreadPool<> _workerPool; + mkn::kul::Mutex m_mutex; + mkn::kul::ChroncurrentThreadPool<> _acceptPool; + mkn::kul::ChroncurrentThreadPool<> _workerPool; void operateAccept(const size_t& threadID) { std::map fds; fds.insert(std::make_pair(0, 0)); - for (size_t i = threadID; i < _KUL_TCP_MAX_CLIENT_; i += _acceptThreads) + for (size_t i = threadID; i < _MKN_RAM_TCP_MAX_CLIENT_; i += _acceptThreads) fds.insert(std::make_pair(i, 0)); while (s) try { - kul::ScopeLock lock(m_mutex); + mkn::kul::ScopeLock lock(m_mutex); loop(fds); - } catch (const kul::tcp::Exception& e1) { + } catch (const mkn::ram::tcp::Exception& e1) { KERR << e1.stack(); } catch (const std::exception& e1) { KERR << e1.what(); @@ -129,18 +130,18 @@ class KUL_PUBLISH MultiServer : public kul::https::Server { void operateBuffer(std::map* fds, const int& fd, char* in, const int& read, int& e) { - kul::https::Server::handleBuffer(*fds, fd, in, read, e); + mkn::ram::https::Server::handleBuffer(*fds, fd, in, read, e); if (e < 0) { std::vector del{fd}; closeFDs(*fds, del); } } - virtual void errorBuffer(const kul::Exception& e) { KERR << e.stack(); }; + virtual void errorBuffer(const mkn::kul::Exception& e) { KERR << e.stack(); }; public: MultiServer(const short& p, const uint8_t& acceptThreads, const uint8_t& workerThreads, - const kul::File& c, const kul::File& k, const std::string& cs = "") - : kul::https::Server(p, c, k, cs), + const mkn::kul::File& c, const mkn::kul::File& k, const std::string& cs = "") + : mkn::ram::https::Server(p, c, k, cs), _acceptThreads(acceptThreads), _workerThreads(workerThreads), _acceptPool(acceptThreads), @@ -149,8 +150,8 @@ class KUL_PUBLISH MultiServer : public kul::https::Server { KEXCEPTION("MultiServer cannot have less than one threads for accepting"); if (workerThreads < 1) KEXCEPTION("MultiServer cannot have less than one threads for working"); } - MultiServer(const uint8_t& acceptThreads, const uint8_t& workerThreads, const kul::File& c, - const kul::File& k, const std::string& cs = "") + MultiServer(const uint8_t& acceptThreads, const uint8_t& workerThreads, const mkn::kul::File& c, + const mkn::kul::File& k, const std::string& cs = "") : MultiServer(443, acceptThreads, workerThreads, c, k, cs) {} virtual ~MultiServer() { @@ -158,14 +159,14 @@ class KUL_PUBLISH MultiServer : public kul::https::Server { _workerPool.stop(); } - virtual void start() KTHROW(kul::tcp::Exception) override; + virtual void start() KTHROW(mkn::ram::tcp::Exception) override; virtual void join() { _acceptPool.join(); _workerPool.join(); } virtual void stop() override { - kul::https::Server::stop(); + mkn::ram::https::Server::stop(); _acceptPool.stop(); _workerPool.stop(); } @@ -188,7 +189,7 @@ class SSLReqHelper { SSL_library_init(); SSL_load_error_strings(); OpenSSL_add_all_algorithms(); - ctx = SSL_CTX_new(_KUL_HTTPS_CLIENT_METHOD_()); + ctx = SSL_CTX_new(_MKN_RAM_HTTPS_CLIENT_METHOD_()); if (ctx == NULL) { ERR_print_errors_fp(stderr); abort(); @@ -220,7 +221,7 @@ class _1_1GetRequest : public http::_1_1GetRequest, https::A1_1Request { _1_1GetRequest(const std::string& host, const std::string& path = "", const uint16_t& port = 443) : http::_1_1GetRequest(host, path, port) {} virtual ~_1_1GetRequest() {} - virtual void send() KTHROW(kul::http::Exception) override; + virtual void send() KTHROW(mkn::ram::http::Exception) override; }; using Get = _1_1GetRequest; @@ -228,9 +229,10 @@ class _1_1PostRequest : public http::_1_1PostRequest, https::A1_1Request { public: _1_1PostRequest(const std::string& host, const std::string& path = "", const uint16_t& port = 443) : http::_1_1PostRequest(host, path, port) {} - virtual void send() KTHROW(kul::http::Exception) override; + virtual void send() KTHROW(mkn::ram::http::Exception) override; }; using Post = _1_1PostRequest; } // namespace https -} // namespace kul -#endif //_KUL_INCLUDE_HTTPS_HPP_ +} // namespace ram +} // namespace mkn +#endif //_MKN_RAM_INCLUDE_HTTPS_HPP_ diff --git a/inc/kul/os/win/tcp.hpp b/inc/mkn/ram/os/win/tcp.hpp similarity index 89% rename from inc/kul/os/win/tcp.hpp rename to inc/mkn/ram/os/win/tcp.hpp index 457acc1..16b354b 100644 --- a/inc/kul/os/win/tcp.hpp +++ b/inc/mkn/ram/os/win/tcp.hpp @@ -28,10 +28,10 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _KUL_OS_WIN_TCP_HPP_ -#define _KUL_OS_WIN_TCP_HPP_ +#ifndef _MKN_RAM_OS_WIN_TCP_HPP_ +#define _MKN_RAM_OS_WIN_TCP_HPP_ -#include "kul/tcp/def.hpp" +#include "mkn/ram/tcp/def.hpp" #undef UNICODE #define WIN32_LEAN_AND_MEAN @@ -50,7 +50,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #pragma comment(lib, "Mswsock.lib") #pragma comment(lib, "AdvApi32.lib") -namespace kul { +namespace mkn { +namespace ram { namespace tcp { template @@ -160,7 +161,7 @@ class SocketServer : public ASocketServer { int64_t _started; WSADATA wsaData; - WSAPOLLFD m_fds[_KUL_TCP_MAX_CLIENT_]; + WSAPOLLFD m_fds[_MKN_RAM_TCP_MAX_CLIENT_]; SOCKET lisock = INVALID_SOCKET; SOCKET ClientSocket = INVALID_SOCKET; @@ -169,14 +170,14 @@ class SocketServer : public ASocketServer { struct addrinfo hints; socklen_t clilen; - struct sockaddr_in serv_addr, cli_addr[_KUL_TCP_MAX_CLIENT_]; + struct sockaddr_in serv_addr, cli_addr[_MKN_RAM_TCP_MAX_CLIENT_]; virtual bool handle(T* const in, const size_t& inLen, T* const out, size_t& outLen) { return true; } virtual int readFrom(const int& fd, T* in, int opts = 0) { - return ::recv(m_fds[fd].fd, in, _KUL_TCP_READ_BUFFER_ - 1, opts); + return ::recv(m_fds[fd].fd, in, _MKN_RAM_TCP_READ_BUFFER_ - 1, opts); } virtual int writeTo(const int& fd, const T* const out, size_t size) { return ::send(m_fds[fd].fd, out, size, 0); @@ -184,16 +185,16 @@ class SocketServer : public ASocketServer { virtual bool receive(std::map& fds, const int& fd) { KUL_DBG_FUNC_ENTER - T in[_KUL_TCP_READ_BUFFER_]; - ZeroMemory(in, _KUL_TCP_READ_BUFFER_); + T in[_MKN_RAM_TCP_READ_BUFFER_]; + ZeroMemory(in, _MKN_RAM_TCP_READ_BUFFER_); bool cl; do { cl = 0; - iResult = recv(ClientSocket, in, _KUL_TCP_READ_BUFFER_ - 1, 0); + iResult = recv(ClientSocket, in, _MKN_RAM_TCP_READ_BUFFER_ - 1, 0); if (iResult > 0) { - T out[_KUL_TCP_READ_BUFFER_]; - ZeroMemory(out, _KUL_TCP_READ_BUFFER_); + T out[_MKN_RAM_TCP_READ_BUFFER_]; + ZeroMemory(out, _MKN_RAM_TCP_READ_BUFFER_); size_t outLen; cl = handle(in, iResult, out, outLen); auto sent = writeTo(ClientSocket, out, strlen(out)); @@ -222,7 +223,7 @@ class SocketServer : public ASocketServer { virtual void closeFDs(std::map& fds, std::vector& del) { closeFDsNoCompress(fds, del); } - virtual void loop(std::map& fds) KTHROW(kul::tcp::Exception) { + virtual void loop(std::map& fds) KTHROW(mkn::ram::tcp::Exception) { auto ret = poll(); if (!s) return; if (ret < 0) @@ -282,8 +283,8 @@ class SocketServer : public ASocketServer { } public: - SocketServer(const uint16_t& p, bool _bind = 1) : kul::tcp::ASocketServer(p) { - // if(_bind) bind(__KUL_TCP_BIND_SOCKTOPTS__); + SocketServer(const uint16_t& p, bool _bind = 1) : mkn::ram::tcp::ASocketServer(p) { + // if(_bind) bind(__MKN_RAM_TCP_BIND_SOCKTOPTS__); } void freeaddrinfo() { if (!result) return; @@ -296,10 +297,10 @@ class SocketServer : public ASocketServer { if (ClientSocket) closesocket(ClientSocket); WSACleanup(); } - virtual void bind(int sockOpt = __KUL_TCP_BIND_SOCKTOPTS__) KTHROW(kul::Exception) {} - virtual void start() KTHROW(kul::tcp::Exception) { + virtual void bind(int sockOpt = __MKN_RAM_TCP_BIND_SOCKTOPTS__) KTHROW(kul::Exception) {} + virtual void start() KTHROW(mkn::ram::tcp::Exception) { KUL_DBG_FUNC_ENTER - _started = kul::Now::MILLIS(); + _started = mkn::kul::Now::MILLIS(); iResult = WSAStartup(MAKEWORD(2, 2), &wsaData); if (iResult != 0) KEXCEPTION("WSAStartup failed with error: ") << iResult; @@ -336,10 +337,10 @@ class SocketServer : public ASocketServer { s = true; std::map fds; - for (int i = 0; i < _KUL_TCP_MAX_CLIENT_; i++) fds.insert(std::make_pair(i, 0)); + for (int i = 0; i < _MKN_RAM_TCP_MAX_CLIENT_; i++) fds.insert(std::make_pair(i, 0)); try { while (s) loop(fds); - } catch (const kul::tcp::Exception& e1) { + } catch (const mkn::ram::tcp::Exception& e1) { KERR << e1.stack(); } catch (const std::exception& e1) { KERR << e1.what(); @@ -357,7 +358,8 @@ class SocketServer : public ASocketServer { } }; -} // END NAMESPACE tcp -} // END NAMESPACE kul +} // namespace tcp +} // namespace ram +} // namespace mkn -#endif //_KUL_OS_WIN_TCP_HPP_ +#endif //_MKN_RAM_OS_WIN_TCP_HPP_ diff --git a/inc/kul/tcp.hpp b/inc/mkn/ram/tcp.hpp similarity index 81% rename from inc/kul/tcp.hpp rename to inc/mkn/ram/tcp.hpp index 8b1897e..cf76659 100644 --- a/inc/kul/tcp.hpp +++ b/inc/mkn/ram/tcp.hpp @@ -28,16 +28,18 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _KUL_TCP_HPP_ -#define _KUL_TCP_HPP_ +#ifndef _MKN_RAM_TCP_HPP_ +#define _MKN_RAM_TCP_HPP_ -#include "kul/dbg.hpp" +#include "mkn/kul/dbg.hpp" -namespace kul { namespace tcp { +namespace mkn { +namespace ram { +namespace tcp { -class Exception : public kul::Exception { +class Exception : public mkn::kul::Exception { public: - Exception(const char* f, const uint16_t& l, const std::string& s) : kul::Exception(f, l, s) {} + Exception(const char* f, const uint16_t& l, const std::string& s) : mkn::kul::Exception(f, l, s) {} }; template @@ -46,7 +48,7 @@ class ASocket { virtual ~ASocket() {} virtual bool connect(const std::string& host, const int16_t& port) = 0; virtual bool close() = 0; - virtual size_t read(T* data, const size_t& len, bool& more) KTHROW(kul::tcp::Exception) = 0; + virtual size_t read(T* data, const size_t& len, bool& more) KTHROW(mkn::ram::tcp::Exception) = 0; virtual size_t write(const T* data, const size_t& len) = 0; protected: @@ -57,8 +59,8 @@ template class ASocketServer { public: virtual ~ASocketServer() {} - virtual void start() KTHROW(kul::tcp::Exception) = 0; - uint64_t up() const { return s - kul::Now::MILLIS(); } + virtual void start() KTHROW(mkn::ram::tcp::Exception) = 0; + uint64_t up() const { return s - mkn::kul::Now::MILLIS(); } const uint16_t& port() const { return p; } bool started() const { return s; } @@ -73,14 +75,15 @@ class ASocketServer { uint64_t s; }; -} // END NAMESPACE tcp -} // END NAMESPACE kul +} // namespace tcp +} // namespace ram +} // namespace mkn #if defined(_WIN32) -#include "kul/os/win/tcp.hpp" +#include "mkn/ram/os/win/tcp.hpp" #else -#include "kul/os/nixish/tcp.hpp" +#include "mkn/ram/os/nixish/tcp.hpp" #endif -#endif //_KUL_TCP_HPP_ +#endif //_MKN_RAM_TCP_HPP_ diff --git a/inc/kul/tcp/def.hpp b/inc/mkn/ram/tcp/def.hpp similarity index 66% rename from inc/kul/tcp/def.hpp rename to inc/mkn/ram/tcp/def.hpp index 11c13c4..bc6f898 100644 --- a/inc/kul/tcp/def.hpp +++ b/inc/mkn/ram/tcp/def.hpp @@ -28,31 +28,31 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _KUL_TCP_DEF_HPP_ -#define _KUL_TCP_DEF_HPP_ +#ifndef _MKN_RAM_TCP_DEF_HPP_ +#define _MKN_RAM_TCP_DEF_HPP_ -#ifndef _KUL_TCP_SESSION_TTL_ -#define _KUL_TCP_SESSION_TTL_ 600 // seconds -#endif /* _KUL_TCP_SESSION_TTL_ */ +#ifndef _MKN_RAM_TCP_SESSION_TTL_ +#define _MKN_RAM_TCP_SESSION_TTL_ 600 // seconds +#endif /* _MKN_RAM_TCP_SESSION_TTL_ */ -#ifndef _KUL_TCP_SESSION_CHECK_ -#define _KUL_TCP_SESSION_CHECK_ 10000 // milliseconds to sleep between checks -#endif /* _KUL_TCP_SESSION_CHECK_ */ +#ifndef _MKN_RAM_TCP_SESSION_CHECK_ +#define _MKN_RAM_TCP_SESSION_CHECK_ 10000 // milliseconds to sleep between checks +#endif /* _MKN_RAM_TCP_SESSION_CHECK_ */ -#ifndef _KUL_TCP_READ_BUFFER_ -#define _KUL_TCP_READ_BUFFER_ 963210 -#endif /* _KUL_TCP_READ_BUFFER_ */ +#ifndef _MKN_RAM_TCP_READ_BUFFER_ +#define _MKN_RAM_TCP_READ_BUFFER_ 963210 +#endif /* _MKN_RAM_TCP_READ_BUFFER_ */ -#ifndef _KUL_TCP_MAX_CLIENT_ -#define _KUL_TCP_MAX_CLIENT_ 4096 -#endif /* _KUL_TCP_MAX_CLIENT_ */ +#ifndef _MKN_RAM_TCP_MAX_CLIENT_ +#define _MKN_RAM_TCP_MAX_CLIENT_ 4096 +#endif /* _MKN_RAM_TCP_MAX_CLIENT_ */ -#ifndef _KUL_TCP_REQUEST_BUFFER_ -#define _KUL_TCP_REQUEST_BUFFER_ 963210 -#endif /* _KUL_TCP_REQUEST_BUFFER_ */ +#ifndef _MKN_RAM_TCP_REQUEST_BUFFER_ +#define _MKN_RAM_TCP_REQUEST_BUFFER_ 963210 +#endif /* _MKN_RAM_TCP_REQUEST_BUFFER_ */ #ifdef _WIN32 #define bzero ZeroMemory #endif -#endif /* _KUL_TCP_DEF_HPP_ */ +#endif /* _MKN_RAM_TCP_DEF_HPP_ */ diff --git a/lgtm.yml b/lgtm.yml index 043715f..937fa79 100644 --- a/lgtm.yml +++ b/lgtm.yml @@ -4,7 +4,7 @@ extraction: packages: "build-essential" configure: command: - - git clone https://github.com/Dekken/maiken -b master --depth 1 maiken + - git clone https://github.com/PhilipDeegan/maiken -b master --depth 1 maiken - cd maiken; make nix; mv mkn ..; cd ..; rm -rf maiken index: build_command: ./mkn diff --git a/mkn.yaml b/mkn.yaml index a499c74..2513409 100644 --- a/mkn.yaml +++ b/mkn.yaml @@ -21,12 +21,12 @@ profile: - name: https parent: lib - arg: -D_KUL_INCLUDE_HTTPS_ + arg: -D_MKN_RAM_INCLUDE_HTTPS_ if_mod: win: - name: conan.install init: - install: -s compiler="Visual Studio" -s compiler.version=15 + install: -s compiler="Visual Studio" if_lib: nix: ssl crypto bsd: ssl crypto @@ -39,7 +39,7 @@ profile: - name: usage self: https main: usage.cpp - arg: -D_KUL_INCLUDE_HTTPS_ + arg: -D_MKN_RAM_INCLUDE_HTTPS_ if_link: win_cl: -nodefaultlib:libucrt.lib ucrt.lib @@ -49,6 +49,7 @@ profile: - name: test self: https + mode: none main: test.cpp - name: test.client @@ -66,4 +67,4 @@ profile: style: file types: cpp:cxx:cc:h:hpp paths: . - args: -D_KUL_INCLUDE_HTTPS_ + args: -D_MKN_RAM_INCLUDE_HTTPS_ diff --git a/inc/kul/os/nixish/http.hpp b/os/nixish/inc/mkn/ram/http.hpp similarity index 83% rename from inc/kul/os/nixish/http.hpp rename to os/nixish/inc/mkn/ram/http.hpp index 3890cb8..1d8b4d8 100644 --- a/inc/kul/os/nixish/http.hpp +++ b/os/nixish/inc/mkn/ram/http.hpp @@ -28,21 +28,24 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _KUL_OS_NIXISH_HTTP_HPP_ -#define _KUL_OS_NIXISH_HTTP_HPP_ +#ifndef _MKN_RAM_NIXISH_HTTP_HPP_ +#define _MKN_RAM_NIXISH_HTTP_HPP_ #include -#include "kul/http/def.hpp" -#include "kul/tcp.hpp" -#include "kul/threads.hpp" +#include "mkn/ram/http.hpp" +#include "mkn/kul/http/def.hpp" +#include "mkn/ram/tcp.hpp" -namespace kul { +#include "mkn/kul/threads.hpp" + +namespace mkn { +namespace ram { namespace http { -class Server : public kul::http::AServer { +class Server : public mkn::ram::http::AServer { private: - int fdSize = _KUL_TCP_READ_BUFFER_; + int fdSize = _MKN_RAM_TCP_READ_BUFFER_; std::unordered_map> inBuffers; protected: @@ -59,10 +62,10 @@ class Server : public kul::http::AServer { virtual ~Server() {} }; -class MultiServer : public kul::http::Server { +class MultiServer : public mkn::ram::http::Server { protected: uint8_t _acceptThreads, _workerThreads; - kul::Mutex m_mutex; + mkn::kul::Mutex m_mutex; ConcurrentThreadPool<> _acceptPool; ConcurrentThreadPool<> _workerPool; @@ -76,23 +79,23 @@ class MultiServer : public kul::http::Server { void operateBuffer(std::map *fds, int const& fd, char *in, int const& read, int &e) { - kul::http::Server::handleBuffer(*fds, fd, in, read, e); + mkn::ram::http::Server::handleBuffer(*fds, fd, in, read, e); if (e <= 0) { std::vector del{fd}; closeFDs(*fds, del); } } - virtual void errorBuffer(const kul::Exception &e) { KERR << e.stack(); }; + virtual void errorBuffer(const mkn::kul::Exception &e) { KERR << e.stack(); }; void operateAccept(size_t const& threadID) { std::map fds; fds.insert(std::make_pair(0, 0)); - for (size_t i = threadID; i < _KUL_TCP_MAX_CLIENT_; i += _acceptThreads) + for (size_t i = threadID; i < _MKN_RAM_TCP_MAX_CLIENT_; i += _acceptThreads) fds.insert(std::make_pair(i, 0)); while (s) try { - kul::ScopeLock lock(m_mutex); + mkn::kul::ScopeLock lock(m_mutex); loop(fds); - } catch (const kul::tcp::Exception &e1) { + } catch (const mkn::ram::tcp::Exception &e1) { KERR << e1.stack(); } catch (const std::exception &e1) { KERR << e1.what(); @@ -119,7 +122,7 @@ class MultiServer : public kul::http::Server { _workerPool.join(); } virtual void stop() override { - kul::http::Server::stop(); + mkn::ram::http::Server::stop(); _acceptPool.stop(); _workerPool.stop(); } @@ -130,6 +133,7 @@ class MultiServer : public kul::http::Server { const std::exception_ptr &exception() { return _acceptPool.exception(); } }; } // namespace http +} // namespace ram } // namespace kul -#endif /* _KUL_OS_NIXISH_HTTP_HPP_ */ +#endif /* _MKN_RAM_NIXISH_HTTP_HPP_ */ diff --git a/os/nixish/inc/kul/https.hpp b/os/nixish/inc/mkn/ram/https.hpp similarity index 74% rename from os/nixish/inc/kul/https.hpp rename to os/nixish/inc/mkn/ram/https.hpp index fdbc193..6bc532c 100644 --- a/os/nixish/inc/kul/https.hpp +++ b/os/nixish/inc/mkn/ram/https.hpp @@ -28,8 +28,8 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _KUL_HTTPS_HPP_ -#define _KUL_HTTPS_HPP_ +#ifndef _MKN_RAM_NIXISH_HTTPS_HPP_ +#define _MKN_RAM_NIXISH_HTTPS_HPP_ #include #include @@ -40,44 +40,44 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#include "kul/http.hpp" +#include "mkn/ram/http.hpp" -#define KUL_HTTPS_METHOD_APPENDER2(x, y) x##y -#define KUL_HTTPS_METHOD_APPENDER(x, y) KUL_HTTPS_METHOD_APPENDER2(x, y) +#define MKN_RAM_HTTPS_METHOD_APPENDER2(x, y) x##y +#define MKN_RAM_HTTPS_METHOD_APPENDER(x, y) MKN_RAM_HTTPS_METHOD_APPENDER2(x, y) -#if !defined(_KUL_HTTPS_CLIENT_METHOD_) && !defined(_KUL_HTTPS_SERVER_METHOD_) +#if !defined(_MKN_RAM_HTTPS_CLIENT_METHOD_) && !defined(_MKN_RAM_HTTPS_SERVER_METHOD_) -#ifndef _KUL_HTTPS_METHOD_ +#ifndef _MKN_RAM_HTTPS_METHOD_ #if OPENSSL_VERSION_NUMBER < 0x10100000L -#define _KUL_HTTPS_METHOD_ DTLS +#define _MKN_RAM_HTTPS_METHOD_ DTLS #else -#define _KUL_HTTPS_METHOD_ TLS +#define _MKN_RAM_HTTPS_METHOD_ TLS #endif /* OPENSSL_VERSION_NUMBER < 0x10100000L */ -#endif /* _KUL_HTTPS_METHOD_ */ +#endif /* _MKN_RAM_HTTPS_METHOD_ */ -#define _KUL_HTTPS_CLIENT_METHOD_ KUL_HTTPS_METHOD_APPENDER(_KUL_HTTPS_METHOD_, _client_method) -#define _KUL_HTTPS_SERVER_METHOD_ KUL_HTTPS_METHOD_APPENDER(_KUL_HTTPS_METHOD_, _server_method) +#define _MKN_RAM_HTTPS_CLIENT_METHOD_ MKN_RAM_HTTPS_METHOD_APPENDER(_MKN_RAM_HTTPS_METHOD_, _client_method) +#define _MKN_RAM_HTTPS_SERVER_METHOD_ MKN_RAM_HTTPS_METHOD_APPENDER(_MKN_RAM_HTTPS_METHOD_, _server_method) #else -#ifndef _KUL_HTTPS_CLIENT_METHOD_ -#define _KUL_HTTPS_CLIENT_METHOD_ TLS_client_method -#endif /* _KUL_HTTPS_CLIENT_METHOD_ */ -#ifndef _KUL_HTTPS_SERVER_METHOD_ -#define _KUL_HTTPS_SERVER_METHOD_ TLS_server_method -#endif /* _KUL_HTTPS_SERVER_METHOD_ */ +#ifndef _MKN_RAM_HTTPS_CLIENT_METHOD_ +#define _MKN_RAM_HTTPS_CLIENT_METHOD_ TLS_client_method +#endif /* _MKN_RAM_HTTPS_CLIENT_METHOD_ */ +#ifndef _MKN_RAM_HTTPS_SERVER_METHOD_ +#define _MKN_RAM_HTTPS_SERVER_METHOD_ TLS_server_method +#endif /* _MKN_RAM_HTTPS_SERVER_METHOD_ */ #endif /* defined xyz */ -namespace kul { +namespace mkn { namespace https { -class Server : public kul::http::Server { +class Server : public mkn::ram::http::Server { protected: X509 *cc = {0}; - SSL *ssl_clients[_KUL_TCP_MAX_CLIENT_] = {0}; + SSL *ssl_clients[_MKN_RAM_TCP_MAX_CLIENT_] = {0}; SSL_CTX *ctx = {0}; - kul::File crt, key; + mkn::kul::File crt, key; std::string const cs; virtual void loop(std::map &fds) KTHROW(kul::tcp::Exception) override; @@ -88,10 +88,10 @@ class Server : public kul::http::Server { int &e) override; public: - Server(const short &p, kul::File const& c, kul::File const& k, std::string const& cs = "") - : kul::http::Server(p), crt(c), key(k), cs(cs) {} - Server(kul::File const& c, kul::File const& k, std::string const& cs = "") - : kul::https::Server(443, c, k, cs) {} + Server(const short &p, mkn::kul::File const& c, mkn::kul::File const& k, std::string const& cs = "") + : mkn::ram::http::Server(p), crt(c), key(k), cs(cs) {} + Server(kul::File const& c, mkn::kul::File const& k, std::string const& cs = "") + : mkn::ram::https::Server(443, c, k, cs) {} virtual ~Server() { if (s) Server::stop(); } @@ -100,7 +100,7 @@ class Server : public kul::http::Server { virtual void stop() override; }; -class MultiServer : public kul::https::Server { +class MultiServer : public mkn::ram::https::Server { protected: uint8_t _acceptThreads, _workerThreads; std::mutex m_mutex; @@ -111,13 +111,13 @@ class MultiServer : public kul::https::Server { KUL_DBG_FUNC_ENTER std::map fds; fds.insert(std::make_pair(0, 0)); - for (size_t i = threadID; i < _KUL_TCP_MAX_CLIENT_; i += _acceptThreads) + for (size_t i = threadID; i < _MKN_RAM_TCP_MAX_CLIENT_; i += _acceptThreads) fds.insert(std::make_pair(i, 0)); while (s) try { - // kul::ScopeLock lock(m_mutex); + // mkn::kul::ScopeLock lock(m_mutex); std::lock_guard lock(m_mutex); loop(fds); - } catch (const kul::tcp::Exception &e1) { + } catch (const mkn::ram::tcp::Exception &e1) { KERR << e1.stack(); } catch (const std::exception &e1) { KERR << e1.what(); @@ -140,7 +140,7 @@ class MultiServer : public kul::https::Server { void operateBuffer(std::map *fds, int const& fd, char *in, int const& read, int &e) { KUL_DBG_FUNC_ENTER - kul::https::Server::handleBuffer(*fds, fd, in, read, e); + mkn::ram::https::Server::handleBuffer(*fds, fd, in, read, e); if (e <= 0) { getpeername(m_fds[fd].fd, (struct sockaddr *)&cli_addr, (socklen_t *)&clilen); KOUT(DBG) << "DISCO " @@ -151,12 +151,12 @@ class MultiServer : public kul::https::Server { closeFDs(*fds, del); } } - virtual void errorBuffer(const kul::Exception &e) { KERR << e.stack(); }; + virtual void errorBuffer(const mkn::kul::Exception &e) { KERR << e.stack(); }; public: MultiServer(const short &p, const uint8_t &acceptThreads, const uint8_t &workerThreads, - kul::File const& c, kul::File const& k, std::string const& cs = "") - : kul::https::Server(p, c, k, cs), + mkn::kul::File const& c, mkn::kul::File const& k, std::string const& cs = "") + : mkn::ram::https::Server(p, c, k, cs), _acceptThreads(acceptThreads), _workerThreads(workerThreads), _acceptPool(acceptThreads), @@ -165,8 +165,8 @@ class MultiServer : public kul::https::Server { KEXCEPTION("MultiServer cannot have less than one threads for accepting"); if (workerThreads < 1) KEXCEPTION("MultiServer cannot have less than one threads for working"); } - MultiServer(const uint8_t &acceptThreads, const uint8_t &workerThreads, kul::File const& c, - kul::File const& k, std::string const& cs = "") + MultiServer(const uint8_t &acceptThreads, const uint8_t &workerThreads, mkn::kul::File const& c, + mkn::kul::File const& k, std::string const& cs = "") : MultiServer(443, acceptThreads, workerThreads, c, k, cs) {} virtual ~MultiServer() { @@ -181,7 +181,7 @@ class MultiServer : public kul::https::Server { _workerPool.join(); } virtual void stop() override { - kul::https::Server::stop(); + mkn::ram::https::Server::stop(); _acceptPool.stop(); _workerPool.stop(); } @@ -204,7 +204,7 @@ class SSLReqHelper { SSL_library_init(); SSL_load_error_strings(); OpenSSL_add_all_algorithms(); - ctx = SSL_CTX_new(_KUL_HTTPS_CLIENT_METHOD_()); + ctx = SSL_CTX_new(_MKN_RAM_HTTPS_CLIENT_METHOD_()); if (ctx == NULL) { ERR_print_errors_fp(stderr); abort(); @@ -236,7 +236,7 @@ class _1_1GetRequest : public http::_1_1GetRequest, https::A1_1Request { _1_1GetRequest(std::string const& host, std::string const& path = "", uint16_t const& port = 443) : http::_1_1GetRequest(host, path, port) {} virtual ~_1_1GetRequest() {} - virtual void send() KTHROW(kul::http::Exception) override; + virtual void send() KTHROW(mkn::ram::http::Exception) override; }; using Get = _1_1GetRequest; @@ -244,9 +244,9 @@ class _1_1PostRequest : public http::_1_1PostRequest, https::A1_1Request { public: _1_1PostRequest(std::string const& host, std::string const& path = "", uint16_t const& port = 443) : http::_1_1PostRequest(host, path, port) {} - virtual void send() KTHROW(kul::http::Exception) override; + virtual void send() KTHROW(mkn::ram::http::Exception) override; }; using Post = _1_1PostRequest; } // namespace https } // namespace kul -#endif //_KUL_HTTPS_HPP_ +#endif //_MKN_RAM_NIXISH_HTTPS_HPP_ diff --git a/os/nixish/inc/kul/tcp.hpp b/os/nixish/inc/mkn/ram/tcp.hpp similarity index 87% rename from os/nixish/inc/kul/tcp.hpp rename to os/nixish/inc/mkn/ram/tcp.hpp index 93b7358..ba31ced 100644 --- a/os/nixish/inc/kul/tcp.hpp +++ b/os/nixish/inc/mkn/ram/tcp.hpp @@ -28,8 +28,8 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _KUL_TCP_HPP_ -#define _KUL_TCP_HPP_ +#ifndef _MKN_RAM_NIXISH_TCP_HPP_ +#define _MKN_RAM_NIXISH_TCP_HPP_ #include #include @@ -44,17 +44,19 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#include "kul/byte.hpp" -#include "kul/log.hpp" -#include "kul/tcp.base.hpp" -#include "kul/tcp/def.hpp" -#include "kul/time.hpp" +#include "mkn/kul/byte.hpp" +#include "mkn/kul/log.hpp" +#include "mkn/kul/time.hpp" -#ifndef __KUL_TCP_BIND_SOCKTOPTS__ -#define __KUL_TCP_BIND_SOCKTOPTS__ SO_REUSEADDR -#endif //__KUL_TCP_BIND_SOCKTOPTS__ +#include "mkn/ram/tcp.base.hpp" +#include "mkn/ram/tcp/def.hpp" -namespace kul { +#ifndef __MKN_RAM_TCP_BIND_SOCKTOPTS__ +#define __MKN_RAM_TCP_BIND_SOCKTOPTS__ SO_REUSEADDR +#endif //__MKN_RAM_TCP_BIND_SOCKTOPTS__ + +namespace mkn { +namespace ram { namespace tcp { template @@ -166,7 +168,7 @@ class Socket : public ASocket { servAddr.sin_family = AF_INET; int16_t e = 0; servAddr.sin_port = - !kul::byte::isBigEndian() ? htons(port) : kul::byte::LittleEndian::UINT32(port); + !kul::byte::isBigEndian() ? htons(port) : mkn::kul::byte::LittleEndian::UINT32(port); if (host == "localhost" || host == "127.0.0.1") { servAddr.sin_addr.s_addr = INADDR_ANY; e = ::connect(sck, (struct sockaddr *)&servAddr, sizeof(servAddr)); @@ -203,9 +205,9 @@ class SocketServer : public ASocketServer { bool s = 0; int lisock = 0, nfds = 12; int64_t _started; - struct pollfd m_fds[_KUL_TCP_MAX_CLIENT_]; + struct pollfd m_fds[_MKN_RAM_TCP_MAX_CLIENT_]; socklen_t clilen; - struct sockaddr_in serv_addr, cli_addr[_KUL_TCP_MAX_CLIENT_]; + struct sockaddr_in serv_addr, cli_addr[_MKN_RAM_TCP_MAX_CLIENT_]; virtual bool handle(T *const in, size_t const& inLen, T *const out, size_t &outLen) { // default overridable function @@ -220,10 +222,10 @@ class SocketServer : public ASocketServer { size_t size = 0; int64_t val = 0; while (1) { - val = ::recv(m_fds[fd].fd, in + size, _KUL_TCP_READ_BUFFER_ - (size + 1), + val = ::recv(m_fds[fd].fd, in + size, _MKN_RAM_TCP_READ_BUFFER_ - (size + 1), MSG_PEEK | MSG_DONTWAIT); if (val < 0) break; - size += ::recv(m_fds[fd].fd, in + size, _KUL_TCP_READ_BUFFER_ - (size + 1), opts); + size += ::recv(m_fds[fd].fd, in + size, _MKN_RAM_TCP_READ_BUFFER_ - (size + 1), opts); } return size; } @@ -233,8 +235,8 @@ class SocketServer : public ASocketServer { virtual bool receive(std::map &fds, int const& fd) { (void)fds; KUL_DBG_FUNC_ENTER - T in[_KUL_TCP_READ_BUFFER_]; - bzero(in, _KUL_TCP_READ_BUFFER_); + T in[_MKN_RAM_TCP_READ_BUFFER_]; + bzero(in, _MKN_RAM_TCP_READ_BUFFER_); int16_t e = 0, read = readFrom(fd, in); if (read < 0 && errno != EWOULDBLOCK) KEXCEPTION("Socket Server error on recv - fd(" + std::to_string(fd) + @@ -249,12 +251,12 @@ class SocketServer : public ASocketServer { bool cl = 1; in[read] = '\0'; try { - T out[_KUL_TCP_READ_BUFFER_]; - bzero(out, _KUL_TCP_READ_BUFFER_); + T out[_MKN_RAM_TCP_READ_BUFFER_]; + bzero(out, _MKN_RAM_TCP_READ_BUFFER_); size_t outLen; cl = handle(in, read, out, outLen); e = writeTo(fd, out, outLen); - } catch (const kul::tcp::Exception &e1) { + } catch (const mkn::ram::tcp::Exception &e1) { KERR << e1.stack(); e = -1; } @@ -315,7 +317,7 @@ class SocketServer : public ASocketServer { virtual int poll(int timeout = 10) { auto p = ::poll(m_fds, nfds, timeout); if (errno == 11) { - kul::this_thread::sleep(timeout); + mkn::kul::this_thread::sleep(timeout); return 0; } else if (errno == 2 || errno == 17 || errno == 32) { } else if (errno) { @@ -340,14 +342,14 @@ class SocketServer : public ASocketServer { } public: - SocketServer(uint16_t const& p, bool _bind = 1) : kul::tcp::ASocketServer(p) { - if (_bind) bind(__KUL_TCP_BIND_SOCKTOPTS__); + SocketServer(uint16_t const& p, bool _bind = 1) : mkn::ram::tcp::ASocketServer(p) { + if (_bind) bind(__MKN_RAM_TCP_BIND_SOCKTOPTS__); memset(m_fds, 0, sizeof(m_fds)); } ~SocketServer() { - for (int i = 0; i < _KUL_TCP_MAX_CLIENT_; i++) ::close(m_fds[i].fd); + for (int i = 0; i < _MKN_RAM_TCP_MAX_CLIENT_; i++) ::close(m_fds[i].fd); } - virtual void bind(int sockOpt = __KUL_TCP_BIND_SOCKTOPTS__) KTHROW(kul::Exception) { + virtual void bind(int sockOpt = __MKN_RAM_TCP_BIND_SOCKTOPTS__) KTHROW(kul::Exception) { lisock = socket(AF_INET, SOCK_STREAM, 0); int iso = 1; int rc = setsockopt(lisock, SOL_SOCKET, sockOpt, (char *)&iso, sizeof(iso)); @@ -367,7 +369,7 @@ class SocketServer : public ASocketServer { serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = INADDR_ANY; serv_addr.sin_port = !kul::byte::isBigEndian() ? htons(this->port()) - : kul::byte::LittleEndian::UINT32(this->port()); + : mkn::kul::byte::LittleEndian::UINT32(this->port()); int16_t e = 0; if ((e = ::bind(lisock, (struct sockaddr *)&serv_addr, sizeof(serv_addr))) < 0) { KERR << std::to_string(errno) << " - " << std::string(strerror(errno)); @@ -376,7 +378,7 @@ class SocketServer : public ASocketServer { } virtual void start() KTHROW(kul::tcp::Exception) { KUL_DBG_FUNC_ENTER - _started = kul::Now::MILLIS(); + _started = mkn::kul::Now::MILLIS(); auto ret = listen(lisock, 256); if (ret < 0) KEXCEPTION("Socket Server error on listen"); clilen = sizeof(cli_addr[0]); @@ -385,10 +387,10 @@ class SocketServer : public ASocketServer { m_fds[0].events = POLLIN; //|POLLPRI; nfds = lisock + 1; std::map fds; - for (size_t i = 0; i < _KUL_TCP_MAX_CLIENT_; i++) fds.insert(std::make_pair(i, 0)); + for (size_t i = 0; i < _MKN_RAM_TCP_MAX_CLIENT_; i++) fds.insert(std::make_pair(i, 0)); try { while (s) loop(fds); - } catch (const kul::tcp::Exception &e1) { + } catch (const mkn::ram::tcp::Exception &e1) { KERR << e1.stack(); } catch (const std::exception &e1) { KERR << e1.what(); @@ -400,12 +402,13 @@ class SocketServer : public ASocketServer { KUL_DBG_FUNC_ENTER s = 0; ::close(lisock); - for (int i = 0; i < _KUL_TCP_MAX_CLIENT_; i++) + for (int i = 0; i < _MKN_RAM_TCP_MAX_CLIENT_; i++) if (i != lisock) shutdown(i, SHUT_RDWR); } }; -} // END NAMESPACE tcp -} // END NAMESPACE kul +} // namespace tcp +} // namespace ram +} // namespace mkn -#endif //_KUL_TCP_HPP_ +#endif //_MKN_RAM_NIXISH_TCP_HPP_ diff --git a/os/nixish/src/http/multi.cpp b/os/nixish/src/http/multi.cpp index b233db7..ad81c90 100644 --- a/os/nixish/src/http/multi.cpp +++ b/os/nixish/src/http/multi.cpp @@ -28,11 +28,11 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "kul/http.hpp" +#include "mkn/ram/http.hpp" -void kul::http::MultiServer::start() KTHROW(kul::tcp::Exception) { +void mkn::ram::http::MultiServer::start() KTHROW(kul::tcp::Exception) { KUL_DBG_FUNC_ENTER - _started = kul::Now::MILLIS(); + _started = mkn::kul::Now::MILLIS(); listen(lisock, 256); clilen = sizeof(cli_addr[0]); s = true; diff --git a/os/nixish/src/http/server.cpp b/os/nixish/src/http/server.cpp index 55b97bf..15869f6 100644 --- a/os/nixish/src/http/server.cpp +++ b/os/nixish/src/http/server.cpp @@ -28,12 +28,12 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "kul/http.hpp" +#include "mkn/ram/http.hpp" -bool kul::http::Server::receive(std::map &fds, int const& fd) { +bool mkn::ram::http::Server::receive(std::map &fds, int const& fd) { KUL_DBG_FUNC_ENTER; char *in = getOrCreateBufferFor(fd); - bzero(in, _KUL_TCP_READ_BUFFER_); + bzero(in, _MKN_RAM_TCP_READ_BUFFER_); int e = 0, read = readFrom(fd, in); if (read < 0) e = -1; diff --git a/os/nixish/src/https/multi.cpp b/os/nixish/src/https/multi.cpp index fe8873b..e35588b 100644 --- a/os/nixish/src/https/multi.cpp +++ b/os/nixish/src/https/multi.cpp @@ -28,12 +28,12 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifdef _KUL_INCLUDE_HTTPS_ -#include "kul/https.hpp" +#ifdef _MKN_RAM_INCLUDE_HTTPS_ +#include "mkn/ram/https.hpp" -void kul::https::MultiServer::start() KTHROW(kul::tcp::Exception) { +void mkn::ram::https::MultiServer::start() KTHROW(kul::tcp::Exception) { KUL_DBG_FUNC_ENTER - _started = kul::Now::MILLIS(); + _started = mkn::kul::Now::MILLIS(); listen(lisock, 256); clilen = sizeof(cli_addr); s = true; @@ -47,4 +47,4 @@ void kul::https::MultiServer::start() KTHROW(kul::tcp::Exception) { _workerPool.start(); } -#endif //_KUL_INCLUDE_HTTPS_ \ No newline at end of file +#endif //_MKN_RAM_INCLUDE_HTTPS_ \ No newline at end of file diff --git a/os/nixish/src/https/request.cpp b/os/nixish/src/https/request.cpp index e0e4083..250e220 100644 --- a/os/nixish/src/https/request.cpp +++ b/os/nixish/src/https/request.cpp @@ -28,25 +28,25 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifdef _KUL_INCLUDE_HTTPS_ -#include "kul/https.hpp" +#ifdef _MKN_RAM_INCLUDE_HTTPS_ +#include "mkn/ram/https.hpp" -void kul::https::Requester::send(std::string const& h, std::string const& req, uint16_t const& p, +void mkn::ram::https::Requester::send(std::string const& h, std::string const& req, uint16_t const& p, std::stringstream &ss, SSL *ssl) { KUL_DBG_FUNC_ENTER int sck = 0; - if (!kul::tcp::Socket::SOCKET(sck, PF_INET, SOCK_STREAM, 0)) - KEXCEPT(kul::http::Exception, "Error opening socket"); - if (!kul::tcp::Socket::CONNECT(sck, h, p)) - KEXCEPT(kul::http::Exception, "Failed to connect to host: " + h); + if (!mkn::ram::tcp::Socket::SOCKET(sck, PF_INET, SOCK_STREAM, 0)) + KEXCEPT(mkn::ram::http::Exception, "Error opening socket"); + if (!mkn::ram::tcp::Socket::CONNECT(sck, h, p)) + KEXCEPT(mkn::ram::http::Exception, "Failed to connect to host: " + h); SSL_set_fd(ssl, sck); if (SSL_connect(ssl) == -1) KEXCEPTION("HTTPS REQUEST INIT FAILED"); SSL_write(ssl, req.c_str(), req.size()); - char buffer[_KUL_TCP_REQUEST_BUFFER_]; + char buffer[_MKN_RAM_TCP_REQUEST_BUFFER_]; int64_t d = 0, i = 0; do { - bzero(buffer, _KUL_TCP_REQUEST_BUFFER_); - d = SSL_read(ssl, buffer, _KUL_TCP_REQUEST_BUFFER_ - 1); + bzero(buffer, _MKN_RAM_TCP_REQUEST_BUFFER_); + d = SSL_read(ssl, buffer, _MKN_RAM_TCP_REQUEST_BUFFER_ - 1); if (d == 0) break; if (d < 0) { short se = 0; @@ -59,34 +59,34 @@ void kul::https::Requester::send(std::string const& h, std::string const& req, u ::close(sck); } -void kul::https::_1_1GetRequest::send() KTHROW(kul::http::Exception) { +void mkn::ram::https::_1_1GetRequest::send() KTHROW(mkn::ram::http::Exception) { KUL_DBG_FUNC_ENTER try { std::stringstream ss; Requester::send(_host, toString(), _port, ss, ssl); auto rec(ss.str()); - kul::http::_1_1Response res(kul::http::_1_1Response::FROM_STRING(rec)); + mkn::ram::http::_1_1Response res(mkn::ram::http::_1_1Response::FROM_STRING(rec)); handleResponse(res); - } catch (const kul::Exception &e) { + } catch (const mkn::kul::Exception &e) { KLOG(ERR) << e.debug(); KEXCEPT(Exception, "HTTP GET failed with host: " + _host); } } -void kul::https::_1_1PostRequest::send() KTHROW(kul::http::Exception) { +void mkn::ram::https::_1_1PostRequest::send() KTHROW(mkn::ram::http::Exception) { KUL_DBG_FUNC_ENTER try { std::stringstream ss; Requester::send(_host, toString(), _port, ss, ssl); auto rec(ss.str()); - kul::http::_1_1Response res(kul::http::_1_1Response::FROM_STRING(rec)); + mkn::ram::http::_1_1Response res(mkn::ram::http::_1_1Response::FROM_STRING(rec)); handleResponse(res); - } catch (const kul::Exception &e) { + } catch (const mkn::kul::Exception &e) { KLOG(ERR) << e.debug(); KEXCEPT(Exception, "HTTP POST failed with host: " + _host); } } -#endif //_KUL_INCLUDE_HTTPS_ \ No newline at end of file +#endif //_MKN_RAM_INCLUDE_HTTPS_ \ No newline at end of file diff --git a/os/nixish/src/https/server.cpp b/os/nixish/src/https/server.cpp index e94bee4..c1eb5a0 100644 --- a/os/nixish/src/https/server.cpp +++ b/os/nixish/src/https/server.cpp @@ -28,10 +28,10 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifdef _KUL_INCLUDE_HTTPS_ -#include "kul/https.hpp" +#ifdef _MKN_RAM_INCLUDE_HTTPS_ +#include "mkn/ram/https.hpp" -void kul::https::Server::loop(std::map &fds) KTHROW(kul::tcp::Exception) { +void mkn::ram::https::Server::loop(std::map &fds) KTHROW(kul::tcp::Exception) { KUL_DBG_FUNC_ENTER auto ret = poll(100); @@ -97,20 +97,20 @@ void kul::https::Server::loop(std::map &fds) KTHROW(kul::tcp::Exce if (del.size()) closeFDs(fds, del); } -void kul::https::Server::setChain(const kul::File &f) { +void mkn::ram::https::Server::setChain(const mkn::kul::File &f) { if (!f) KEXCEPTION("HTTPS Server chain file does not exist: " + f.full()); if (SSL_CTX_use_certificate_chain_file(ctx, f.mini().c_str()) <= 0) KEXCEPTION("HTTPS Server SSL_CTX_use_PrivateKey_file failed"); } -kul::https::Server &kul::https::Server::init() { +mkn::ram::https::Server &mkn::ram::https::Server::init() { KUL_DBG_FUNC_ENTER if (!crt) KEXCEPTION("HTTPS Server crt file does not exist: " + crt.full()); if (!key) KEXCEPTION("HTTPS Server key file does not exist: " + key.full()); SSL_library_init(); SSL_load_error_strings(); OpenSSL_add_ssl_algorithms(); - ctx = SSL_CTX_new(_KUL_HTTPS_SERVER_METHOD_()); + ctx = SSL_CTX_new(_MKN_RAM_HTTPS_SERVER_METHOD_()); if (!ctx) KEXCEPTION("HTTPS Server SSL_CTX failed SSL_CTX_new"); if (SSL_CTX_use_certificate_file(ctx, crt.mini().c_str(), SSL_FILETYPE_PEM) <= 0) KEXCEPTION("HTTPS Server SSL_CTX_use_certificate_file failed"); @@ -122,12 +122,12 @@ kul::https::Server &kul::https::Server::init() { return *this; } -void kul::https::Server::stop() { +void mkn::ram::https::Server::stop() { KUL_DBG_FUNC_ENTER s = 0; ERR_free_strings(); EVP_cleanup(); - for (size_t i = 0; i < _KUL_TCP_MAX_CLIENT_; i++) { + for (size_t i = 0; i < _MKN_RAM_TCP_MAX_CLIENT_; i++) { auto ssl = ssl_clients[i]; if (ssl) { SSL_shutdown(ssl); @@ -135,10 +135,10 @@ void kul::https::Server::stop() { } } if (ctx) SSL_CTX_free(ctx); - kul::http::Server::stop(); + mkn::ram::http::Server::stop(); } -void kul::https::Server::handleBuffer(std::map &fds, int const& fd, char *in, +void mkn::ram::https::Server::handleBuffer(std::map &fds, int const& fd, char *in, int const& read, int &e) { KUL_DBG_FUNC_ENTER in[read] = '\0'; @@ -153,23 +153,23 @@ void kul::https::Server::handleBuffer(std::map &fds, int const& fd if (f) break; } if (!f) KEXCEPTION("Logic error encountered, probably https attempt on http port"); - std::shared_ptr req = handleRequest(fd, s, res); - const kul::http::_1_1Response &rs(respond(*req.get())); + std::shared_ptr req = handleRequest(fd, s, res); + const mkn::ram::http::_1_1Response &rs(respond(*req.get())); std::string ret(rs.toString()); ::SSL_write(ssl_clients[m_fds[fd].fd], ret.c_str(), ret.length()); e = 0; - } catch (const kul::http::Exception &e1) { + } catch (const mkn::ram::http::Exception &e1) { KERR << e1.stack(); e = -1; } fds[fd] = 1; } -bool kul::https::Server::receive(std::map &fds, int const& fd) { +bool mkn::ram::https::Server::receive(std::map &fds, int const& fd) { KUL_DBG_FUNC_ENTER char *in = getOrCreateBufferFor(fd); - bzero(in, _KUL_TCP_READ_BUFFER_); - int e = 0, read = ::SSL_read(ssl_clients[m_fds[fd].fd], in, _KUL_TCP_READ_BUFFER_ - 1); + bzero(in, _MKN_RAM_TCP_READ_BUFFER_); + int e = 0, read = ::SSL_read(ssl_clients[m_fds[fd].fd], in, _MKN_RAM_TCP_READ_BUFFER_ - 1); if (read < 0) { if (fds[fd] == 5) { e = -1; @@ -197,4 +197,4 @@ bool kul::https::Server::receive(std::map &fds, int const& fd) { return true; } -#endif //_KUL_INCLUDE_HTTPS_ +#endif //_MKN_RAM_INCLUDE_HTTPS_ diff --git a/os/win/inc/kul/http.hpp b/os/win/inc/mkn/ram/http.hpp similarity index 85% rename from os/win/inc/kul/http.hpp rename to os/win/inc/mkn/ram/http.hpp index a0f1d32..85b4d63 100644 --- a/os/win/inc/kul/http.hpp +++ b/os/win/inc/mkn/ram/http.hpp @@ -39,9 +39,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define WIN32_LEAN_AND_MEAN #endif -#include "kul/http.hpp" -#include "kul/log.hpp" -#include "kul/threads.hpp" +#include "mkn/ram/http.hpp" +#include "mkn/kul/log.hpp" +#include "mkn/kul/threads.hpp" #ifndef UNICODE #define UNICODE @@ -60,12 +60,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #pragma comment(lib, "httpapi.lib") #pragma comment(lib, "ws2_32.lib") -namespace kul { +namespace mkn { +namespace ram { namespace http { -class Server : public kul::http::AServer { +class Server : public mkn::ram::http::AServer { private: - int fdSize = _KUL_TCP_READ_BUFFER_; + int fdSize = _MKN_RAM_TCP_READ_BUFFER_; std::unordered_map> inBuffers; protected: @@ -82,10 +83,10 @@ class Server : public kul::http::AServer { virtual ~Server() {} }; -class KUL_PUBLISH MultiServer : public kul::http::Server { +class KUL_PUBLISH MultiServer : public mkn::ram::http::Server { protected: uint8_t _acceptThreads, _workerThreads; - kul::Mutex m_mutex; + mkn::kul::Mutex m_mutex; ChroncurrentThreadPool<> _acceptPool; ChroncurrentThreadPool<> _workerPool; @@ -99,23 +100,23 @@ class KUL_PUBLISH MultiServer : public kul::http::Server { void operateBuffer(std::map* fds, const int& fd, char* in, const int& read, int& e) { - kul::http::Server::handleBuffer(*fds, fd, in, read, e); + mkn::ram::http::Server::handleBuffer(*fds, fd, in, read, e); if (e < 0) { std::vector del{fd}; // closeFDs(*fds, del); } } - virtual void errorBuffer(const kul::Exception& e) { KERR << e.stack(); }; + virtual void errorBuffer(const mkn::kul::Exception& e) { KERR << e.stack(); }; void operateAccept(const size_t& threadID) { std::map fds; fds.insert(std::make_pair(0, 0)); - for (int i = threadID; i < _KUL_TCP_MAX_CLIENT_; i += _acceptThreads) + for (int i = threadID; i < _MKN_RAM_TCP_MAX_CLIENT_; i += _acceptThreads) fds.insert(std::make_pair(i, 0)); while (s) try { - kul::ScopeLock lock(m_mutex); + mkn::kul::ScopeLock lock(m_mutex); loop(fds); - } catch (const kul::tcp::Exception& e1) { + } catch (const mkn::ram::tcp::Exception& e1) { KERR << e1.stack(); } catch (const std::exception& e1) { KERR << e1.what(); @@ -136,7 +137,7 @@ class KUL_PUBLISH MultiServer : public kul::http::Server { _workerPool.join(); } virtual void stop() override { - kul::http::Server::stop(); + mkn::ram::http::Server::stop(); _acceptPool.stop(); _workerPool.stop(); } @@ -147,7 +148,8 @@ class KUL_PUBLISH MultiServer : public kul::http::Server { const std::exception_ptr& exception() { return _acceptPool.exception(); } }; -} // END NAMESPACE http -} // END NAMESPACE kul +} // namespace http +} // namespace ram +} // namespace mkn #endif /* _KUL_HTTP_HPP_ */ diff --git a/os/win/inc/kul/https.hpp b/os/win/inc/mkn/ram/https.hpp similarity index 71% rename from os/win/inc/kul/https.hpp rename to os/win/inc/mkn/ram/https.hpp index f03ffe2..aa8810f 100644 --- a/os/win/inc/kul/https.hpp +++ b/os/win/inc/mkn/ram/https.hpp @@ -28,8 +28,8 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _KUL_HTTPS_HPP_ -#define _KUL_HTTPS_HPP_ +#ifndef _MKN_RAM_HTTPS_HPP_ +#define _MKN_RAM_HTTPS_HPP_ #include #include @@ -39,40 +39,41 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#include "kul/http.hpp" +#include "mkn/ram/http.hpp" -#define KUL_HTTPS_METHOD_APPENDER2(x, y) x##y -#define KUL_HTTPS_METHOD_APPENDER(x, y) KUL_HTTPS_METHOD_APPENDER2(x, y) +#define MKN_RAM_HTTPS_METHOD_APPENDER2(x, y) x##y +#define MKN_RAM_HTTPS_METHOD_APPENDER(x, y) MKN_RAM_HTTPS_METHOD_APPENDER2(x, y) -#if !defined(_KUL_HTTPS_CLIENT_METHOD_) && !defined(_KUL_HTTPS_SERVER_METHOD_) +#if !defined(_MKN_RAM_HTTPS_CLIENT_METHOD_) && !defined(_MKN_RAM_HTTPS_SERVER_METHOD_) -#ifndef _KUL_HTTPS_METHOD_ -#define _KUL_HTTPS_METHOD_ TLS -#endif /* _KUL_HTTPS_METHOD_ */ +#ifndef _MKN_RAM_HTTPS_METHOD_ +#define _MKN_RAM_HTTPS_METHOD_ TLS +#endif /* _MKN_RAM_HTTPS_METHOD_ */ -#define _KUL_HTTPS_CLIENT_METHOD_ KUL_HTTPS_METHOD_APPENDER(_KUL_HTTPS_METHOD_, _client_method) -#define _KUL_HTTPS_SERVER_METHOD_ KUL_HTTPS_METHOD_APPENDER(_KUL_HTTPS_METHOD_, _server_method) +#define _MKN_RAM_HTTPS_CLIENT_METHOD_ MKN_RAM_HTTPS_METHOD_APPENDER(_MKN_RAM_HTTPS_METHOD_, _client_method) +#define _MKN_RAM_HTTPS_SERVER_METHOD_ MKN_RAM_HTTPS_METHOD_APPENDER(_MKN_RAM_HTTPS_METHOD_, _server_method) #else -#ifndef _KUL_HTTPS_CLIENT_METHOD_ -#define _KUL_HTTPS_CLIENT_METHOD_ TLS_client_method -#endif /* _KUL_HTTPS_CLIENT_METHOD_ */ -#ifndef _KUL_HTTPS_SERVER_METHOD_ -#define _KUL_HTTPS_SERVER_METHOD_ TLS_server_method -#endif /* _KUL_HTTPS_SERVER_METHOD_ */ +#ifndef _MKN_RAM_HTTPS_CLIENT_METHOD_ +#define _MKN_RAM_HTTPS_CLIENT_METHOD_ TLS_client_method +#endif /* _MKN_RAM_HTTPS_CLIENT_METHOD_ */ +#ifndef _MKN_RAM_HTTPS_SERVER_METHOD_ +#define _MKN_RAM_HTTPS_SERVER_METHOD_ TLS_server_method +#endif /* _MKN_RAM_HTTPS_SERVER_METHOD_ */ #endif /* defined xyz */ -namespace kul { +namespace mkn { +namespace ram { namespace https { -class Server : public kul::http::Server { +class Server : public mkn::ram::http::Server { protected: X509* cc = {0}; - SSL* ssl_clients[_KUL_TCP_MAX_CLIENT_] = {0}; + SSL* ssl_clients[_MKN_RAM_TCP_MAX_CLIENT_] = {0}; SSL_CTX* ctx = {0}; - kul::File crt, key; + mkn::kul::File crt, key; const std::string cs; virtual KUL_PUBLISH void loop(std::map& fds) KTHROW(kul::tcp::Exception) override; @@ -83,34 +84,34 @@ class Server : public kul::http::Server { const int& read, int& e); public: - Server(const short& p, const kul::File& c, const kul::File& k, const std::string& cs = "") - : kul::http::Server(p), crt(c), key(k), cs(cs) {} - Server(const kul::File& c, const kul::File& k, const std::string& cs = "") - : kul::https::Server(443, c, k, cs) {} + Server(const short& p, const mkn::kul::File& c, const mkn::kul::File& k, const std::string& cs = "") + : mkn::ram::http::Server(p), crt(c), key(k), cs(cs) {} + Server(const mkn::kul::File& c, const mkn::kul::File& k, const std::string& cs = "") + : mkn::ram::https::Server(443, c, k, cs) {} virtual ~Server() { if (s) stop(); } - KUL_PUBLISH void setChain(const kul::File& f); + KUL_PUBLISH void setChain(const mkn::kul::File& f); KUL_PUBLISH Server& init(); KUL_PUBLISH virtual void stop() override; }; -class KUL_PUBLISH MultiServer : public kul::https::Server { +class KUL_PUBLISH MultiServer : public mkn::ram::https::Server { protected: uint8_t _acceptThreads, _workerThreads; - kul::Mutex m_mutex; + mkn::kul::Mutex m_mutex; ChroncurrentThreadPool<> _acceptPool; ChroncurrentThreadPool<> _workerPool; void operateAccept(const size_t& threadID) { std::map fds; fds.insert(std::make_pair(0, 0)); - for (size_t i = threadID; i < _KUL_TCP_MAX_CLIENT_; i += _acceptThreads) + for (size_t i = threadID; i < _MKN_RAM_TCP_MAX_CLIENT_; i += _acceptThreads) fds.insert(std::make_pair(i, 0)); while (s) try { - kul::ScopeLock lock(m_mutex); + mkn::kul::ScopeLock lock(m_mutex); loop(fds); - } catch (const kul::tcp::Exception& e1) { + } catch (const mkn::ram::tcp::Exception& e1) { KERR << e1.stack(); } catch (const std::exception& e1) { KERR << e1.what(); @@ -129,18 +130,18 @@ class KUL_PUBLISH MultiServer : public kul::https::Server { void operateBuffer(std::map* fds, const int& fd, char* in, const int& read, int& e) { - kul::https::Server::handleBuffer(*fds, fd, in, read, e); + mkn::ram::https::Server::handleBuffer(*fds, fd, in, read, e); if (e < 0) { std::vector del{fd}; closeFDs(*fds, del); } } - virtual void errorBuffer(const kul::Exception& e) { KERR << e.stack(); }; + virtual void errorBuffer(const mkn::kul::Exception& e) { KERR << e.stack(); }; public: MultiServer(const short& p, const uint8_t& acceptThreads, const uint8_t& workerThreads, - const kul::File& c, const kul::File& k, const std::string& cs = "") - : kul::https::Server(p, c, k, cs), + const mkn::kul::File& c, const mkn::kul::File& k, const std::string& cs = "") + : mkn::ram::https::Server(p, c, k, cs), _acceptThreads(acceptThreads), _workerThreads(workerThreads), _acceptPool(acceptThreads), @@ -149,8 +150,8 @@ class KUL_PUBLISH MultiServer : public kul::https::Server { KEXCEPTION("MultiServer cannot have less than one threads for accepting"); if (workerThreads < 1) KEXCEPTION("MultiServer cannot have less than one threads for working"); } - MultiServer(const uint8_t& acceptThreads, const uint8_t& workerThreads, const kul::File& c, - const kul::File& k, const std::string& cs = "") + MultiServer(const uint8_t& acceptThreads, const uint8_t& workerThreads, const mkn::kul::File& c, + const mkn::kul::File& k, const std::string& cs = "") : MultiServer(443, acceptThreads, workerThreads, c, k, cs) {} virtual ~MultiServer() { @@ -165,7 +166,7 @@ class KUL_PUBLISH MultiServer : public kul::https::Server { _workerPool.join(); } virtual void stop() override { - kul::https::Server::stop(); + mkn::ram::https::Server::stop(); _acceptPool.stop(); _workerPool.stop(); } @@ -188,7 +189,7 @@ class SSLReqHelper { SSL_library_init(); SSL_load_error_strings(); OpenSSL_add_all_algorithms(); - ctx = SSL_CTX_new(_KUL_HTTPS_CLIENT_METHOD_()); + ctx = SSL_CTX_new(_MKN_RAM_HTTPS_CLIENT_METHOD_()); if (ctx == NULL) { ERR_print_errors_fp(stderr); abort(); @@ -220,7 +221,7 @@ class _1_1GetRequest : public http::_1_1GetRequest, https::A1_1Request { _1_1GetRequest(const std::string& host, const std::string& path = "", const uint16_t& port = 443) : http::_1_1GetRequest(host, path, port) {} virtual ~_1_1GetRequest() {} - virtual void send() KTHROW(kul::http::Exception) override; + virtual void send() KTHROW(mkn::ram::http::Exception) override; }; using Get = _1_1GetRequest; @@ -228,9 +229,11 @@ class _1_1PostRequest : public http::_1_1PostRequest, https::A1_1Request { public: _1_1PostRequest(const std::string& host, const std::string& path = "", const uint16_t& port = 443) : http::_1_1PostRequest(host, path, port) {} - virtual void send() KTHROW(kul::http::Exception) override; + virtual void send() KTHROW(mkn::ram::http::Exception) override; }; using Post = _1_1PostRequest; + } // namespace https +} // namespace ram } // namespace kul -#endif //_KUL_INCLUDE_HTTPS_HPP_ +#endif //_MKN_RAM_INCLUDE_HTTPS_HPP_ diff --git a/os/win/inc/kul/tcp.hpp b/os/win/inc/mkn/ram/tcp.hpp similarity index 90% rename from os/win/inc/kul/tcp.hpp rename to os/win/inc/mkn/ram/tcp.hpp index 31c6e0c..e898b29 100644 --- a/os/win/inc/kul/tcp.hpp +++ b/os/win/inc/mkn/ram/tcp.hpp @@ -28,10 +28,10 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _KUL_TCP_HPP_ -#define _KUL_TCP_HPP_ +#ifndef _MKN_RAM_TCP_HPP_ +#define _MKN_RAM_TCP_HPP_ -#include "kul/tcp/def.hpp" +#include "mkn/kul/tcp/def.hpp" #undef UNICODE #define WIN32_LEAN_AND_MEAN @@ -43,7 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#include "kul/tcp.base.hpp" +#include "mkn/kul/tcp.base.hpp" #include #include @@ -52,7 +52,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #pragma comment(lib, "Mswsock.lib") #pragma comment(lib, "AdvApi32.lib") -namespace kul { +namespace mkn { +namespace ram { namespace tcp { template @@ -162,7 +163,7 @@ class SocketServer : public ASocketServer { int64_t _started; WSADATA wsaData; - WSAPOLLFD m_fds[_KUL_TCP_MAX_CLIENT_]; + WSAPOLLFD m_fds[_MKN_RAM_TCP_MAX_CLIENT_]; SOCKET lisock = INVALID_SOCKET; SOCKET ClientSocket = INVALID_SOCKET; @@ -171,14 +172,14 @@ class SocketServer : public ASocketServer { struct addrinfo hints; socklen_t clilen; - struct sockaddr_in serv_addr, cli_addr[_KUL_TCP_MAX_CLIENT_]; + struct sockaddr_in serv_addr, cli_addr[_MKN_RAM_TCP_MAX_CLIENT_]; virtual bool handle(T* const in, const size_t& inLen, T* const out, size_t& outLen) { return true; } virtual int readFrom(const int& fd, T* in, int opts = 0) { - return ::recv(m_fds[fd].fd, in, _KUL_TCP_READ_BUFFER_ - 1, opts); + return ::recv(m_fds[fd].fd, in, _MKN_RAM_TCP_READ_BUFFER_ - 1, opts); } virtual int writeTo(const int& fd, const T* const out, size_t size) { return ::send(m_fds[fd].fd, out, size, 0); @@ -186,16 +187,16 @@ class SocketServer : public ASocketServer { virtual bool receive(std::map& fds, const int& fd) { KUL_DBG_FUNC_ENTER - T in[_KUL_TCP_READ_BUFFER_]; - ZeroMemory(in, _KUL_TCP_READ_BUFFER_); + T in[_MKN_RAM_TCP_READ_BUFFER_]; + ZeroMemory(in, _MKN_RAM_TCP_READ_BUFFER_); bool cl; do { cl = 0; - iResult = recv(ClientSocket, in, _KUL_TCP_READ_BUFFER_ - 1, 0); + iResult = recv(ClientSocket, in, _MKN_RAM_TCP_READ_BUFFER_ - 1, 0); if (iResult > 0) { - T out[_KUL_TCP_READ_BUFFER_]; - ZeroMemory(out, _KUL_TCP_READ_BUFFER_); + T out[_MKN_RAM_TCP_READ_BUFFER_]; + ZeroMemory(out, _MKN_RAM_TCP_READ_BUFFER_); size_t outLen; cl = handle(in, iResult, out, outLen); auto sent = writeTo(ClientSocket, out, strlen(out)); @@ -284,8 +285,8 @@ class SocketServer : public ASocketServer { } public: - SocketServer(const uint16_t& p, bool _bind = 1) : kul::tcp::ASocketServer(p) { - // if(_bind) bind(__KUL_TCP_BIND_SOCKTOPTS__); + SocketServer(const uint16_t& p, bool _bind = 1) : mkn::ram::tcp::ASocketServer(p) { + // if(_bind) bind(__MKN_RAM_TCP_BIND_SOCKTOPTS__); } void freeaddrinfo() { if (!result) return; @@ -298,10 +299,10 @@ class SocketServer : public ASocketServer { if (ClientSocket) closesocket(ClientSocket); WSACleanup(); } - virtual void bind(int sockOpt = __KUL_TCP_BIND_SOCKTOPTS__) KTHROW(kul::Exception) {} + virtual void bind(int sockOpt = __MKN_RAM_TCP_BIND_SOCKTOPTS__) KTHROW(kul::Exception) {} virtual void start() KTHROW(kul::tcp::Exception) { KUL_DBG_FUNC_ENTER - _started = kul::Now::MILLIS(); + _started = mkn::kul::Now::MILLIS(); iResult = WSAStartup(MAKEWORD(2, 2), &wsaData); if (iResult != 0) KEXCEPTION("WSAStartup failed with error: ") << iResult; @@ -338,10 +339,10 @@ class SocketServer : public ASocketServer { s = true; std::map fds; - for (int i = 0; i < _KUL_TCP_MAX_CLIENT_; i++) fds.insert(std::make_pair(i, 0)); + for (int i = 0; i < _MKN_RAM_TCP_MAX_CLIENT_; i++) fds.insert(std::make_pair(i, 0)); try { while (s) loop(fds); - } catch (const kul::tcp::Exception& e1) { + } catch (const mkn::ram::tcp::Exception& e1) { KERR << e1.stack(); } catch (const std::exception& e1) { KERR << e1.what(); @@ -359,7 +360,8 @@ class SocketServer : public ASocketServer { } }; -} // END NAMESPACE tcp -} // END NAMESPACE kul +} // namespace tcp +} // namespace ram +} // namespace mkn -#endif //_KUL_TCP_HPP_ +#endif //_MKN_RAM_TCP_HPP_ diff --git a/os/win/src/http/multi.cpp b/os/win/src/http/multi.cpp index 5d1982f..6631cf5 100644 --- a/os/win/src/http/multi.cpp +++ b/os/win/src/http/multi.cpp @@ -28,11 +28,11 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "kul/http.hpp" +#include "mkn/ram/http.hpp" -void kul::http::MultiServer::start() KTHROW(kul::tcp::Exception) { +void mkn::ram::http::MultiServer::start() KTHROW(kul::tcp::Exception) { KUL_DBG_FUNC_ENTER - _started = kul::Now::MILLIS(); + _started = mkn::kul::Now::MILLIS(); for (size_t i = 0; i < _acceptThreads; i++) _acceptPool.async(std::bind(&MultiServer::operateAccept, std::ref(*this), i)); diff --git a/os/win/src/http/server.cpp b/os/win/src/http/server.cpp index f405c3d..cc9f011 100644 --- a/os/win/src/http/server.cpp +++ b/os/win/src/http/server.cpp @@ -28,12 +28,12 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "kul/http.hpp" +#include "mkn/ram/http.hpp" -bool kul::http::Server::receive(std::map& fds, const int& fd) { +bool mkn::ram::http::Server::receive(std::map& fds, const int& fd) { KUL_DBG_FUNC_ENTER; char* in = getOrCreateBufferFor(fd); - ZeroMemory(in, _KUL_TCP_READ_BUFFER_); + ZeroMemory(in, _MKN_RAM_TCP_READ_BUFFER_); int e = 0, read = readFrom(fd, in); if (read < 0) e = -1; diff --git a/os/win/src/https/multi.cpp b/os/win/src/https/multi.cpp index fe8873b..e35588b 100644 --- a/os/win/src/https/multi.cpp +++ b/os/win/src/https/multi.cpp @@ -28,12 +28,12 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifdef _KUL_INCLUDE_HTTPS_ -#include "kul/https.hpp" +#ifdef _MKN_RAM_INCLUDE_HTTPS_ +#include "mkn/ram/https.hpp" -void kul::https::MultiServer::start() KTHROW(kul::tcp::Exception) { +void mkn::ram::https::MultiServer::start() KTHROW(kul::tcp::Exception) { KUL_DBG_FUNC_ENTER - _started = kul::Now::MILLIS(); + _started = mkn::kul::Now::MILLIS(); listen(lisock, 256); clilen = sizeof(cli_addr); s = true; @@ -47,4 +47,4 @@ void kul::https::MultiServer::start() KTHROW(kul::tcp::Exception) { _workerPool.start(); } -#endif //_KUL_INCLUDE_HTTPS_ \ No newline at end of file +#endif //_MKN_RAM_INCLUDE_HTTPS_ \ No newline at end of file diff --git a/os/win/src/https/request.cpp b/os/win/src/https/request.cpp index d9c74f9..059c884 100644 --- a/os/win/src/https/request.cpp +++ b/os/win/src/https/request.cpp @@ -28,24 +28,24 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifdef _KUL_INCLUDE_HTTPS_ -#include "kul/https.hpp" +#ifdef _MKN_RAM_INCLUDE_HTTPS_ +#include "mkn/ram/https.hpp" -void kul::https::Requester::send(const std::string& h, const std::string& req, const uint16_t& p, +void mkn::ram::https::Requester::send(const std::string& h, const std::string& req, const uint16_t& p, std::stringstream& ss, SSL* ssl) { KUL_DBG_FUNC_ENTER { - kul::tcp::Socket sock; + mkn::ram::tcp::Socket sock; if (!sock.connect(h, p)) KEXCEPTION("TCP FAILED TO CONNECT!"); SOCKET sck = sock.socket(); SSL_set_fd(ssl, sck); if (SSL_connect(ssl) == -1) KEXCEPTION("HTTPS REQUEST INIT FAILED"); SSL_write(ssl, req.c_str(), req.size()); - char buffer[_KUL_TCP_REQUEST_BUFFER_]; + char buffer[_MKN_RAM_TCP_REQUEST_BUFFER_]; int d = 0; uint32_t i; do { - bzero(buffer, _KUL_TCP_REQUEST_BUFFER_); - d = SSL_read(ssl, buffer, _KUL_TCP_REQUEST_BUFFER_ - 1); + bzero(buffer, _MKN_RAM_TCP_REQUEST_BUFFER_); + d = SSL_read(ssl, buffer, _MKN_RAM_TCP_REQUEST_BUFFER_ - 1); if (d == 0) break; if (d < 0) { short se = 0; @@ -59,34 +59,34 @@ void kul::https::Requester::send(const std::string& h, const std::string& req, c } } -void kul::https::_1_1GetRequest::send() KTHROW(kul::http::Exception) { +void mkn::ram::https::_1_1GetRequest::send() KTHROW(mkn::ram::http::Exception) { KUL_DBG_FUNC_ENTER try { std::stringstream ss; Requester::send(_host, toString(), _port, ss, ssl); auto rec(ss.str()); - kul::http::_1_1Response res(kul::http::_1_1Response::FROM_STRING(rec)); + mkn::ram::http::_1_1Response res(mkn::ram::http::_1_1Response::FROM_STRING(rec)); handleResponse(res); - } catch (const kul::Exception& e) { + } catch (const mkn::kul::Exception& e) { KLOG(ERR) << e.debug(); KEXCEPT(Exception, "HTTP GET failed with host: " + _host); } } -void kul::https::_1_1PostRequest::send() KTHROW(kul::http::Exception) { +void mkn::ram::https::_1_1PostRequest::send() KTHROW(mkn::ram::http::Exception) { KUL_DBG_FUNC_ENTER try { std::stringstream ss; Requester::send(_host, toString(), _port, ss, ssl); auto rec(ss.str()); - kul::http::_1_1Response res(kul::http::_1_1Response::FROM_STRING(rec)); + mkn::ram::http::_1_1Response res(mkn::ram::http::_1_1Response::FROM_STRING(rec)); handleResponse(res); - } catch (const kul::Exception& e) { + } catch (const mkn::kul::Exception& e) { KLOG(ERR) << e.debug(); KEXCEPT(Exception, "HTTP POST failed with host: " + _host); } } -#endif //_KUL_INCLUDE_HTTPS_ \ No newline at end of file +#endif //_MKN_RAM_INCLUDE_HTTPS_ \ No newline at end of file diff --git a/os/win/src/https/server.cpp b/os/win/src/https/server.cpp index b889db2..acdb01d 100644 --- a/os/win/src/https/server.cpp +++ b/os/win/src/https/server.cpp @@ -28,10 +28,10 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifdef _KUL_INCLUDE_HTTPS_ -#include "kul/https.hpp" +#ifdef _MKN_RAM_INCLUDE_HTTPS_ +#include "mkn/ram/https.hpp" -void kul::https::Server::loop(std::map& fds) KTHROW(kul::tcp::Exception) { +void mkn::ram::https::Server::loop(std::map& fds) KTHROW(kul::tcp::Exception) { KUL_DBG_FUNC_ENTER auto ret = poll(1000); @@ -95,20 +95,20 @@ void kul::https::Server::loop(std::map& fds) KTHROW(kul::tcp::Exce if (del.size()) closeFDs(fds, del); } -void kul::https::Server::setChain(const kul::File& f) { +void mkn::ram::https::Server::setChain(const mkn::kul::File& f) { if (!f) KEXCEPTION("HTTPS Server chain file does not exist: " + f.full()); if (SSL_CTX_use_certificate_chain_file(ctx, f.mini().c_str()) <= 0) KEXCEPTION("HTTPS Server SSL_CTX_use_PrivateKey_file failed"); } -kul::https::Server& kul::https::Server::init() { +mkn::ram::https::Server& mkn::ram::https::Server::init() { KUL_DBG_FUNC_ENTER if (!crt) KEXCEPTION("HTTPS Server crt file does not exist: " + crt.full()); if (!key) KEXCEPTION("HTTPS Server key file does not exist: " + key.full()); SSL_library_init(); SSL_load_error_strings(); OpenSSL_add_ssl_algorithms(); - ctx = SSL_CTX_new(_KUL_HTTPS_SERVER_METHOD_()); + ctx = SSL_CTX_new(_MKN_RAM_HTTPS_SERVER_METHOD_()); if (!ctx) KEXCEPTION("HTTPS Server SSL_CTX failed SSL_CTX_new"); if (SSL_CTX_use_certificate_file(ctx, crt.mini().c_str(), SSL_FILETYPE_PEM) <= 0) KEXCEPTION("HTTPS Server SSL_CTX_use_certificate_file failed"); @@ -120,12 +120,12 @@ kul::https::Server& kul::https::Server::init() { return *this; } -void kul::https::Server::stop() { +void mkn::ram::https::Server::stop() { KUL_DBG_FUNC_ENTER s = 0; ERR_free_strings(); EVP_cleanup(); - for (size_t i = 0; i < _KUL_TCP_MAX_CLIENT_; i++) { + for (size_t i = 0; i < _MKN_RAM_TCP_MAX_CLIENT_; i++) { auto ssl = ssl_clients[i]; if (ssl) { SSL_shutdown(ssl); @@ -133,10 +133,10 @@ void kul::https::Server::stop() { } } if (ctx) SSL_CTX_free(ctx); - kul::http::Server::stop(); + mkn::ram::http::Server::stop(); } -void kul::https::Server::handleBuffer(std::map& fds, const int& fd, char* in, +void mkn::ram::https::Server::handleBuffer(std::map& fds, const int& fd, char* in, const int& read, int& e) { in[read] = '\0'; std::string res; @@ -150,22 +150,22 @@ void kul::https::Server::handleBuffer(std::map& fds, const int& fd if (f) break; } if (!f) KEXCEPTION("Logic error encountered, probably https attempt on http port"); - std::shared_ptr req = handleRequest(fd, s, res); - const kul::http::_1_1Response& rs(respond(*req.get())); + std::shared_ptr req = handleRequest(fd, s, res); + const mkn::ram::http::_1_1Response& rs(respond(*req.get())); std::string ret(rs.toString()); e = ::SSL_write(ssl_clients[m_fds[fd].fd], ret.c_str(), ret.length()); - } catch (const kul::http::Exception& e1) { + } catch (const mkn::ram::http::Exception& e1) { KERR << e1.stack(); e = -1; } fds[fd] = 1; } -bool kul::https::Server::receive(std::map& fds, const int& fd) { +bool mkn::ram::https::Server::receive(std::map& fds, const int& fd) { KUL_DBG_FUNC_ENTER char* in = getOrCreateBufferFor(fd); - bzero(in, _KUL_TCP_READ_BUFFER_); - int e = 0, read = ::SSL_read(ssl_clients[m_fds[fd].fd], in, _KUL_TCP_READ_BUFFER_ - 1); + bzero(in, _MKN_RAM_TCP_READ_BUFFER_); + int e = 0, read = ::SSL_read(ssl_clients[m_fds[fd].fd], in, _MKN_RAM_TCP_READ_BUFFER_ - 1); if (read < 0) e = -1; else if (read > 0) { @@ -183,4 +183,4 @@ bool kul::https::Server::receive(std::map& fds, const int& fd) { return true; } -#endif //_KUL_INCLUDE_HTTPS_ \ No newline at end of file +#endif //_MKN_RAM_INCLUDE_HTTPS_ \ No newline at end of file diff --git a/remotes.json b/remotes.json new file mode 100644 index 0000000..dde4a13 --- /dev/null +++ b/remotes.json @@ -0,0 +1,9 @@ +{ + "remotes": [ + { + "name": "conan-center", + "url": "https://conan.bintray.com", + "verify_ssl": true + } + ] +} \ No newline at end of file diff --git a/src/fcgi/server.cpp b/src/fcgi/server.cpp index ce0dd3d..9ee2cbe 100644 --- a/src/fcgi/server.cpp +++ b/src/fcgi/server.cpp @@ -30,15 +30,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifdef _KUL_INCLUDE_FCGI_ -#include "kul/asio/fcgi.hpp" +#include "mkn/kul/asio/fcgi.hpp" -#include "kul/http.hpp" +#include "mkn/ram/http.hpp" -void kul::asio::fcgi::Server::start() KTHROW(Exception) { +void mkn::ram::asio::fcgi::Server::start() KTHROW(Exception) { KUL_DBG_FUNC_ENTER nfds = lisock + 1; - _started = kul::Now::MILLIS(); + _started = mkn::kul::Now::MILLIS(); listen(lisock, 256); clilen = sizeof(cli_addr); s = true; @@ -53,10 +53,10 @@ void kul::asio::fcgi::Server::start() KTHROW(Exception) { m_workerPool.start(); } -bool kul::asio::fcgi::Server::receive(std::map& fds, const int& fd) { +bool mkn::ram::asio::fcgi::Server::receive(std::map& fds, const int& fd) { KUL_DBG_FUNC_ENTER uint8_t* in = getOrCreateBufferFor(fd); - bzero(in, _KUL_TCP_READ_BUFFER_); + bzero(in, _MKN_RAM_TCP_READ_BUFFER_); int e = 0, read = readFrom(fd, in, MSG_DONTWAIT); if (read < 0) e = -1; @@ -72,7 +72,7 @@ bool kul::asio::fcgi::Server::receive(std::map& fds, const int& fd return false; } -void kul::asio::fcgi::Server::write(std::map& fds, const int& fd, const uint8_t* out, +void mkn::ram::asio::fcgi::Server::write(std::map& fds, const int& fd, const uint8_t* out, const size_t size) { KUL_DBG_FUNC_ENTER writeTo(fd, out, size); @@ -81,7 +81,7 @@ void kul::asio::fcgi::Server::write(std::map& fds, const int& fd, closeFDs(fds, del); } -void kul::asio::fcgi::Server::PARSE_FIRST(std::map& fds, uint8_t* const in, +void mkn::ram::asio::fcgi::Server::PARSE_FIRST(std::map& fds, uint8_t* const in, const int& inLen, const int& fd) KTHROW(kul::fcgi::Exception) { KUL_DBG_FUNC_ENTER @@ -106,7 +106,7 @@ void kul::asio::fcgi::Server::PARSE_FIRST(std::map& fds, uint8_t* } } -void kul::asio::fcgi::Server::PARSE(std::map& fds, uint8_t* const in, +void mkn::ram::asio::fcgi::Server::PARSE(std::map& fds, uint8_t* const in, const int& inLen, const int& fd, size_t pos) KTHROW(kul::fcgi::Exception) { KUL_DBG_FUNC_ENTER @@ -137,9 +137,9 @@ void kul::asio::fcgi::Server::PARSE(std::map& fds, uint8_t* const } } -size_t kul::asio::fcgi::Server::FORM_RESPONSE(const FCGI_Message& msg, uint8_t* out) { +size_t mkn::ram::asio::fcgi::Server::FORM_RESPONSE(const FCGI_Message& msg, uint8_t* out) { KUL_DBG_FUNC_ENTER - bzero(out, _KUL_TCP_READ_BUFFER_); + bzero(out, _MKN_RAM_TCP_READ_BUFFER_); size_t pos = 0; out[pos++] = 1; @@ -154,7 +154,7 @@ size_t kul::asio::fcgi::Server::FORM_RESPONSE(const FCGI_Message& msg, uint8_t* out[pos++] = rid[0]; } - kul::http::_1_1Response resp(msg.response()); + mkn::ram::http::_1_1Response resp(msg.response()); resp.header("Content-Type", "text/html"); std::string response(resp.toString()); auto ending(response.find("\r\n")); diff --git a/src/http/request.cpp b/src/http/request.cpp index 192018b..f609bee 100644 --- a/src/http/request.cpp +++ b/src/http/request.cpp @@ -28,23 +28,23 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "kul/http.hpp" +#include "mkn/ram/http.hpp" -void kul::http::A1_1Request::send() KTHROW(kul::http::Exception) { +void mkn::ram::http::A1_1Request::send() KTHROW(mkn::ram::http::Exception) { KUL_DBG_FUNC_ENTER std::stringstream ss; { - kul::tcp::Socket sock; + mkn::ram::tcp::Socket sock; if (!sock.connect(_host, _port)) KEXCEPTION("TCP FAILED TO CONNECT!"); const std::string& req(toString()); sock.write(req.c_str(), req.size()); - std::unique_ptr buf(new char[_KUL_TCP_REQUEST_BUFFER_]); + std::unique_ptr buf(new char[_MKN_RAM_TCP_REQUEST_BUFFER_]); int64_t i, d = 0; bool more = false; do { - bzero(buf.get(), _KUL_TCP_REQUEST_BUFFER_); + bzero(buf.get(), _MKN_RAM_TCP_REQUEST_BUFFER_); more = false; - d = sock.read(buf.get(), _KUL_TCP_REQUEST_BUFFER_ - 1, more); + d = sock.read(buf.get(), _MKN_RAM_TCP_REQUEST_BUFFER_ - 1, more); if (d == -1) return; for (i = 0; i < d; i++) ss << buf[i]; } while (more); @@ -56,7 +56,7 @@ void kul::http::A1_1Request::send() KTHROW(kul::http::Exception) { class RequestHeaders { private: - kul::hash::map::S2S _hs; + mkn::kul::hash::map::S2S _hs; RequestHeaders() { _hs.insert("Connection", "close"); _hs.insert("Accept", "text/html"); @@ -67,9 +67,9 @@ class RequestHeaders { static RequestHeaders i; return i; } - kul::hash::map::S2S defaultHeaders(const kul::http::A1_1Request& r, + mkn::kul::hash::map::S2S defaultHeaders(const mkn::ram::http::A1_1Request& r, const std::string& body = "") const { - kul::hash::map::S2S hs1; + mkn::kul::hash::map::S2S hs1; for (const auto& h : _hs) if (!r.header("Transfer-Encoding")) hs1.insert(h.first, h.second); if (!body.empty() && !r.header("Content-Length") && !r.header("Transfer-Encoding")) @@ -78,7 +78,7 @@ class RequestHeaders { } }; -std::string kul::http::_1_1GetRequest::toString() const { +std::string mkn::ram::http::_1_1GetRequest::toString() const { KUL_DBG_FUNC_ENTER std::stringstream ss; ss << method() << " /" << _path; @@ -98,7 +98,7 @@ std::string kul::http::_1_1GetRequest::toString() const { return ss.str(); } -std::string kul::http::_1_1PostRequest::toString() const { +std::string mkn::ram::http::_1_1PostRequest::toString() const { KUL_DBG_FUNC_ENTER std::stringstream ss; ss << method() << " /" << _path << " " << version(); diff --git a/src/http/response.cpp b/src/http/response.cpp index 748f553..54e651e 100644 --- a/src/http/response.cpp +++ b/src/http/response.cpp @@ -28,12 +28,12 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "kul/http.hpp" +#include "mkn/ram/http.hpp" -std::string kul::http::_1_1Response::toString() const { +std::string mkn::ram::http::_1_1Response::toString() const { std::stringstream ss; - ss << version() << " " << _s << " " << r << kul::os::EOL(); - for (const auto& h : headers()) ss << h.first << ": " << h.second << kul::os::EOL(); + ss << version() << " " << _s << " " << r << mkn::kul::os::EOL(); + for (const auto& h : headers()) ss << h.first << ": " << h.second << mkn::kul::os::EOL(); for (const auto& p : cookies()) { ss << "Set-Cookie: " << p.first << "=" << p.second.value() << "; "; if (p.second.domain().size()) ss << "domain=" << p.second.domain() << "; "; @@ -44,13 +44,13 @@ std::string kul::http::_1_1Response::toString() const { ss << "expires=Sat, 25-Apr-2015 13:33:33 GMT; maxage=-1; "; else if (p.second.expires().size()) ss << "expires=" << p.second.expires() << "; "; - ss << kul::os::EOL(); + ss << mkn::kul::os::EOL(); } - ss << kul::os::EOL() << body() << "\r\n" << '\0'; + ss << mkn::kul::os::EOL() << body() << "\r\n" << '\0'; return ss.str(); } -kul::http::_1_1Response kul::http::_1_1Response::FROM_STRING(std::string& b) { +mkn::ram::http::_1_1Response mkn::ram::http::_1_1Response::FROM_STRING(std::string& b) { _1_1Response res; std::stringstream ss(b); @@ -66,7 +66,7 @@ kul::http::_1_1Response kul::http::_1_1Response::FROM_STRING(std::string& b) { break; } else if (line.find("Set-Cookie:") == 0) { std::string lef, rig, cook(line.substr(11)); - kul::String::TRIM(cook); + mkn::kul::String::TRIM(cook); lef = cook; auto eq(cook.find("=")); if (eq != std::string::npos) { @@ -77,11 +77,11 @@ kul::http::_1_1Response kul::http::_1_1Response::FROM_STRING(std::string& b) { } else { if (line.find(":") != std::string::npos) { std::vector bits; - kul::String::SPLIT(line, ':', bits); + mkn::kul::String::SPLIT(line, ':', bits); std::string l(bits[0]); std::string r(bits[1]); - kul::String::TRIM(l); - kul::String::TRIM(r); + mkn::kul::String::TRIM(l); + mkn::kul::String::TRIM(r); res.header(l, r); } else res.header(line, ""); diff --git a/src/http/server.cpp b/src/http/server.cpp index 4491100..beedd29 100644 --- a/src/http/server.cpp +++ b/src/http/server.cpp @@ -28,21 +28,21 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "kul/http.hpp" +#include "mkn/ram/http.hpp" -std::shared_ptr kul::http::AServer::handleRequest(const int& fd, +std::shared_ptr mkn::ram::http::AServer::handleRequest(const int& fd, const std::string& b, std::string& path) { KUL_DBG_FUNC_ENTER std::string a; - std::shared_ptr req; + std::shared_ptr req; { std::string mode, host; std::stringstream ss(b); { std::string r; std::getline(ss, r); - std::vector l0 = kul::String::SPLIT(r, ' '); + std::vector l0 = mkn::kul::String::SPLIT(r, ' '); if (!l0.size()) KEXCEPTION("Malformed request found: " + b); std::string s(l0[1]); if (l0[0] == "GET") { @@ -72,22 +72,22 @@ std::shared_ptr kul::http::AServer::handleRequest(const while (std::getline(ss, l)) { if (l.size() <= 1) break; std::vector bits; - kul::String::SPLIT(l, ':', bits); - kul::String::TRIM(bits[0]); + mkn::kul::String::SPLIT(l, ':', bits); + mkn::kul::String::TRIM(bits[0]); std::stringstream sv; if (bits.size() > 1) sv << bits[1]; for (size_t i = 2; i < bits.size(); i++) sv << ":" << bits[i]; std::string v(sv.str()); - kul::String::TRIM(v); + mkn::kul::String::TRIM(v); if (*v.rbegin() == '\r') v.pop_back(); if (bits[0] == "Cookie") { - for (const auto& coo : kul::String::SPLIT(v, ';')) { + for (const auto& coo : mkn::kul::String::SPLIT(v, ';')) { if (coo.find("=") == std::string::npos) { req->cookie(coo, ""); KOUT(ERR) << "Cookie without equals sign, skipping"; } else { std::vector kv; - kul::String::ESC_SPLIT(coo, '=', kv); + mkn::kul::String::ESC_SPLIT(coo, '=', kv); if (kv[1].size()) req->cookie(kv[0], kv[1]); } } @@ -105,7 +105,7 @@ std::shared_ptr kul::http::AServer::handleRequest(const return req; } -void kul::http::AServer::handleBuffer(std::map& fds, const int& fd, char* in, +void mkn::ram::http::AServer::handleBuffer(std::map& fds, const int& fd, char* in, const int& read, int& e) { KUL_DBG_FUNC_ENTER; in[read] = '\0'; @@ -125,7 +125,7 @@ void kul::http::AServer::handleBuffer(std::map& fds, const int& fd std::string ret(rs.toString()); writeTo(fd, ret.c_str(), ret.length()); e = 0; - } catch (const kul::http::Exception& e1) { + } catch (const mkn::ram::http::Exception& e1) { KLOG(ERR) << e1.stack(); e = -1; } diff --git a/test.cpp b/test.cpp index c52e841..4def9e3 100644 --- a/test.cpp +++ b/test.cpp @@ -28,41 +28,41 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#define _KUL_INCLUDE_HTTPS_ -#define __KUL_RAM_NOMAIN__ +#define _MKN_RAM_INCLUDE_HTTPS_ +#define __MKN_RAM_NOMAIN__ #include "usage.cpp" -class TestHTTPSServer : public kul::https::Server { +class TestHTTPSServer : public mkn::ram::https::Server { private: void operator()() { start(); } public: TestHTTPSServer() - : kul::https::Server(_KUL_HTTP_TEST_PORT_, kul::File("res/test/server.crt"), - kul::File("res/test/server.key")) {} - friend class kul::Thread; + : mkn::ram::https::Server(_MKN_RAM_HTTP_TEST_PORT_, mkn::kul::File("res/test/server.crt"), + mkn::kul::File("res/test/server.key")) {} + friend class mkn::kul::Thread; }; -class HTTPS_Get : public kul::https::_1_1GetRequest { +class HTTPS_Get : public mkn::ram::https::_1_1GetRequest { public: HTTPS_Get(std::string const& host, std::string const& path = "", uint16_t const& port = 80) - : kul::https::_1_1GetRequest(host, path, port) {} + : mkn::ram::https::_1_1GetRequest(host, path, port) {} }; int main(int argc, char *argv[]) { - using namespace kul::http; + using namespace mkn::ram::http; { TestHTTPSServer serv; serv.init().withResponse([](const A1_1Request &r) { - KLOG(NON) << kul::os::EOL() << r.toString(); + KLOG(NON) << mkn::kul::os::EOL() << r.toString(); return _1_1Response{}.withBody("HELLO WORLD"); }); - kul::Thread t(std::ref(serv)); + mkn::kul::Thread t(std::ref(serv)); t.run(); - kul::this_thread::sleep(333); + mkn::kul::this_thread::sleep(333); if (t.exception()) std::rethrow_exception(t.exception()); { - HTTPS_Get get("localhost", "index.html", _KUL_HTTP_TEST_PORT_); - KLOG(NON) << kul::os::EOL() << get.toString(); + HTTPS_Get get("localhost", "index.html", _MKN_RAM_HTTP_TEST_PORT_); + KLOG(NON) << mkn::kul::os::EOL() << get.toString(); get.withResponse( - [](const kul::http::_1_1Response &r) { KLOG(INF) << kul::os::EOL() << r.toString(); }) + [](const mkn::ram::http::_1_1Response &r) { KLOG(INF) << mkn::kul::os::EOL() << r.toString(); }) .send(); } serv.stop(); diff --git a/test/client.cpp b/test/client.cpp index 17b749b..f0bf177 100644 --- a/test/client.cpp +++ b/test/client.cpp @@ -30,60 +30,60 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include -#include "kul/http.hpp" -#include "kul/tcp.hpp" +#include "mkn/kul/signal.hpp" -#ifdef _KUL_INCLUDE_HTTPS_ -#include "kul/https.hpp" -#endif //_KUL_INCLUDE_HTTPS_ +#include "mkn/ram/tcp.hpp" +#include "mkn/ram/http.hpp" -#include "kul/html4.hpp" +#ifdef _MKN_RAM_INCLUDE_HTTPS_ +#include "mkn/ram/https.hpp" +#endif //_MKN_RAM_INCLUDE_HTTPS_ -#include "kul/signal.hpp" +#include "mkn/ram/html4.hpp" -#ifndef _KUL_HTTP_TEST_PORT_ -#define _KUL_HTTP_TEST_PORT_ 8888 -#endif /*_KUL_HTTP_TEST_PORT_*/ -#ifdef _KUL_INCLUDE_HTTPS_ +#ifndef _MKN_RAM_HTTP_TEST_PORT_ +#define _MKN_RAM_HTTP_TEST_PORT_ 8888 +#endif /*_MKN_RAM_HTTP_TEST_PORT_*/ +#ifdef _MKN_RAM_INCLUDE_HTTPS_ -namespace kul { +namespace mkn { namespace ram { -class HTTPS_Get : public kul::https::_1_1GetRequest { +class HTTPS_Get : public mkn::ram::https::_1_1GetRequest { public: HTTPS_Get(std::string const& host, std::string const& path = "", uint16_t const& port = 80) - : kul::https::_1_1GetRequest(host, path, port) {} - void handleResponse(const kul::hash::map::S2S &h, std::string const& b) override { + : mkn::ram::https::_1_1GetRequest(host, path, port) {} + void handleResponse(const mkn::kul::hash::map::S2S &h, std::string const& b) override { KLOG(INF) << "HTTPS GET RESPONSE:\n" << b; } }; -class HTTPS_Post : public kul::https::_1_1PostRequest { +class HTTPS_Post : public mkn::ram::https::_1_1PostRequest { public: HTTPS_Post(std::string const& host, std::string const& path = "", uint16_t const& port = 80) - : kul::https::_1_1PostRequest(host, path, port) {} - void handleResponse(const kul::hash::map::S2S &h, std::string const& b) override { + : mkn::ram::https::_1_1PostRequest(host, path, port) {} + void handleResponse(const mkn::kul::hash::map::S2S &h, std::string const& b) override { KUL_DBG_FUNC_ENTER for (const auto &p : h) KOUT(NON) << "HEADER: " << p.first << " : " << p.second; KOUT(NON) << "HTTPS POST RESPONSE:\n" << b; } }; -#endif //_KUL_INCLUDE_HTTPS_ +#endif //_MKN_RAM_INCLUDE_HTTPS_ -class Get : public kul::http::_1_1GetRequest { +class Get : public mkn::ram::http::_1_1GetRequest { public: Get(std::string const& host, std::string const& path = "", uint16_t const& port = 80) - : kul::http::_1_1GetRequest(host, path, port) {} - void handleResponse(const kul::hash::map::S2S &h, std::string const& b) override { + : mkn::ram::http::_1_1GetRequest(host, path, port) {} + void handleResponse(const mkn::kul::hash::map::S2S &h, std::string const& b) override { KLOG(INF) << b; // if(b.substr(0, b.size() - 2) != "MULTI HTTP PROVIDED BY KUL") // KEXCEPTION("Body failed :" + b + ":"); } }; -class Post : public kul::http::_1_1PostRequest { +class Post : public mkn::ram::http::_1_1PostRequest { public: Post(std::string const& host, std::string const& path = "", uint16_t const& port = 80) - : kul::http::_1_1PostRequest(host, path, port) {} - void handleResponse(const kul::hash::map::S2S &h, std::string const& b) override { + : mkn::ram::http::_1_1PostRequest(host, path, port) {} + void handleResponse(const mkn::kul::hash::map::S2S &h, std::string const& b) override { if (b.substr(0, b.size() - 2) != "MULTI HTTP PROVIDED BY KUL") KEXCEPTION("Body failed :" + b + ":"); } @@ -92,49 +92,49 @@ class Post : public kul::http::_1_1PostRequest { } int main(int argc, char *argv[]) { - kul::Signal s; + mkn::kul::Signal s; try { - kul::ram::Get g("localhost", "index.html", _KUL_HTTP_TEST_PORT_); - kul::ChroncurrentThreadPool<> requests(10, 0); + mkn::kul::ram::Get g("localhost", "index.html", _MKN_RAM_HTTP_TEST_PORT_); + mkn::kul::ChroncurrentThreadPool<> requests(10, 0); for (size_t i = 0; i < 5000; i++) requests.async([&]() { g.send(); }); requests.start().finish(); - // kul::ram::Get("localhost", "index.html", _KUL_HTTP_TEST_PORT_).send(); + // mkn::kul::ram::Get("localhost", "index.html", _MKN_RAM_HTTP_TEST_PORT_).send(); // for(size_t i = 0; i < 100; i++) - // kul::ram::Post("localhost", "index.html", - // _KUL_HTTP_TEST_PORT_).send(); + // mkn::kul::ram::Post("localhost", "index.html", + // _MKN_RAM_HTTP_TEST_PORT_).send(); - // kul::this_thread::sleep(500); + // mkn::kul::this_thread::sleep(500); // for(size_t i = 0; i < 1000; i++) - // kul::ram::Get("localhost", "index.html", - // _KUL_HTTP_TEST_PORT_).send(); + // mkn::kul::ram::Get("localhost", "index.html", + // _MKN_RAM_HTTP_TEST_PORT_).send(); // for(size_t i = 0; i < 1000; i++) - // kul::ram::Post("localhost", "index.html", - // _KUL_HTTP_TEST_PORT_).send(); + // mkn::kul::ram::Post("localhost", "index.html", + // _MKN_RAM_HTTP_TEST_PORT_).send(); - // kul::this_thread::sleep(500); + // mkn::kul::this_thread::sleep(500); - // #ifdef _KUL_INCLUDE_HTTPS_ + // #ifdef _MKN_RAM_INCLUDE_HTTPS_ // for(size_t i = 0; i < 100; i++) - // kul::ram::HTTPS_Get("localhost", "index.html", - // _KUL_HTTP_TEST_PORT_).send(); + // mkn::kul::ram::HTTPS_Get("localhost", "index.html", + // _MKN_RAM_HTTP_TEST_PORT_).send(); // for(size_t i = 0; i < 100; i++) - // kul::ram::HTTPS_Post("localhost", "index.html", - // _KUL_HTTP_TEST_PORT_).send(); + // mkn::kul::ram::HTTPS_Post("localhost", "index.html", + // _MKN_RAM_HTTP_TEST_PORT_).send(); - // kul::this_thread::sleep(500); + // mkn::kul::this_thread::sleep(500); // for(size_t i = 0; i < 1000; i++) - // kul::ram::HTTPS_Get("localhost", "index.html", - // _KUL_HTTP_TEST_PORT_).send(); + // mkn::kul::ram::HTTPS_Get("localhost", "index.html", + // _MKN_RAM_HTTP_TEST_PORT_).send(); // for(size_t i = 0; i < 1000; i++) - // kul::ram::HTTPS_Post("localhost", "index.html", - // _KUL_HTTP_TEST_PORT_).send(); - // #endif//_KUL_INCLUDE_HTTPS_ + // mkn::kul::ram::HTTPS_Post("localhost", "index.html", + // _MKN_RAM_HTTP_TEST_PORT_).send(); + // #endif//_MKN_RAM_INCLUDE_HTTPS_ - } catch (const kul::Exception &e) { + } catch (const mkn::kul::Exception &e) { KERR << e.stack(); return 1; } catch (const std::exception &e) { diff --git a/test/fcgi.cpp b/test/fcgi.cpp index 2b36a34..c33ce00 100644 --- a/test/fcgi.cpp +++ b/test/fcgi.cpp @@ -28,13 +28,13 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "kul/asio/fcgi.hpp" -#include "kul/signal.hpp" +#include "mkn/kul/asio/fcgi.hpp" +#include "mkn/kul/signal.hpp" int main(int argc, char *argv[]) { - kul::Signal sig; + mkn::kul::Signal sig; try { - kul::asio::fcgi::Server s(5863, 4, 8); + mkn::ram::asio::fcgi::Server s(5863, 4, 8); sig.intr([&](int16_t) { KERR << "Interrupted"; @@ -43,7 +43,7 @@ int main(int argc, char *argv[]) { exit(2); }); s.join(); - } catch (const kul::Exception &e) { + } catch (const mkn::kul::Exception &e) { KERR << e.stack(); } catch (const std::exception &e) { KERR << e.what(); diff --git a/test/server.cpp b/test/server.cpp index 8566f61..f13d5f2 100644 --- a/test/server.cpp +++ b/test/server.cpp @@ -30,153 +30,153 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include -#include "kul/http.hpp" -#include "kul/tcp.hpp" +#include "mkn/ram/http.hpp" +#include "mkn/kul/tcp.hpp" -#ifdef _KUL_INCLUDE_HTTPS_ -#include "kul/https.hpp" -#endif //_KUL_INCLUDE_HTTPS_ +#ifdef _MKN_RAM_INCLUDE_HTTPS_ +#include "mkn/ram/https.hpp" +#endif //_MKN_RAM_INCLUDE_HTTPS_ -#include "kul/html4.hpp" +#include "mkn/kul/html4.hpp" -#include "kul/signal.hpp" +#include "mkn/kul/signal.hpp" -#ifndef _KUL_HTTP_TEST_PORT_ -#define _KUL_HTTP_TEST_PORT_ 8888 -#endif /*_KUL_HTTP_TEST_PORT_*/ +#ifndef _MKN_RAM_HTTP_TEST_PORT_ +#define _MKN_RAM_HTTP_TEST_PORT_ 8888 +#endif /*_MKN_RAM_HTTP_TEST_PORT_*/ -namespace kul { +namespace mkn { namespace ram { -void addResponseHeaders(kul::http::_1_1Response &r) { - if (!r.header("Date")) r.header("Date", kul::DateTime::NOW()); +void addResponseHeaders(mkn::ram::http::_1_1Response &r) { + if (!r.header("Date")) r.header("Date", mkn::kul::DateTime::NOW()); if (!r.header("Connection")) r.header("Connection", "close"); if (!r.header("Content-Type")) r.header("Content-Type", "text/html"); if (!r.header("Content-Length")) r.header("Content-Length", std::to_string(r.body().size())); } -class TestHTTPServer : public kul::http::Server { +class TestHTTPServer : public mkn::ram::http::Server { private: void operator()() { start(); } public: - kul::http::_1_1Response respond(kul::http::A1_1Request const& req) { + mkn::ram::http::_1_1Response respond(mkn::ram::http::A1_1Request const& req) { KUL_DBG_FUNC_ENTER - kul::http::_1_1Response r; + mkn::ram::http::_1_1Response r; r.body("HTTP PROVIDED BY KUL"); addResponseHeaders(r); return r; } - TestHTTPServer() : kul::http::Server(_KUL_HTTP_TEST_PORT_) {} - friend class kul::Thread; + TestHTTPServer() : mkn::ram::http::Server(_MKN_RAM_HTTP_TEST_PORT_) {} + friend class mkn::kul::Thread; }; -class TestMultiHTTPServer : public kul::http::MultiServer { +class TestMultiHTTPServer : public mkn::ram::http::MultiServer { private: void operator()() { start(); } public: - kul::http::_1_1Response respond(kul::http::A1_1Request const& req) { + mkn::ram::http::_1_1Response respond(mkn::ram::http::A1_1Request const& req) { KUL_DBG_FUNC_ENTER - kul::http::_1_1Response r; + mkn::ram::http::_1_1Response r; r.body("MULTI HTTP PROVIDED BY KUL"); addResponseHeaders(r); return r; } TestMultiHTTPServer(uint16_t const& threads) - : kul::http::MultiServer(_KUL_HTTP_TEST_PORT_, threads) {} - TestMultiHTTPServer() : kul::http::MultiServer(_KUL_HTTP_TEST_PORT_, 2, 4) {} - friend class kul::Thread; + : mkn::ram::http::MultiServer(_MKN_RAM_HTTP_TEST_PORT_, threads) {} + TestMultiHTTPServer() : mkn::ram::http::MultiServer(_MKN_RAM_HTTP_TEST_PORT_, 2, 4) {} + friend class mkn::kul::Thread; }; -#ifdef _KUL_INCLUDE_HTTPS_ -class TestHTTPSServer : public kul::https::Server { +#ifdef _MKN_RAM_INCLUDE_HTTPS_ +class TestHTTPSServer : public mkn::ram::https::Server { private: void operator()() { start(); } public: - kul::http::_1_1Response respond(kul::http::A1_1Request const& req) { + mkn::ram::http::_1_1Response respond(mkn::ram::http::A1_1Request const& req) { KUL_DBG_FUNC_ENTER - kul::http::_1_1Response r; + mkn::ram::http::_1_1Response r; r.body("HTTPS PROVIDED BY KUL: " + req.method()); addResponseHeaders(r); return r; } TestHTTPSServer() - : kul::https::Server(_KUL_HTTP_TEST_PORT_, kul::File("res/test/server.crt"), - kul::File("res/test/server.key")) {} - friend class kul::Thread; + : mkn::ram::https::Server(_MKN_RAM_HTTP_TEST_PORT_, mkn::kul::File("res/test/server.crt"), + mkn::kul::File("res/test/server.key")) {} + friend class mkn::kul::Thread; }; -class TestMultiHTTPSServer : public kul::https::MultiServer { +class TestMultiHTTPSServer : public mkn::ram::https::MultiServer { private: void operator()() { start(); } public: - kul::http::_1_1Response respond(kul::http::A1_1Request const& req) { + mkn::ram::http::_1_1Response respond(mkn::ram::http::A1_1Request const& req) { KUL_DBG_FUNC_ENTER - kul::http::_1_1Response r; + mkn::ram::http::_1_1Response r; r.body("MULTI HTTPS PROVIDED BY KUL"); addResponseHeaders(r); return r; } TestMultiHTTPSServer() - : kul::https::MultiServer(_KUL_HTTP_TEST_PORT_, 3, kul::File("res/test/server.crt"), - kul::File("res/test/server.key")) {} - friend class kul::Thread; + : mkn::ram::https::MultiServer(_MKN_RAM_HTTP_TEST_PORT_, 3, mkn::kul::File("res/test/server.crt"), + mkn::kul::File("res/test/server.key")) {} + friend class mkn::kul::Thread; }; -class HTTPS_Get : public kul::https::_1_1GetRequest { +class HTTPS_Get : public mkn::ram::https::_1_1GetRequest { public: HTTPS_Get(std::string const& host, std::string const& path = "", uint16_t const& port = 80) - : kul::https::_1_1GetRequest(host, path, port) {} - void handleResponse(const kul::hash::map::S2S &h, std::string const& b) override { + : mkn::ram::https::_1_1GetRequest(host, path, port) {} + void handleResponse(const mkn::kul::hash::map::S2S &h, std::string const& b) override { KLOG(INF) << "HTTPS GET RESPONSE:\n" << b; } }; -class HTTPS_Post : public kul::https::_1_1PostRequest { +class HTTPS_Post : public mkn::ram::https::_1_1PostRequest { public: HTTPS_Post(std::string const& host, std::string const& path = "", uint16_t const& port = 80) - : kul::https::_1_1PostRequest(host, path, port) {} - void handleResponse(const kul::hash::map::S2S &h, std::string const& b) override { + : mkn::ram::https::_1_1PostRequest(host, path, port) {} + void handleResponse(const mkn::kul::hash::map::S2S &h, std::string const& b) override { KUL_DBG_FUNC_ENTER for (const auto &p : h) KOUT(NON) << "HEADER: " << p.first << " : " << p.second; KOUT(NON) << "HTTPS POST RESPONSE:\n" << b; } }; -#endif //_KUL_INCLUDE_HTTPS_ +#endif //_MKN_RAM_INCLUDE_HTTPS_ -class TestSocketServer : public kul::tcp::SocketServer { +class TestSocketServer : public mkn::ram::tcp::SocketServer { private: void operator()() { start(); } public: bool handle(char *in, char *out) override { KUL_DBG_FUNC_ENTER - kul::http::_1_1Response getResponse; + mkn::ram::http::_1_1Response getResponse; addResponseHeaders(getResponse); getResponse.body("magicmansion"); std::string getResponseStr(getResponse.toString()); std::strcpy(out, getResponseStr.c_str()); return true; // if true, close connection } - TestSocketServer() : kul::tcp::SocketServer(_KUL_HTTP_TEST_PORT_) {} - friend class kul::Thread; + TestSocketServer() : mkn::ram::tcp::SocketServer(_MKN_RAM_HTTP_TEST_PORT_) {} + friend class mkn::kul::Thread; }; -class Get : public kul::http::_1_1GetRequest { +class Get : public mkn::ram::http::_1_1GetRequest { public: Get(std::string const& host, std::string const& path = "", uint16_t const& port = 80) - : kul::http::_1_1GetRequest(host, path, port) {} - void handleResponse(const kul::hash::map::S2S &h, std::string const& b) override { + : mkn::ram::http::_1_1GetRequest(host, path, port) {} + void handleResponse(const mkn::kul::hash::map::S2S &h, std::string const& b) override { KLOG(INF) << "GET RESPONSE:\n" << b; } }; -class Post : public kul::http::_1_1PostRequest { +class Post : public mkn::ram::http::_1_1PostRequest { public: Post(std::string const& host, std::string const& path = "", uint16_t const& port = 80) - : kul::http::_1_1PostRequest(host, path, port) {} - void handleResponse(const kul::hash::map::S2S &h, std::string const& b) override { + : mkn::ram::http::_1_1PostRequest(host, path, port) {} + void handleResponse(const mkn::kul::hash::map::S2S &h, std::string const& b) override { KUL_DBG_FUNC_ENTER for (const auto &p : h) KOUT(NON) << "HEADER: " << p.first << " : " << p.second; KOUT(NON) << "POST RESPONSE:\n" << b; @@ -186,14 +186,14 @@ class Post : public kul::http::_1_1PostRequest { } // namespace kul int main(int argc, char *argv[]) { - kul::Signal s; + mkn::kul::Signal s; try { // KOUT(NON) << "TCP Socket SERVER"; // { - // kul::ram::TestSocketServer serv; - // kul::Thread t(std::ref(serv)); + // mkn::kul::ram::TestSocketServer serv; + // mkn::kul::Thread t(std::ref(serv)); // t.run(); - // kul::this_thread::sleep(100); + // mkn::kul::this_thread::sleep(100); // if(t.exception()) std::rethrow_exception(t.exception()); // s.abrt([&](int16_t i){ serv.stop(); }); // t.join(); @@ -201,60 +201,60 @@ int main(int argc, char *argv[]) { // } // KOUT(NON) << "Single HTTP SERVER"; // { - // kul::ram::TestHTTPServer serv; - // kul::Thread t(std::ref(serv)); + // mkn::kul::ram::TestHTTPServer serv; + // mkn::kul::Thread t(std::ref(serv)); // t.run(); - // kul::this_thread::sleep(100); + // mkn::kul::this_thread::sleep(100); // if(t.exception()) std::rethrow_exception(t.exception()); // s.abrt([&](int16_t i){ serv.stop(); }); // t.join(); // } KOUT(NON) << "Multi HTTP SERVER"; { - kul::ram::TestMultiHTTPServer serv(10); - kul::Thread t(std::ref(serv)); + mkn::kul::ram::TestMultiHTTPServer serv(10); + mkn::kul::Thread t(std::ref(serv)); t.run(); s.abrt([&](int16_t i) { serv.stop(); }); - kul::this_thread::sleep(100); + mkn::kul::this_thread::sleep(100); if (t.exception()) std::rethrow_exception(t.exception()); - kul::this_thread::sleep(100); + mkn::kul::this_thread::sleep(100); serv.join(); serv.stop(); - kul::this_thread::sleep(100); + mkn::kul::this_thread::sleep(100); } -#ifdef _KUL_INCLUDE_HTTPS_ +#ifdef _MKN_RAM_INCLUDE_HTTPS_ // KOUT(NON) << "Single HTTPS SERVER"; // { -// kul::ram::TestHTTPSServer serv; +// mkn::kul::ram::TestHTTPSServer serv; // serv.init(); -// kul::Thread t(std::ref(serv)); +// mkn::kul::Thread t(std::ref(serv)); // t.run(); -// kul::this_thread::sleep(100); +// mkn::kul::this_thread::sleep(100); // if(t.exception()) std::rethrow_exception(t.exception()); -// kul::this_thread::sleep(1000); +// mkn::kul::this_thread::sleep(1000); // serv.stop(); -// kul::this_thread::sleep(100); +// mkn::kul::this_thread::sleep(100); // t.join(); // } // KOUT(NON) << "Multi HTTPS SERVER"; // { -// kul::ram::TestMultiHTTPSServer serv; +// mkn::kul::ram::TestMultiHTTPSServer serv; // serv.init(); -// kul::Thread t(std::ref(serv)); +// mkn::kul::Thread t(std::ref(serv)); // t.run(); -// kul::this_thread::sleep(100); +// mkn::kul::this_thread::sleep(100); // if(t.exception()) std::rethrow_exception(t.exception()); -// kul::this_thread::sleep(5000); +// mkn::kul::this_thread::sleep(5000); // serv.join(); // serv.stop(); -// kul::this_thread::sleep(100); +// mkn::kul::this_thread::sleep(100); // t.join(); // } -#endif //_KUL_INCLUDE_HTTPS_ +#endif //_MKN_RAM_INCLUDE_HTTPS_ - } catch (const kul::Exception &e) { + } catch (const mkn::kul::Exception &e) { KERR << e.stack(); return 1; } catch (const std::exception &e) { diff --git a/usage.cpp b/usage.cpp index 736d2c5..94eea21 100644 --- a/usage.cpp +++ b/usage.cpp @@ -30,106 +30,107 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include -#include "kul/http.hpp" -#include "kul/tcp.hpp" +#include "mkn/kul/signal.hpp" -#ifdef _KUL_INCLUDE_HTTPS_ -#include "kul/https.hpp" -#endif //_KUL_INCLUDE_HTTPS_ +#include "mkn/ram/tcp.hpp" +#include "mkn/ram/http.hpp" -#include "kul/html4.hpp" +#ifdef _MKN_RAM_INCLUDE_HTTPS_ +#include "mkn/ram/https.hpp" +#endif //_MKN_RAM_INCLUDE_HTTPS_ + +#include "mkn/ram/html4.hpp" -#include "kul/signal.hpp" #ifdef _WIN32 #define bzero ZeroMemory #endif -#ifndef _KUL_HTTP_TEST_PORT_ -#define _KUL_HTTP_TEST_PORT_ 8888 -#endif /*_KUL_HTTP_TEST_PORT_*/ +#ifndef _MKN_RAM_HTTP_TEST_PORT_ +#define _MKN_RAM_HTTP_TEST_PORT_ 8888 +#endif /*_MKN_RAM_HTTP_TEST_PORT_*/ -namespace kul { +namespace mkn { namespace ram { -class TestHTTPServer : public kul::http::Server { +class TestHTTPServer : public mkn::ram::http::Server { private: void operator()() { start(); } public: - kul::http::_1_1Response respond(kul::http::A1_1Request const& req) { - kul::http::_1_1Response r; + mkn::ram::http::_1_1Response respond(mkn::ram::http::A1_1Request const& req) { + mkn::ram::http::_1_1Response r; return r.withBody("HTTP PROVIDED BY KUL").withDefaultHeaders(); } - TestHTTPServer() : kul::http::Server(_KUL_HTTP_TEST_PORT_) {} - friend class kul::Thread; + TestHTTPServer() : mkn::ram::http::Server(_MKN_RAM_HTTP_TEST_PORT_) {} + friend class mkn::kul::Thread; }; -class TestMultiHTTPServer : public kul::http::MultiServer { +class TestMultiHTTPServer : public mkn::ram::http::MultiServer { private: void operator()() { start(); } public: - kul::http::_1_1Response respond(kul::http::A1_1Request const& req) { - kul::http::_1_1Response r; + mkn::ram::http::_1_1Response respond(mkn::ram::http::A1_1Request const& req) { + mkn::ram::http::_1_1Response r; return r.withBody("MULTI HTTP PROVIDED BY KUL").withDefaultHeaders(); } - TestMultiHTTPServer() : kul::http::MultiServer(_KUL_HTTP_TEST_PORT_, 3) {} - friend class kul::Thread; + TestMultiHTTPServer() : mkn::ram::http::MultiServer(_MKN_RAM_HTTP_TEST_PORT_, 3) {} + friend class mkn::kul::Thread; }; -#ifdef _KUL_INCLUDE_HTTPS_ -class TestHTTPSServer : public kul::https::Server { +#ifdef _MKN_RAM_INCLUDE_HTTPS_ +class TestHTTPSServer : public mkn::ram::https::Server { private: void operator()() { start(); } public: - kul::http::_1_1Response respond(kul::http::A1_1Request const& req) { - kul::http::_1_1Response r; + mkn::ram::http::_1_1Response respond(mkn::ram::http::A1_1Request const& req) { + mkn::ram::http::_1_1Response r; return r.withBody("HTTPS PROVIDED BY KUL: " + req.method()).withDefaultHeaders(); } TestHTTPSServer() - : kul::https::Server(_KUL_HTTP_TEST_PORT_, kul::File("res/test/server.crt"), - kul::File("res/test/server.key")) {} - friend class kul::Thread; + : mkn::ram::https::Server(_MKN_RAM_HTTP_TEST_PORT_, mkn::kul::File("res/test/server.crt"), + mkn::kul::File("res/test/server.key")) {} + friend class mkn::kul::Thread; }; -class TestMultiHTTPSServer : public kul::https::MultiServer { +class TestMultiHTTPSServer : public mkn::ram::https::MultiServer { private: void operator()() { start(); } public: - kul::http::_1_1Response respond(kul::http::A1_1Request const& req) { - kul::http::_1_1Response r; + mkn::ram::http::_1_1Response respond(mkn::ram::http::A1_1Request const& req) { + mkn::ram::http::_1_1Response r; return r.withBody("MULTI HTTPS PROVIDED BY KUL: " + req.method()).withDefaultHeaders(); } TestMultiHTTPSServer(const uint8_t &acceptThreads = 1, const uint8_t &workerThreads = 1) - : kul::https::MultiServer(_KUL_HTTP_TEST_PORT_, acceptThreads, workerThreads, - kul::File("res/test/server.crt"), - kul::File("res/test/server.key")) {} - friend class kul::Thread; + : mkn::ram::https::MultiServer(_MKN_RAM_HTTP_TEST_PORT_, acceptThreads, workerThreads, + mkn::kul::File("res/test/server.crt"), + mkn::kul::File("res/test/server.key")) {} + friend class mkn::kul::Thread; }; -class HTTPS_Get : public kul::https::_1_1GetRequest { +class HTTPS_Get : public mkn::ram::https::_1_1GetRequest { public: HTTPS_Get(std::string const& host, std::string const& path = "", uint16_t const& port = 80) - : kul::https::_1_1GetRequest(host, path, port) {} - void handleResponse(const kul::http::_1_1Response &r) override { + : mkn::ram::https::_1_1GetRequest(host, path, port) {} + void handleResponse(mkn::ram::http::_1_1Response const& r) override { KLOG(INF) << "HTTPS GET RESPONSE: " << r.body(); } }; -class HTTPS_Post : public kul::https::_1_1PostRequest { +class HTTPS_Post : public mkn::ram::https::_1_1PostRequest { public: HTTPS_Post(std::string const& host, std::string const& path = "", uint16_t const& port = 80) - : kul::https::_1_1PostRequest(host, path, port) {} - void handleResponse(const kul::http::_1_1Response &r) override { + : mkn::ram::https::_1_1PostRequest(host, path, port) {} + void handleResponse(const mkn::ram::http::_1_1Response &r) override { for (const auto &p : r.headers()) KOUT(NON) << "HEADER: " << p.first << " : " << p.second; KOUT(NON) << "HTTPS POST RESPONSE: " << r.body(); } }; -#endif //_KUL_INCLUDE_HTTPS_ +#endif //_MKN_RAM_INCLUDE_HTTPS_ -class TestSocketServer : public kul::tcp::SocketServer { +class TestSocketServer : public mkn::ram::tcp::SocketServer { private: void operator()() { start(); } @@ -140,23 +141,23 @@ class TestSocketServer : public kul::tcp::SocketServer { outLen = rep.size(); return true; } - TestSocketServer() : kul::tcp::SocketServer(_KUL_HTTP_TEST_PORT_) {} - friend class kul::Thread; + TestSocketServer() : mkn::ram::tcp::SocketServer(_MKN_RAM_HTTP_TEST_PORT_) {} + friend class mkn::kul::Thread; }; -class Get : public kul::http::_1_1GetRequest { +class Get : public mkn::ram::http::_1_1GetRequest { public: Get(std::string const& host, std::string const& path = "", uint16_t const& port = 80) - : kul::http::_1_1GetRequest(host, path, port) {} - void handleResponse(const kul::http::_1_1Response &r) override { + : mkn::ram::http::_1_1GetRequest(host, path, port) {} + void handleResponse(const mkn::ram::http::_1_1Response &r) override { KLOG(INF) << "GET RESPONSE: " << r.body(); } }; -class Post : public kul::http::_1_1PostRequest { +class Post : public mkn::ram::http::_1_1PostRequest { public: Post(std::string const& host, std::string const& path = "", uint16_t const& port = 80) - : kul::http::_1_1PostRequest(host, path, port) {} - void handleResponse(const kul::http::_1_1Response &r) override { + : mkn::ram::http::_1_1PostRequest(host, path, port) {} + void handleResponse(const mkn::ram::http::_1_1Response &r) override { for (const auto &p : r.headers()) KOUT(NON) << "HEADER: " << p.first << " : " << p.second; KOUT(NON) << "HTTPS POST RESPONSE: " << r.body(); } @@ -165,85 +166,87 @@ class Post : public kul::http::_1_1PostRequest { class Test { public: Test() { -#ifdef _KUL_INCLUDE_HTTPS_ +#ifdef _MKN_RAM_INCLUDE_HTTPS_ KOUT(NON) << "Single HTTPS SERVER"; { TestHTTPSServer serv; serv.init(); - kul::Thread t(std::ref(serv)); + mkn::kul::Thread t(std::ref(serv)); t.run(); - kul::this_thread::sleep(333); + mkn::kul::this_thread::sleep(333); if (t.exception()) std::rethrow_exception(t.exception()); { - HTTPS_Get("localhost", "index.html", _KUL_HTTP_TEST_PORT_).send(); + HTTPS_Get("localhost", "index.html", _MKN_RAM_HTTP_TEST_PORT_).send(); if (t.exception()) std::rethrow_exception(t.exception()); - HTTPS_Post p("localhost", "index.html", _KUL_HTTP_TEST_PORT_); + HTTPS_Post p("localhost", "index.html", _MKN_RAM_HTTP_TEST_PORT_); p.body("tsop"); p.send(); if (t.exception()) std::rethrow_exception(t.exception()); - HTTPS_Get("localhost", "index.html", _KUL_HTTP_TEST_PORT_).send(); + HTTPS_Get("localhost", "index.html", _MKN_RAM_HTTP_TEST_PORT_).send(); if (t.exception()) std::rethrow_exception(t.exception()); } - kul::this_thread::sleep(100); + mkn::kul::this_thread::sleep(100); serv.stop(); t.join(); - kul::this_thread::sleep(100); + mkn::kul::this_thread::sleep(100); } KOUT(NON) << "Multi HTTPS SERVER"; { TestMultiHTTPSServer serv(1, 5); serv.init(); - kul::Thread t(std::ref(serv)); + mkn::kul::Thread t(std::ref(serv)); t.run(); - kul::this_thread::sleep(333); + mkn::kul::this_thread::sleep(333); std::atomic index(0); auto getter = [&]() { - HTTPS_Get("localhost", "index.html_" + std::to_string(index++), _KUL_HTTP_TEST_PORT_) + HTTPS_Get("localhost", "index.html_" + std::to_string(index++), _MKN_RAM_HTTP_TEST_PORT_) .send(); }; - auto except = [&t](const kul::Exception &e) { + auto except = [&t](const mkn::kul::Exception &e) { KLOG(ERR) << e.stack(); if (t.exception()) std::rethrow_exception(t.exception()); }; - kul::ChroncurrentThreadPool<> ctp(3, 1); + mkn::kul::ChroncurrentThreadPool<> ctp(3, 1); for (size_t i = 0; i < 999; i++) ctp.async(getter, except); ctp.finish(1000000000); - kul::this_thread::sleep(100); + mkn::kul::this_thread::sleep(100); serv.stop(); - kul::this_thread::sleep(100); + mkn::kul::this_thread::sleep(100); serv.join(); t.join(); } -#endif // _KUL_HTTPS_ +#endif // _MKN_RAM_HTTPS_ KOUT(NON) << "Single HTTP SERVER"; { TestHTTPServer serv; - kul::Thread t(std::ref(serv)); + mkn::kul::Thread t(std::ref(serv)); t.run(); - kul::this_thread::sleep(333); + mkn::kul::this_thread::sleep(333); if (t.exception()) std::rethrow_exception(t.exception()); { - Get("localhost", "index.html", _KUL_HTTP_TEST_PORT_).send(); - Get("localhost", "index.html", _KUL_HTTP_TEST_PORT_).send(); + Get("localhost", "index.html", _MKN_RAM_HTTP_TEST_PORT_).send(); + Get("localhost", "index.html", _MKN_RAM_HTTP_TEST_PORT_).send(); if (t.exception()) std::rethrow_exception(t.exception()); - Post p("localhost", "index.html", _KUL_HTTP_TEST_PORT_); + Post p("localhost", "index.html", _MKN_RAM_HTTP_TEST_PORT_); p.body("tsop"); p.send(); if (t.exception()) std::rethrow_exception(t.exception()); } - kul::this_thread::sleep(100); + mkn::kul::this_thread::sleep(100); serv.stop(); - kul::this_thread::sleep(100); + mkn::kul::this_thread::sleep(100); t.join(); } KLOG(INF) << "Test socket connection"; { - kul::tcp::Socket sock; - if (!sock.connect("google.com", 80)) KEXCEPTION("TCP FAILED TO CONNECT!"); + mkn::ram::tcp::Socket sock; + if (!sock.connect("google.com", 80)) + KEXCEPT(mkn::ram::tcp::Exception, "TCP FAILED TO CONNECT!"); + Get get("google.com"); std::string req(get.toString()); std::vector v1, v2; @@ -254,30 +257,31 @@ class Test { sock.write(s1.c_str(), s1.size()); sock.write(s2.c_str(), s2.size()); KOUT(NON) << "Reading from TCP socket"; - char buf[_KUL_TCP_REQUEST_BUFFER_]; - bzero(buf, _KUL_TCP_REQUEST_BUFFER_); - sock.read(buf, _KUL_TCP_REQUEST_BUFFER_); + char buf[_MKN_RAM_TCP_REQUEST_BUFFER_]; + bzero(buf, _MKN_RAM_TCP_REQUEST_BUFFER_); + sock.read(buf, _MKN_RAM_TCP_REQUEST_BUFFER_); sock.close(); } KOUT(NON) << "TCP Socket SERVER"; - kul::this_thread::sleep(500); + mkn::kul::this_thread::sleep(500); { TestSocketServer serv; - kul::Thread t(std::ref(serv)); + mkn::kul::Thread t(std::ref(serv)); t.run(); - kul::this_thread::sleep(333); + mkn::kul::this_thread::sleep(333); if (t.exception()) std::rethrow_exception(t.exception()); for (size_t i = 0; i < 5; i++) { - kul::tcp::Socket sock; - if (!sock.connect("localhost", _KUL_HTTP_TEST_PORT_)) KEXCEPTION("TCP FAILED TO CONNECT!"); + mkn::ram::tcp::Socket sock; + if (!sock.connect("localhost", _MKN_RAM_HTTP_TEST_PORT_)) + KEXCEPT(mkn::ram::tcp::Exception, "TCP FAILED TO CONNECT!"); const char *c = "socketserver"; sock.write(c, strlen(c)); - char buf[_KUL_TCP_REQUEST_BUFFER_]; - bzero(buf, _KUL_TCP_REQUEST_BUFFER_); - sock.read(buf, _KUL_TCP_REQUEST_BUFFER_); + char buf[_MKN_RAM_TCP_REQUEST_BUFFER_]; + bzero(buf, _MKN_RAM_TCP_REQUEST_BUFFER_); + sock.read(buf, _MKN_RAM_TCP_REQUEST_BUFFER_); sock.close(); } @@ -285,19 +289,19 @@ class Test { serv.stop(); t.join(); } - // kul::this_thread::sleep(100); + // mkn::kul::this_thread::sleep(100); // { // TestMultiHTTPServer serv; - // kul::Thread t(std::ref(serv)); + // mkn::kul::Thread t(std::ref(serv)); // t.run(); - // kul::this_thread::sleep(333); + // mkn::kul::this_thread::sleep(333); // for(size_t i = 0; i < 10; i++){ - // Get("localhost", "index.html", _KUL_HTTP_TEST_PORT_).send(); + // Get("localhost", "index.html", _MKN_RAM_HTTP_TEST_PORT_).send(); // if(t.exception()) std::rethrow_exception(t.exception()); // } - // kul::this_thread::sleep(100); + // mkn::kul::this_thread::sleep(100); // serv.stop(); - // kul::this_thread::sleep(100); + // mkn::kul::this_thread::sleep(100); // serv.join(); // } // KOUT(NON) << "FINISHED!"; @@ -306,13 +310,13 @@ class Test { } // namespace ram } // namespace kul -#ifndef __KUL_RAM_NOMAIN__ +#ifndef __MKN_RAM_NOMAIN__ int main(int argc, char *argv[]) { - kul::Signal s; + mkn::kul::Signal s; try { - kul::ram::Test(); + mkn::ram::Test(); - } catch (const kul::Exception &e) { + } catch (const mkn::kul::Exception &e) { KERR << e.stack(); return 1; } catch (const std::exception &e) { @@ -324,4 +328,4 @@ int main(int argc, char *argv[]) { } return 0; } -#endif //__KUL_RAM_NOMAIN__ \ No newline at end of file +#endif //__MKN_RAM_NOMAIN__ \ No newline at end of file