Skip to content

Commit

Permalink
hotplace rev.607 grooming
Browse files Browse the repository at this point in the history
  • Loading branch information
princeb612 committed Sep 13, 2024
1 parent b7766dc commit b727f17
Show file tree
Hide file tree
Showing 19 changed files with 182 additions and 145 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# history

* Revision 607
* [changed] sprintf
* [deprecated] close_listener (see close_socket)

* Revision 604
* [changed] rename x509 to x509cert

Expand Down
28 changes: 13 additions & 15 deletions sdk/base/stream/printf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <sdk/base/basic/base16.hpp>
#include <sdk/base/basic/ieee754.hpp>
#include <sdk/base/basic/valist.hpp>
#include <sdk/base/nostd/pattern.hpp>
#include <sdk/base/stream/printf.hpp>
#include <sdk/base/stream/tstring.hpp>
#include <sdk/base/string/string.hpp>
Expand Down Expand Up @@ -47,8 +48,6 @@ return_t sprintf(stream_t* stream, const char* fmt, valist va) {
__leave2;
}

stream->clear();

if (nullptr == fmt) {
ret = errorcode_t::invalid_parameter;
__leave2;
Expand Down Expand Up @@ -85,18 +84,17 @@ return_t sprintf(stream_t* stream, const char* fmt, valist va) {
typedef std::list<int> va_array_t;
va_map_t va_map; /* pair(position, {id}) */
va_array_t va_array;
for (i = 0; i != va.size(); i++) {
size_t id = i + 1;
std::string find = format("{%zi}", id);
size_t pos = 0;
while (true) {
pos = formatter.find_first_of(find.c_str(), pos);
if ((size_t)-1 == pos) {
break;
}
va_map.insert(std::make_pair(pos, i));
pos += find.size();
}
t_aho_corasick<char> ac;
for (i = 0; i < va.size(); i++) {
auto pat = format("{%zi}", i + 1);
ac.insert(pat.c_str(), pat.size());
}
ac.build();
auto result = ac.search(formatter.c_str(), formatter.size());
for (auto item : result) {
const range_t& range = item.first;
unsigned patid = item.second;
va_map.insert({range.begin, patid});
}

// Step2. relocate valist, build list
Expand All @@ -120,7 +118,7 @@ return_t sprintf(stream_t* stream, const char* fmt, valist va) {
va_new.at(i, v);
formatter_map_t::iterator fmt_it = formats.find(v.type);
if (formats.end() != fmt_it) {
formatter.replace(format("{%i}", idx + 1).c_str(), fmt_it->second.c_str(), bufferio_flag_t::run_once);
formatter.replace(format("{%i}", idx + 1).c_str(), fmt_it->second.c_str(), 0, bufferio_flag_t::run_once);
}
i++;
}
Expand Down
51 changes: 31 additions & 20 deletions sdk/base/unittest/testcase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,17 +247,22 @@ void test_case::test(return_t result, const char* test_function, const char* mes
critical_section_guard guard(_lock);

console_color_t color = console_color_t::yellow;
if (errorcode_t::success == result) {
_total._count_success++;
} else if (errorcode_t::not_supported == result) {
color = console_color_t::cyan;
_total._count_not_supported++;
} else if (errorcode_t::low_security == result) {
color = console_color_t::yellow;
_total._count_low_security++;
} else {
color = console_color_t::red;
_total._count_fail++;
switch (result) {
case errorcode_t::success:
_total._count_success++;
break;
case errorcode_t::not_supported:
color = console_color_t::cyan;
_total._count_not_supported++;
break;
case errorcode_t::low_security:
color = console_color_t::yellow;
_total._count_low_security++;
break;
default:
color = console_color_t::red;
_total._count_fail++;
break;
}

unittest_item_t item;
Expand All @@ -278,14 +283,19 @@ void test_case::test(return_t result, const char* test_function, const char* mes
unittest_map_t::iterator it = pib.first;
test_status_t& status = it->second;

if (errorcode_t::success == result) {
status._test_stat._count_success++;
} else if (errorcode_t::not_supported == result) {
status._test_stat._count_not_supported++;
} else if (errorcode_t::low_security == result) {
status._test_stat._count_low_security++;
} else {
status._test_stat._count_fail++;
switch (result) {
case errorcode_t::success:
status._test_stat._count_success++;
break;
case errorcode_t::not_supported:
status._test_stat._count_not_supported++;
break;
case errorcode_t::low_security:
status._test_stat._count_low_security++;
break;
default:
status._test_stat._count_fail++;
break;
}

status._test_list.push_back(item); /* append a unittest_item_t */
Expand Down Expand Up @@ -559,8 +569,9 @@ void test_case::report_failed(basic_stream& stream) {
for (const auto& pair : _test_map) {
for (const auto& item : pair.second._test_list) {
switch (item._result) {
case errorcode_t::not_supported:
case errorcode_t::low_security:
case errorcode_t::not_supported:
case errorcode_t::pending:
case errorcode_t::success:
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion sdk/crypto/basic/crypto_advisor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ return_t crypto_advisor::build_if_necessary() {
_evp_cipher_map.insert(std::make_pair(item->_cipher, &item->method));
}

set_feature(item->method.fetchname, advisor_feature_cipher); // workaround for openssl-1.1.1 - EVP_CIPHER_fetch("aes-128-wrap") return nullptr
set_feature(item->method.fetchname, advisor_feature_cipher); // workaround for openssl-1.1.1 - EVP_CIPHER_fetch("aes-128-wrap") return nullptr
set_feature(item->method.fetchname, advisor_feature_wrap);
}

Expand Down
2 changes: 1 addition & 1 deletion sdk/crypto/basic/openssl_crypt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class openssl_crypt : public crypt_t {
* "chacha20", "chacha20-poly1305",
* "aes-128-wrap", "aes-192-wrap", "aes-256-wrap"
*
* unsupported algorithms (build default option)
* unsupported algorithms
* openssl 1.1.1 - rc5
* openssl 3.0 - bf, cast5, idea, rc2, rc5, seed series
* openssl 3.1 - bf, cast5, idea, rc2, rc5, seed series
Expand Down
2 changes: 1 addition & 1 deletion sdk/crypto/basic/openssl_hash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class openssl_hash : public hash_t {
* "blake2b512", "blake2s256"
* "ripemd160", "whirlpool"
*
* unsupported algorithms (build default option)
* unsupported algorithms
* openssl 1.1.1 - sha2-512/224, sha2-512/256
* openssl 3.0 - md4, whirlpool
* openssl 3.1 - md4, whirlpool
Expand Down
5 changes: 5 additions & 0 deletions sdk/crypto/jose/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,8 @@
| O | RSA | JWK/PEM | |
| O | EC | JWK/PEM | crv "P-256","P-384","P-521" |
| O | OKP | JWK/PEM | crv "Ed25519","Ed448","X25519","X448" |

## JSON parser performance comparison

* https://github.com/miloyip/nativejson-benchmark
* https://github.com/fabienrenaud/java-json-benchmark
16 changes: 6 additions & 10 deletions sdk/io/system/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,23 +389,19 @@ return_t close_socket(socket_t sock, bool bOnOff, uint16 wLinger) {
return ret;
}

return_t close_listener(unsigned int nSockets, socket_t* Sockets) {
return_t close_listener(unsigned int count, socket_t* sockets) {
return_t ret = errorcode_t::success;

__try2 {
if (nullptr == Sockets) {
if (nullptr == sockets) {
ret = errorcode_t::invalid_parameter;
__leave2;
}

for (unsigned int i = 0; i < nSockets; i++) {
if (INVALID_SOCKET != Sockets[i]) {
#if defined __linux__
close(Sockets[i]);
#elif defined _WIN32 || defined _WIN64
closesocket(Sockets[i]);
#endif
Sockets[i] = INVALID_SOCKET;
for (unsigned int i = 0; i < count; i++) {
if (INVALID_SOCKET != sockets[i]) {
close_socket(sockets[i], true, 0);
sockets[i] = INVALID_SOCKET;
}
}
}
Expand Down
16 changes: 5 additions & 11 deletions sdk/io/system/socket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ return_t create_socket(socket_t* socket_created, sockaddr_storage_t* sockaddr_cr
* @error error code (see error.hpp)
* @example
* unsigned int nFamily[2] = { AF_INET, AF_INET6 }; // IPv4 and IPv6
* socket_t Sockets[2] = { INVALID_SOCKET, INVALID_SOCKET };
* create_listener (2, nFamily, Sockets, IPPROTO_TCP, 9000);
* socket_t sockets[2] = { INVALID_SOCKET, INVALID_SOCKET };
* create_listener (2, nFamily, sockets, IPPROTO_TCP, 9000);
* // ...
* close_listener (2, Sockets);
* for (auto sock : sockets) {
* close_socket(sock, true, 0);
* }
*/
return_t create_listener(unsigned int size_vector, unsigned int* vector_family, socket_t* vector_socket, int protocol_type, uint32 port,
bool support_win32_acceptex = false);
Expand Down Expand Up @@ -76,14 +78,6 @@ return_t connect_socket_addr(socket_t sock, sockaddr_storage_t* pSockAddr, size_
* @param uint16 linger [in]
*/
return_t close_socket(socket_t sock, bool onoff, uint16 linger);
/**
* @brief stop listen
* @param unsigned int nSockets [in]
* @param socket_t* Sockets [in]
* @return error code (see error.hpp)
* @example see create_listener
*/
return_t close_listener(unsigned int nSockets, socket_t* Sockets);

enum SOCK_WAIT_FLAGS {
SOCK_WAIT_READABLE = 1 << 0,
Expand Down
6 changes: 3 additions & 3 deletions sdk/net/tls/dtls_client_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ return_t dtls_client_socket::close(socket_t sock, tls_context_t* tls_handle) {

__try2 {
if (nullptr != tls_handle) {
_tls->close(tls_handle);
_tls->close(tls_handle); // closure notification
}
client_socket::close(sock, tls_handle);
}
Expand All @@ -96,8 +96,8 @@ return_t dtls_client_socket::recvfrom(socket_t sock, tls_context_t* tls_handle,
while (true) {
ret = wait_socket(sock, get_wto(), SOCK_WAIT_READABLE);
if (errorcode_t::success == ret) {
ret = _tls->recvfrom(tls_handle, tls_io_flag_t::read_ssl_read | tls_io_flag_t::read_bio_write | tls_io_flag_t::read_socket_recv, ptr_data,
size_data, cbread, addr, addrlen);
int mode = tls_io_flag_t::read_ssl_read | tls_io_flag_t::read_bio_write | tls_io_flag_t::read_socket_recv;
ret = _tls->recvfrom(tls_handle, mode, ptr_data, size_data, cbread, addr, addrlen);
if (errorcode_t::pending == ret) {
continue;
} else {
Expand Down
Loading

0 comments on commit b727f17

Please sign in to comment.