Skip to content

Commit

Permalink
Refac (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipDeegan authored Nov 10, 2021
1 parent 086bd5f commit cae03b6
Show file tree
Hide file tree
Showing 54 changed files with 1,269 additions and 968 deletions.
24 changes: 0 additions & 24 deletions .github/workflows/build.yml

This file was deleted.

19 changes: 19 additions & 0 deletions .github/workflows/build_nix.yml
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions .github/workflows/build_osx.yml
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions .github/workflows/build_win.yml
Original file line number Diff line number Diff line change
@@ -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"'
14 changes: 7 additions & 7 deletions README.noformat
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,34 @@ 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
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

8 changes: 5 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
2 changes: 1 addition & 1 deletion conanfile.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[requires]
OpenSSL/1.1.0g@conan/stable
OpenSSL/1.1.0k@conan/stable
52 changes: 27 additions & 25 deletions inc/kul/asio/fcgi.hpp → inc/mkn/ram/asio/fcgi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <cstring>

#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;
Expand Down Expand Up @@ -74,34 +75,34 @@ class FCGI_Message {
FCGI_Message() {}
};

class Server : public kul::tcp::SocketServer<uint8_t> {
class Server : public mkn::ram::tcp::SocketServer<uint8_t> {
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<uint64_t, std::unique_ptr<FCGI_Message>> msgs;
std::unordered_map<int, std::unique_ptr<uint8_t[]>> 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<uint8_t[]>(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<FCGI_Message>();
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);
}

Expand Down Expand Up @@ -134,12 +135,12 @@ class Server : public kul::tcp::SocketServer<uint8_t> {
void operateAccept(const size_t& threadID) {
std::map<int, uint8_t> 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();
Expand All @@ -161,11 +162,11 @@ class Server : public kul::tcp::SocketServer<uint8_t> {
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<uint8_t>(port),
: mkn::ram::tcp::SocketServer<uint8_t>(port),
m_acceptThreads(acceptThreads),
m_workerThreads(workerThreads),
m_acceptPool(acceptThreads),
Expand All @@ -180,15 +181,15 @@ class Server : public kul::tcp::SocketServer<uint8_t> {
m_workerPool.stop();
}

void start() KTHROW(kul::tcp::Exception) override;
void start() KTHROW(mkn::ram::tcp::Exception) override;

void join() {
if (!started()) start();
m_acceptPool.join();
m_workerPool.join();
}
void stop() override {
kul::tcp::SocketServer<uint8_t>::stop();
mkn::ram::tcp::SocketServer<uint8_t>::stop();
m_acceptPool.stop();
m_workerPool.stop();
}
Expand All @@ -200,6 +201,7 @@ class Server : public kul::tcp::SocketServer<uint8_t> {

} // namespace fcgi
} // namespace asio
} // END NAMESPACE kul
} // namespace ram
} // namespace mkn

#endif /* _KUL_ASIO_FCGI_HPP_ */
#endif /* _MKN_RAM_ASIO_FCGI_HPP_ */
File renamed without changes.
20 changes: 10 additions & 10 deletions inc/kul/html/def.hpp → inc/mkn/ram/html/def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_ "<!DOCTYPE html>"
#endif /* _KUL_HTML_DOC_TYPE_ */
#ifndef _MKN_RAM_HTML_DOC_TYPE_
#define _MKN_RAM_HTML_DOC_TYPE_ "<!DOCTYPE html>"
#endif /* _MKN_RAM_HTML_DOC_TYPE_ */

#endif /* _KUL_HTML_DEF_HPP_ */
#endif /* _MKN_RAM_HTML_DEF_HPP_ */
20 changes: 11 additions & 9 deletions inc/kul/html/page.hpp → inc/mkn/ram/html/page.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 << "<html>";
ss << *h->render();
Expand All @@ -92,7 +93,8 @@ class Page {
}
};

} // END NAMESPACE html4
} // END NAMESPACE kul
} // namespace html4
} // namespace ram
} // namespace mkn

#endif /* _KUL_HTML_PAGE_HPP_ */
#endif /* _MKN_RAM_HTML_PAGE_HPP_ */
Loading

0 comments on commit cae03b6

Please sign in to comment.