Skip to content

Commit

Permalink
hotplace rev.521 HTTP/2 study
Browse files Browse the repository at this point in the history
  • Loading branch information
princeb612 committed May 7, 2024
1 parent 5eb8ca6 commit 80fe421
Show file tree
Hide file tree
Showing 55 changed files with 1,637 additions and 1,302 deletions.
2 changes: 1 addition & 1 deletion sdk/base/basic/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ variant& variant::set_binary_new(const binary_t& bin) {
return *this;
}

int variant::to_int() const { return t_variant_to_int<int>(_vt); }
int variant::to_int() const { return t_to_int<int>(_vt); }

return_t variant::to_binary(binary_t& target) const {
return_t ret = errorcode_t::success;
Expand Down
2 changes: 1 addition & 1 deletion sdk/base/basic/variant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ typedef struct __variant_t {
} variant_t;

template <typename T>
T t_variant_to_int(const variant_t& vt) {
T t_to_int(const variant_t& vt) {
T i = 0;

switch (vt.type) {
Expand Down
12 changes: 9 additions & 3 deletions sdk/base/stream/basic_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,24 @@

namespace hotplace {

basic_stream::basic_stream(size_t allocsize, uint32 flags) : _handle(nullptr) { _bio.open(&_handle, allocsize, 1, flags); }
basic_stream::basic_stream() : _handle(nullptr) {
size_t allocsize = stream_policy::get_instance()->get_allocsize();
_bio.open(&_handle, allocsize, 1);
}

basic_stream::basic_stream(const char* data, ...) : _handle(nullptr) {
size_t allocsize = stream_policy::get_instance()->get_allocsize();
va_list ap;
va_start(ap, data);
_bio.open(&_handle, 1 << 10, 1);
_bio.open(&_handle, allocsize, 1);
_bio.vprintf(_handle, data, ap);
va_end(ap);
}

basic_stream::basic_stream(const basic_stream& stream) : _handle(nullptr) {
_bio.open(&_handle, 1 << 10, 1);
size_t allocsize = stream_policy::get_instance()->get_allocsize();

_bio.open(&_handle, allocsize, 1);
byte_t* data = nullptr;
size_t size = 0;

Expand Down
29 changes: 23 additions & 6 deletions sdk/base/stream/basic_stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ namespace hotplace {
*/
class basic_stream : public stream_t {
public:
/**
* @brief constructor
* @param size_t allocsize [inopt] default 4K
* @param uint32 flags [inopt] default 0
*/
basic_stream(size_t allocsize = (1 << 12), uint32 flags = 0);
basic_stream();
/**
* @brief constructor
* @param const char* data [in]
Expand Down Expand Up @@ -146,6 +141,28 @@ class basic_stream : public stream_t {
bufferio_context_t* _handle;
};

/**
* @remarks
* stream_policy* pol = stream_policy::get_instance();
* pol->set_allocsize(1 << 5);
*
* basic_stream bs;
* bs << "hello world";
*/
class stream_policy {
public:
static stream_policy* get_instance();
stream_policy& set_allocsize(size_t allocsize);
size_t get_allocsize();

private:
static stream_policy _instance;
stream_policy();

typedef std::map<std::string, uint32> basic_stream_policy_map_t;
basic_stream_policy_map_t _config;
};

} // namespace hotplace

#endif
39 changes: 39 additions & 0 deletions sdk/base/stream/stream_policy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* vim: set tabstop=4 shiftwidth=4 softtabstop=4 expandtab smarttab : */
/**
* @file {file}
* @author Soo Han, Kim (princeb612.kr@gmail.com)
* @desc
*
* Revision History
* Date Name Description
*/

#include <ctype.h>

#include <sdk/base/stream/basic_stream.hpp>

namespace hotplace {

const uint32 basic_stream_policy_minsize = 1 << 3;
const uint32 basic_stream_policy_allocsize = 1 << 12;

stream_policy stream_policy::_instance;

stream_policy::stream_policy() { _config.insert(std::make_pair("allocsize", basic_stream_policy_allocsize)); }

stream_policy* stream_policy::get_instance() { return &_instance; }

stream_policy& stream_policy::set_allocsize(size_t allocsize) {
if (allocsize < basic_stream_policy_minsize) {
allocsize = basic_stream_policy_minsize;
}
std::pair<basic_stream_policy_map_t::iterator, bool> pib = _config.insert(std::make_pair("allocsize", allocsize));
if (false == pib.second) {
pib.first->second = allocsize;
}
return *this;
}

size_t stream_policy::get_allocsize() { return _config["allocsize"]; }

} // namespace hotplace
6 changes: 3 additions & 3 deletions sdk/io/basic/payload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ size_t payload_member::get_space() {
} else if (variant_flag_t::flag_int == get_variant().flag()) {
space = get_variant().size();
} else if (ref) {
space = t_variant_to_int<size_t>(ref->get_variant().content());
space = t_to_int<size_t>(ref);
}
return space;
}
Expand All @@ -109,7 +109,7 @@ size_t payload_member::get_capacity() {
if (_reserve) {
space = _reserve;
} else if (ref) {
space = t_variant_to_int<size_t>(ref->get_variant().content());
space = t_to_int<size_t>(ref);
} else {
space = get_variant().size();
}
Expand Down Expand Up @@ -195,7 +195,7 @@ payload_member& payload_member::read(byte_t* ptr, size_t size_ptr, size_t* size_
if (_reserve) {
size = _reserve;
} else if (ref) {
size = t_variant_to_int<size_t>(ref->get_variant().content());
size = t_to_int<size_t>(ref);
}

if (size_ptr >= size) {
Expand Down
9 changes: 9 additions & 0 deletions sdk/io/basic/payload.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ class payload {
std::map<std::string, bool> _option; // map<group, true/false>
};

template <typename T>
T t_to_int(payload_member* v) {
T i = 0;
if (v) {
i = t_to_int<T>(v->get_variant().content());
}
return i;
}

} // namespace io
} // namespace hotplace

Expand Down
2 changes: 1 addition & 1 deletion sdk/io/cbor/cbor_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class cbor_map : public cbor_object {

template <typename KTY>
struct cbor_map_int_binder {
KTY bind(variant vt) { return t_variant_to_int<KTY>(vt.content()); }
KTY bind(variant vt) { return t_to_int<KTY>(vt.content()); }
};

template <typename KTY>
Expand Down
13 changes: 10 additions & 3 deletions sdk/io/stream/ansi_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,22 @@
namespace hotplace {
namespace io {

ansi_string::ansi_string(size_t allocsize, uint32 flags) { _bio.open(&_handle, allocsize, sizeof(char), flags | bufferio_context_flag_t::memzero_free); }
ansi_string::ansi_string() {
size_t allocsize = stream_policy::get_instance()->get_allocsize();
_bio.open(&_handle, allocsize, sizeof(char), bufferio_context_flag_t::memzero_free);
}

ansi_string::ansi_string(const char* data) {
_bio.open(&_handle, 1 << 10, sizeof(char), bufferio_context_flag_t::memzero_free);
size_t allocsize = stream_policy::get_instance()->get_allocsize();

_bio.open(&_handle, allocsize, sizeof(char), bufferio_context_flag_t::memzero_free);
_bio.write(_handle, data, strlen(data));
}

ansi_string::ansi_string(const ansi_string& stream) {
_bio.open(&_handle, 1 << 10, sizeof(char), bufferio_context_flag_t::memzero_free);
size_t allocsize = stream_policy::get_instance()->get_allocsize();

_bio.open(&_handle, allocsize, sizeof(char), bufferio_context_flag_t::memzero_free);
byte_t* data = nullptr;
size_t size = 0;

Expand Down
4 changes: 2 additions & 2 deletions sdk/io/stream/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace io {

class ansi_string : public stream_t {
public:
ansi_string(size_t allocsize = (1 << 12), uint32 flags = 0);
ansi_string();
ansi_string(const char* data);
ansi_string(const ansi_string& stream);
virtual ~ansi_string();
Expand Down Expand Up @@ -148,7 +148,7 @@ class ansi_string : public stream_t {
#if defined _WIN32 || defined _WIN64
class wide_string : public stream_t {
public:
wide_string(size_t allocsize = (1 << 12), uint32 flags = 0);
wide_string();
wide_string(const wchar_t* data);
wide_string(const wide_string& stream);
virtual ~wide_string();
Expand Down
13 changes: 10 additions & 3 deletions sdk/io/stream/unicode/wide_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,22 @@
namespace hotplace {
namespace io {

wide_string::wide_string(size_t allocsize, uint32 flags) { _bio.open(&_handle, allocsize, sizeof(wchar_t), flags | bufferio_context_flag_t::memzero_free); }
wide_string::wide_string() {
size_t allocsize = stream_policy::get_instance()->get_allocsize();
_bio.open(&_handle, allocsize, sizeof(wchar_t), bufferio_context_flag_t::memzero_free);
}

wide_string::wide_string(const wchar_t* data) {
_bio.open(&_handle, 1 << 10, sizeof(wchar_t), bufferio_context_flag_t::memzero_free);
size_t allocsize = stream_policy::get_instance()->get_allocsize();

_bio.open(&_handle, allocsize, sizeof(wchar_t), bufferio_context_flag_t::memzero_free);
_bio.write(_handle, data, wcslen(data) * sizeof(wchar_t));
}

wide_string::wide_string(const wide_string& stream) {
_bio.open(&_handle, 1 << 10, sizeof(wchar_t), bufferio_context_flag_t::memzero_free);
size_t allocsize = stream_policy::get_instance()->get_allocsize();

_bio.open(&_handle, allocsize, sizeof(wchar_t), bufferio_context_flag_t::memzero_free);
byte_t* data = nullptr;
size_t size = 0;

Expand Down
8 changes: 4 additions & 4 deletions sdk/net/basic/client_socket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ class tcp_client_socket {
* @param const char* address [IN]
* @param uint16 port [IN]
* @param uint32 timeout [IN]
* @return error code (see error.hpp)
* @return error code (see error.hpp)
*/
virtual return_t connect(socket_t* sock, tls_context_t** tls_handle, const char* address, uint16 port, uint32 timeout);
/**
* @brief close
* @param socket_t sock [IN] see connect
* @param tls_context_t* tls_handle [IN]
* @return error code (see error.hpp)
* @return error code (see error.hpp)
*/
virtual return_t close(socket_t sock, tls_context_t* tls_handle);

Expand All @@ -50,7 +50,7 @@ class tcp_client_socket {
* @param char* ptr_data [OUT]
* @param size_t size_data [IN]
* @param size_t* cbread [OUT]
* @return error code (see error.hpp)
* @return error code (see error.hpp)
*/
virtual return_t read(socket_t sock, tls_context_t* tls_handle, char* ptr_data, size_t size_data, size_t* cbread);
virtual return_t more(socket_t sock, tls_context_t* tls_handle, char* ptr_data, size_t size_data, size_t* cbread);
Expand All @@ -61,7 +61,7 @@ class tcp_client_socket {
* @param const char* ptr_data [IN]
* @param size_t size_data [IN]
* @param size_t* size_sent [OUT]
* @return error code (see error.hpp)
* @return error code (see error.hpp)
*/
virtual return_t send(socket_t sock, tls_context_t* tls_handle, const char* ptr_data, size_t size_data, size_t* size_sent);

Expand Down
Loading

0 comments on commit 80fe421

Please sign in to comment.