fix/reinit #3
@ -7,24 +7,20 @@ set(tile_VERSION_BUILD $ENV{CI_STEP_NUMBER})
|
|||||||
if(NOT tile_VERSION_BUILD)
|
if(NOT tile_VERSION_BUILD)
|
||||||
set(tile_VERSION_BUILD "0")
|
set(tile_VERSION_BUILD "0")
|
||||||
endif()
|
endif()
|
||||||
set(TILE_VERSION
|
|
||||||
"${tile_VERSION_MAJOR}.${tile_VERSION_MINOR}.${tile_VERSION_PATCH}.${tile_VERSION_BUILD}"
|
|
||||||
)
|
|
||||||
project(
|
project(
|
||||||
tile
|
tile
|
||||||
VERSION "${tile_VERSION_MAJOR}.${tile_VERSION_MINOR}.${tile_VERSION_PATCH}"
|
VERSION "${tile_VERSION_MAJOR}.${tile_VERSION_MINOR}.${tile_VERSION_PATCH}"
|
||||||
LANGUAGES C CXX)
|
LANGUAGES C CXX)
|
||||||
|
|
||||||
|
set(TILE_VERSION "${PROJECT_VERSION}.${tile_VERSION_BUILD}")
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 11)
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
|
|
||||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||||
|
|
||||||
# add static libgcc and libstdc++ for static linking set(CMAKE_C_FLAGS
|
|
||||||
# "${CMAKE_C_FLAGS} -static-libgcc -static-libstdc++") set(CMAKE_CXX_FLAGS
|
|
||||||
# "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++")
|
|
||||||
|
|
||||||
option(TILE_BUILD_TESTS "Build tests" OFF)
|
option(TILE_BUILD_TESTS "Build tests" OFF)
|
||||||
option(TILE_BUILD_BENCHMARKS "Build tests" OFF)
|
option(TILE_BUILD_BENCHMARKS "Build tests" OFF)
|
||||||
option(TILE_WITH_OPENSSL "Build wih openssl" OFF)
|
option(TILE_WITH_OPENSSL "Build wih openssl" OFF)
|
||||||
@ -283,7 +279,7 @@ if(TILE_BUILD_TESTS)
|
|||||||
|
|
||||||
tile_add_test(${TEST_NAME} ${SRC_FILE})
|
tile_add_test(${TEST_NAME} ${SRC_FILE})
|
||||||
endforeach()
|
endforeach()
|
||||||
endfunction(add_test_group)
|
endfunction()
|
||||||
|
|
||||||
add_test_group(${CMAKE_CURRENT_SOURCE_DIR}/tile/system system)
|
add_test_group(${CMAKE_CURRENT_SOURCE_DIR}/tile/system system)
|
||||||
add_test_group(${CMAKE_CURRENT_SOURCE_DIR}/tile/base base)
|
add_test_group(${CMAKE_CURRENT_SOURCE_DIR}/tile/base base)
|
||||||
@ -292,7 +288,7 @@ if(TILE_BUILD_TESTS)
|
|||||||
add_test_group(${CMAKE_CURRENT_SOURCE_DIR}/tile/net net)
|
add_test_group(${CMAKE_CURRENT_SOURCE_DIR}/tile/net net)
|
||||||
add_test_group(${CMAKE_CURRENT_SOURCE_DIR}/tile/rpc rpc)
|
add_test_group(${CMAKE_CURRENT_SOURCE_DIR}/tile/rpc rpc)
|
||||||
tile_add_custom_test("custom_http_client_test" "tests/http_client_test.cc")
|
tile_add_custom_test("custom_http_client_test" "tests/http_client_test.cc")
|
||||||
endif(TILE_BUILD_TESTS)
|
endif()
|
||||||
|
|
||||||
if(TILE_BUILD_BENCHMARKS)
|
if(TILE_BUILD_BENCHMARKS)
|
||||||
add_subdirectory("third_party/benchmark")
|
add_subdirectory("third_party/benchmark")
|
||||||
@ -318,4 +314,4 @@ if(TILE_BUILD_BENCHMARKS)
|
|||||||
tile_add_bm(base_internal_time_keeper_benchmark
|
tile_add_bm(base_internal_time_keeper_benchmark
|
||||||
"tile/base/internal/time_keeper_benchmark.cc")
|
"tile/base/internal/time_keeper_benchmark.cc")
|
||||||
tile_add_bm(base_chrono_benchmark "tile/base/chrono_benchmark.cc")
|
tile_add_bm(base_chrono_benchmark "tile/base/chrono_benchmark.cc")
|
||||||
endif(TILE_BUILD_BENCHMARKS)
|
endif()
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
## TILE
|
## TILE
|
||||||
一个`C++11`工具库,集成常见的编码工具
|
一个`C++11`工具库,集成常见的编码工具
|
||||||
|
## TODO
|
||||||
|
- [ ] 支持`EventLoop`的模式的网络库
|
||||||
|
- [ ] 支持UDP
|
||||||
|
- [ ] 支持TCP
|
||||||
|
|
||||||
|
|
||||||
|
@ -225,6 +225,28 @@ operator+(const Slice &lhs, const Slice &rhs)
|
|||||||
return lhs.ToString() + rhs.ToString();
|
return lhs.ToString() + rhs.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static_assert(std::is_constructible<Slice, char>::value, "Can't Build Sliece");
|
||||||
|
static_assert(std::is_constructible<Slice, char &>::value, "Can't Build Sliece");
|
||||||
|
static_assert(std::is_constructible<Slice, const char>::value, "Can't Build Sliece");
|
||||||
|
static_assert(std::is_constructible<Slice, const char &>::value, "Can't Build Sliece");
|
||||||
|
|
||||||
|
static_assert(std::is_constructible<Slice, char[]>::value, "Can't Build Sliece");
|
||||||
|
static_assert(std::is_constructible<Slice, const char[]>::value, "Can't Build Sliece");
|
||||||
|
|
||||||
|
static_assert(std::is_constructible<Slice, char[2]>::value, "Can't Build Sliece");
|
||||||
|
static_assert(std::is_constructible<Slice, const char[2]>::value, "Can't Build Sliece");
|
||||||
|
|
||||||
|
static_assert(std::is_constructible<Slice, char *>::value, "Can't Build Sliece");
|
||||||
|
static_assert(std::is_constructible<Slice, const char *>::value, "Can't Build Sliece");
|
||||||
|
|
||||||
|
static_assert(std::is_constructible<Slice, void *, int>::value, "Can't Build Sliece");
|
||||||
|
static_assert(std::is_constructible<Slice, const void *, int>::value, "Can't Build Sliece");
|
||||||
|
|
||||||
|
static_assert(std::is_constructible<Slice, std::string>::value, "Can't Build Sliece");
|
||||||
|
static_assert(std::is_constructible<Slice, std::string &>::value, "Can't Build Sliece");
|
||||||
|
static_assert(std::is_constructible<Slice, const std::string>::value, "Can't Build Sliece");
|
||||||
|
static_assert(std::is_constructible<Slice, const std::string &>::value, "Can't Build Sliece");
|
||||||
|
|
||||||
}// namespace tile
|
}// namespace tile
|
||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
|
@ -121,24 +121,6 @@ Split(Slice s, Slice delim, bool keep_empty, std::size_t max_split_parts)
|
|||||||
return splited;
|
return splited;
|
||||||
}
|
}
|
||||||
|
|
||||||
Slice
|
|
||||||
TrimLeft(Slice s, Slice cutset)
|
|
||||||
{
|
|
||||||
return TrimLeft(s, [&cutset](char c) { return cutset.find(Slice(&c, 1)) != Slice::npos; });
|
|
||||||
}
|
|
||||||
|
|
||||||
Slice
|
|
||||||
TrimRight(Slice s, Slice cutset)
|
|
||||||
{
|
|
||||||
return TrimRight(s, [&cutset](char c) { return cutset.find(Slice(&c, 1)) != Slice::npos; });
|
|
||||||
}
|
|
||||||
|
|
||||||
Slice
|
|
||||||
Trim(Slice s, Slice cutset)
|
|
||||||
{
|
|
||||||
return Trim(s, [&cutset](char c) { return cutset.find(Slice(&c, 1)) != Slice::npos; });
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void
|
void
|
||||||
JoinImpl(const T &parts, Slice delim, std::string *result)
|
JoinImpl(const T &parts, Slice delim, std::string *result)
|
||||||
|
@ -39,12 +39,8 @@ bool EndsWithIgnoreCase(Slice s, Slice prefix);
|
|||||||
void Replace(Slice from, Slice to, std::string *str, std::size_t count = std::numeric_limits<std::size_t>::max());
|
void Replace(Slice from, Slice to, std::string *str, std::size_t count = std::numeric_limits<std::size_t>::max());
|
||||||
std::string Replace(Slice str, Slice from, Slice to, std::size_t count = std::numeric_limits<std::size_t>::max());
|
std::string Replace(Slice str, Slice from, Slice to, std::size_t count = std::numeric_limits<std::size_t>::max());
|
||||||
|
|
||||||
Slice TrimLeft(Slice s, Slice cutset);
|
|
||||||
Slice TrimRight(Slice s, Slice cutset);
|
|
||||||
Slice Trim(Slice s, Slice cutset);
|
|
||||||
|
|
||||||
template<typename Pred = int(int)>
|
template<typename Pred = int(int)>
|
||||||
Slice
|
enable_if_t<!std::is_constructible<Slice, Pred>::value, Slice>
|
||||||
TrimLeft(Slice s, Pred pred = isspace)
|
TrimLeft(Slice s, Pred pred = isspace)
|
||||||
{
|
{
|
||||||
while (!s.empty() && pred(s[0])) { s.RemovePrefix(1); }
|
while (!s.empty() && pred(s[0])) { s.RemovePrefix(1); }
|
||||||
@ -52,7 +48,7 @@ TrimLeft(Slice s, Pred pred = isspace)
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename Pred = int(int)>
|
template<typename Pred = int(int)>
|
||||||
Slice
|
enable_if_t<!std::is_constructible<Slice, Pred>::value, Slice>
|
||||||
TrimRight(Slice s, Pred pred = isspace)
|
TrimRight(Slice s, Pred pred = isspace)
|
||||||
{
|
{
|
||||||
while (!s.empty() && pred(s[s.size() - 1])) { s.RemoveSuffix(1); }
|
while (!s.empty() && pred(s[s.size() - 1])) { s.RemoveSuffix(1); }
|
||||||
@ -60,12 +56,36 @@ TrimRight(Slice s, Pred pred = isspace)
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename Pred = int(int)>
|
template<typename Pred = int(int)>
|
||||||
Slice
|
enable_if_t<!std::is_constructible<Slice, Pred>::value, Slice>
|
||||||
Trim(Slice s, Pred pred = isspace)
|
Trim(Slice s, Pred pred = isspace)
|
||||||
{
|
{
|
||||||
return TrimRight(TrimLeft(s, pred), pred);
|
return TrimRight(TrimLeft(s, pred), pred);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
enable_if_t<std::is_constructible<Slice, T>::value, Slice>
|
||||||
|
TrimLeft(Slice s, T slice_like)
|
||||||
|
{
|
||||||
|
Slice cutset(slice_like);
|
||||||
|
return TrimLeft(s, [&cutset](char c) { return cutset.find(c) != Slice::npos; });
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
enable_if_t<std::is_constructible<Slice, T>::value, Slice>
|
||||||
|
TrimRight(Slice s, T slice_like)
|
||||||
|
{
|
||||||
|
Slice cutset(slice_like);
|
||||||
|
return TrimRight(s, [&cutset](char c) { return cutset.find(c) != Slice::npos; });
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
enable_if_t<std::is_constructible<Slice, T>::value, Slice>
|
||||||
|
Trim(Slice s, T slice_like)
|
||||||
|
{
|
||||||
|
Slice cutset(slice_like);
|
||||||
|
return Trim(s, [&cutset](char c) { return cutset.find(c) != Slice::npos; });
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<Slice> Split(Slice s,
|
std::vector<Slice> Split(Slice s,
|
||||||
char delim,
|
char delim,
|
||||||
bool keep_empty = false,
|
bool keep_empty = false,
|
||||||
|
@ -184,6 +184,17 @@ TEST(String, Trim)
|
|||||||
ASSERT_EQ("a a", Trim(" a a "));
|
ASSERT_EQ("a a", Trim(" a a "));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(String, TrimByCustset)
|
||||||
|
{
|
||||||
|
static_assert(std::is_constructible<Slice, decltype("d")>::value, "");
|
||||||
|
static_assert(!std::is_constructible<Slice, int(int)>::value, "");
|
||||||
|
ASSERT_EQ(" ", Trim("abcd abcd", "abcd"));
|
||||||
|
ASSERT_EQ("abcd abc", Trim("abcd abcd", "d"));
|
||||||
|
ASSERT_EQ("abcd abcd ", Trim("abcd abcd ", "d"));
|
||||||
|
ASSERT_EQ(" abcd abcd ", Trim(" abcd abcd ", "ad"));
|
||||||
|
ASSERT_EQ("bcd abc", Trim(" abcd abcd ", "ad "));
|
||||||
|
}
|
||||||
|
|
||||||
TEST(String, Split1)
|
TEST(String, Split1)
|
||||||
{
|
{
|
||||||
auto splited = Split("/a/b/c/d/e/f///g", '/');
|
auto splited = Split("/a/b/c/d/e/f///g", '/');
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
#ifndef TILE_RPC_HTTP_HANDLER_H
|
||||||
|
#define TILE_RPC_HTTP_HANDLER_H
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#endif// TILE_RPC_HTTP_HANDLER_H
|
@ -54,14 +54,20 @@ EasyDetectHttp(const void *data, std::size_t length)
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::size_t
|
std::size_t
|
||||||
DetermineHeaderSizeFast(const char *const ptr, std::size_t limit)
|
DetermineHeaderSizeFast(const char *const ptr, std::size_t length)
|
||||||
{
|
{
|
||||||
auto ep = ptr + limit;
|
char *first_end_pos = (char *) memmem(ptr, length, "\r\n\r\n", 4);
|
||||||
auto p = ptr + 1;
|
|
||||||
|
if (first_end_pos == NULL) { return -1; }
|
||||||
|
return first_end_pos + 4 - ptr;
|
||||||
|
|
||||||
|
/*
|
||||||
|
auto end_ptr = ptr + length;
|
||||||
|
auto p = ptr + 1;
|
||||||
while (true) {
|
while (true) {
|
||||||
// First '\n' in '\r\n\r\n'
|
// First '\n' in '\r\n\r\n'
|
||||||
p = static_cast<char *>(memchr(const_cast<char *>(p), '\n', ep - p));
|
p = static_cast<char *>(memchr(const_cast<char *>(p), '\n', end_ptr - p));
|
||||||
if (TILE_UNLIKELY(p == nullptr || ep - p < 3)) { return -1; }
|
if (TILE_UNLIKELY(p == nullptr || end_ptr - p < 3)) { return -1; }
|
||||||
|
|
||||||
if (p[2] == '\n') {
|
if (p[2] == '\n') {
|
||||||
TILE_CHECK_GE(p - 1, ptr);
|
TILE_CHECK_GE(p - 1, ptr);
|
||||||
@ -73,6 +79,7 @@ DetermineHeaderSizeFast(const char *const ptr, std::size_t limit)
|
|||||||
}
|
}
|
||||||
++p;
|
++p;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
}// namespace
|
}// namespace
|
||||||
|
Loading…
x
Reference in New Issue
Block a user