Skip to content

Commit

Permalink
refactor: rename config
Browse files Browse the repository at this point in the history
  • Loading branch information
shuai132 committed Sep 8, 2023
1 parent 7c43948 commit dd4e37c
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 23 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ please refer to the source code: [test](./test)

* TCP

You can enable automatic handling of packet fragmentation using `Config`.
You can enable automatic handling of packet fragmentation using `config`.
Subsequent send and receive will be complete data packets.

By default, this feature is disabled.

```c++
// echo server
asio::io_context context;
tcp_server server(context, PORT/*, Config*/);
tcp_server server(context, PORT/*, config*/);
server.on_session = [](const std::weak_ptr<tcp_session>& ws) {
auto session = ws.lock();
session->on_close = [] {
Expand All @@ -56,7 +56,7 @@ By default, this feature is disabled.
```c++
// echo client
asio::io_context context;
tcp_client client(context/*, Config*/);
tcp_client client(context/*, config*/);
client.on_data = [](const std::string& data) {
};
Expand Down
4 changes: 2 additions & 2 deletions detail/tcp_channel_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class tcp_channel_t : private noncopyable {
using endpoint = typename T::endpoint;

public:
tcp_channel_t(socket& socket, const Config& config) : socket_(socket), config_(config) {
tcp_channel_t(socket& socket, const config& config) : socket_(socket), config_(config) {
ASIO_NET_LOGD("tcp_channel: %p", this);
}

Expand Down Expand Up @@ -203,7 +203,7 @@ class tcp_channel_t : private noncopyable {

private:
socket& socket_;
const Config& config_;
const config& config_;
detail::message read_msg_;
uint32_t send_buffer_now_ = 0;
std::deque<std::string> write_msg_queue_;
Expand Down
4 changes: 2 additions & 2 deletions detail/tcp_client_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class tcp_client_t : public tcp_channel_t<T> {
using endpoint = typename T::endpoint;

public:
explicit tcp_client_t(asio::io_context& io_context, Config config = {})
explicit tcp_client_t(asio::io_context& io_context, config config = {})
: tcp_channel_t<T>(socket_, config_), io_context_(io_context), socket_(io_context), config_(config) {
config_.init();
}
Expand Down Expand Up @@ -135,7 +135,7 @@ class tcp_client_t : public tcp_channel_t<T> {
private:
asio::io_context& io_context_;
socket socket_;
Config config_;
config config_;
std::unique_ptr<asio::steady_timer> reconnect_timer_;
uint32_t reconnect_ms_ = 0;
std::function<void()> open_;
Expand Down
8 changes: 4 additions & 4 deletions detail/tcp_server_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class tcp_session_t : public tcp_channel_t<T>, public std::enable_shared_from_th
using socket = typename T::socket;

public:
explicit tcp_session_t(socket socket, const Config& config) : tcp_channel_t<T>(socket_, config), socket_(std::move(socket)) {
explicit tcp_session_t(socket socket, const config& config) : tcp_channel_t<T>(socket_, config), socket_(std::move(socket)) {
this->init_socket();
}

Expand All @@ -32,7 +32,7 @@ class tcp_server_t {
using endpoint = typename T::endpoint;

public:
tcp_server_t(asio::io_context& io_context, uint16_t port, Config config = {})
tcp_server_t(asio::io_context& io_context, uint16_t port, config config = {})
: io_context_(io_context), acceptor_(io_context, endpoint(T::v4(), port)), config_(config) {
config_.init();
}
Expand All @@ -44,7 +44,7 @@ class tcp_server_t {
* @param endpoint e.g. /tmp/foobar
* @param config
*/
tcp_server_t(asio::io_context& io_context, const std::string& endpoint, Config config = {})
tcp_server_t(asio::io_context& io_context, const std::string& endpoint, config config = {})
: io_context_(io_context), acceptor_(io_context, typename T::endpoint(endpoint)), config_(config) {
config_.init();
}
Expand Down Expand Up @@ -77,7 +77,7 @@ class tcp_server_t {
private:
asio::io_context& io_context_;
typename T::acceptor acceptor_;
Config config_;
config config_;
};

} // namespace detail
Expand Down
2 changes: 1 addition & 1 deletion rpc/detail/rpc_client_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class rpc_client_t : noncopyable {
public:
explicit rpc_client_t(asio::io_context& io_context, uint32_t max_body_size = UINT32_MAX)
: io_context_(io_context),
client_(std::make_shared<detail::tcp_client_t<T>>(io_context, Config{.auto_pack = true, .max_body_size = max_body_size})) {
client_(std::make_shared<detail::tcp_client_t<T>>(io_context, config{.auto_pack = true, .max_body_size = max_body_size})) {
client_->on_open = [this]() {
auto session = std::make_shared<rpc_session_t<T>>(io_context_);
session->init(client_);
Expand Down
4 changes: 2 additions & 2 deletions rpc/detail/rpc_server_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ template <typename T>
class rpc_server_t : noncopyable {
public:
rpc_server_t(asio::io_context& io_context, uint16_t port, uint32_t max_body_size = UINT32_MAX)
: io_context_(io_context), server_(io_context, port, Config{.auto_pack = true, .max_body_size = max_body_size}) {
: io_context_(io_context), server_(io_context, port, config{.auto_pack = true, .max_body_size = max_body_size}) {
static_assert(std::is_same<T, asio::ip::tcp>::value, "");
server_.on_session = [this](std::weak_ptr<detail::tcp_session_t<T>> ws) {
auto session = std::make_shared<rpc_session_t<T>>(io_context_);
Expand All @@ -25,7 +25,7 @@ class rpc_server_t : noncopyable {
}

rpc_server_t(asio::io_context& io_context, const std::string& endpoint, uint32_t max_body_size = UINT32_MAX)
: io_context_(io_context), server_(io_context, endpoint, Config{.auto_pack = true, .max_body_size = max_body_size}) {
: io_context_(io_context), server_(io_context, endpoint, config{.auto_pack = true, .max_body_size = max_body_size}) {
static_assert(std::is_same<T, asio::local::stream_protocol>::value, "");
server_.on_session = [this](std::weak_ptr<detail::tcp_session_t<T>> ws) {
auto session = std::make_shared<rpc_session_t<T>>(io_context_);
Expand Down
4 changes: 2 additions & 2 deletions test/domain_tcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ int main(int argc, char** argv) {
static std::atomic_bool pass_flag_client_close{false};
std::thread([] {
asio::io_context context;
domain_tcp_server server(context, ENDPOINT, Config{.auto_pack = true});
domain_tcp_server server(context, ENDPOINT, config{.auto_pack = true});
server.on_session = [](const std::weak_ptr<domain_tcp_session>& ws) {
LOG("on_session:");
auto session = ws.lock();
Expand All @@ -49,7 +49,7 @@ int main(int argc, char** argv) {

std::thread([] {
asio::io_context context;
domain_tcp_client client(context, Config{.auto_pack = true});
domain_tcp_client client(context, config{.auto_pack = true});
client.on_open = [&] {
LOG("client on_open:");
for (uint32_t i = 0; i < test_count_max; ++i) {
Expand Down
4 changes: 2 additions & 2 deletions test/tcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ int main(int argc, char** argv) {
static std::atomic_bool pass_flag_client_close{false};
std::thread([] {
asio::io_context context;
tcp_server server(context, PORT, Config{.auto_pack = true});
tcp_server server(context, PORT, config{.auto_pack = true});
server.on_session = [](const std::weak_ptr<tcp_session>& ws) {
LOG("on_session:");
auto session = ws.lock();
Expand All @@ -43,7 +43,7 @@ int main(int argc, char** argv) {
}).detach();
std::thread([] {
asio::io_context context;
tcp_client client(context, Config{.auto_pack = true});
tcp_client client(context, config{.auto_pack = true});
client.on_open = [&] {
LOG("client on_open:");
for (uint32_t i = 0; i < test_count_max; ++i) {
Expand Down
4 changes: 2 additions & 2 deletions test/tcp_bigdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ int main(int argc, char** argv) {
// server
std::thread([] {
asio::io_context context;
tcp_server server(context, PORT, Config{.auto_pack = true});
tcp_server server(context, PORT, config{.auto_pack = true});
server.on_session = [&](const std::weak_ptr<tcp_session>& ws) {
LOG("on_session:");
auto session = ws.lock();
Expand All @@ -38,7 +38,7 @@ int main(int argc, char** argv) {
// client
std::thread([] {
asio::io_context context;
tcp_client client(context, Config{.auto_pack = true});
tcp_client client(context, config{.auto_pack = true});
client.on_open = [&] {
LOG("client on_open:");
std::string msg("hello");
Expand Down
4 changes: 2 additions & 2 deletions test/tcp_reconnect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ int main(int argc, char** argv) {
// server
std::thread([] {
asio::io_context context;
tcp_server server(context, PORT, Config{.auto_pack = true});
tcp_server server(context, PORT, config{.auto_pack = true});
server.on_session = [&](const std::weak_ptr<tcp_session>& ws) {
LOG("on_session:");
auto session = ws.lock();
Expand All @@ -35,7 +35,7 @@ int main(int argc, char** argv) {
// client
std::thread([] {
asio::io_context context;
tcp_client client(context, Config{.auto_pack = true});
tcp_client client(context, config{.auto_pack = true});
client.on_open = [&] {
LOG("client on_open:");
std::string msg("hello");
Expand Down
2 changes: 1 addition & 1 deletion type.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace asio_net {

struct Config {
struct config {
bool auto_pack = false;
uint32_t max_body_size = UINT32_MAX;
uint32_t max_send_buffer_size = UINT32_MAX;
Expand Down

0 comments on commit dd4e37c

Please sign in to comment.