From a76e7ad9761e56de15becada9e3eb208c4f6dca9 Mon Sep 17 00:00:00 2001 From: Sigma711 <1979934715@qq.com> Date: Fri, 14 Jul 2023 02:15:50 -0400 Subject: [PATCH] [src] Modify all wrong spells and solve one FIXME --- .github/pull_request_template.md | 10 ++++++---- .github/workflows/cmake.yml | 2 +- src/acceptor.cc | 2 +- src/connecting.cc | 13 +++++++------ src/connecting.h | 9 +++++---- src/connector.cc | 2 +- src/event_manager.h | 2 +- src/reactor_manager.cc | 5 ++--- src/timer.h | 2 +- 9 files changed, 25 insertions(+), 22 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index a8da4d37..3de90703 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,16 +1,18 @@ -### Purpose - +# + +## Purpose + - Purpose. -### Changes +## Changes - No changes. -### Review Instructions +## Review Instructions - No instructions. diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index dec23aff..949f304c 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -14,7 +14,7 @@ env: jobs: build: - # The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac. + # The CMake configure and build commands are platform-agnostic and should work equally well on Windows or Mac. # You can convert this to a matrix build if you need cross-platform coverage. # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix runs-on: ubuntu-latest diff --git a/src/acceptor.cc b/src/acceptor.cc index a5350d14..aa403e3f 100644 --- a/src/acceptor.cc +++ b/src/acceptor.cc @@ -55,7 +55,7 @@ Acceptor::Acceptor(Poller* poller, const NetAddress& listen_address, accept_socketer_.BindAddress(listen_address); accept_eventer_.RegisterReadCallback([this](const TimePoint& time_point) { this->DoReading(); - }); // Register the accepting action as an reading event handler + }); // Register the accepting action as a reading event handler } Acceptor::~Acceptor() { LOG_DEBUG("Acceptor with fd(%d) is closing.", accept_socketer_.Fd()); diff --git a/src/connecting.cc b/src/connecting.cc index 61abc955..b5d582a1 100644 --- a/src/connecting.cc +++ b/src/connecting.cc @@ -204,14 +204,15 @@ void Connecting::ForceClose() { DoClosing(); } } + // FIXME: Make it be effective in the condition that the connection has been // destroyed. -// void Connecting::ForceCloseAfter(int64_t delay_microseconds) { -// if (kDisconnected != state_) { -// event_manager_->RunAfter(delay_microseconds, -// std::bind(&Connecting::ForceClose, this)); -// } -// } +void Connecting::ForceCloseAfter(int64_t delay_microseconds) { + if (kDisconnected != state_) { + event_manager_->RunAfter(delay_microseconds, + [this]() { this->ForceClose(); }); + } +} std::string Connecting::GetConnectionStateInfo(ConnectionState state) { switch (state) { diff --git a/src/connecting.h b/src/connecting.h index 944bf07e..49135a61 100644 --- a/src/connecting.h +++ b/src/connecting.h @@ -126,13 +126,13 @@ class Connecting : NonCopyableMovable { // Be called when this connection establishing void OnEstablishing(); - // Send the message (asynchronously at most of time) + // Send the message (asynchronously at most time) void Send(const void* message, size_t msg_len); - // Send the message (asynchronously at most of time) + // Send the message (asynchronously at most time) void Send(const std::string& message); - // Send the message (asynchronously at most of time) + // Send the message (asynchronously at most time) void Send(IoBuffer* io_buffer); // Shut down the writing end (close half == stop writing indeed) @@ -145,7 +145,8 @@ class Connecting : NonCopyableMovable { // Close this TCP connection directly (at the end of this loop) void ForceClose(); - // FIXME: void ForceCloseAfter(int64_t delay_microseconds); + + void ForceCloseAfter(int64_t delay_microseconds); private: enum ConnectionState { diff --git a/src/connector.cc b/src/connector.cc index b191a35b..be906427 100644 --- a/src/connector.cc +++ b/src/connector.cc @@ -128,7 +128,7 @@ void Connector::Connect() { ::close(sock_fd); break; default: - LOG_ERROR("Connector fd(%d) is closing because of an unkown error(%d)!!!", + LOG_ERROR("Connector fd(%d) is closing because of an unknow error(%d)!!!", sock_fd, saved_errno); ::close(sock_fd); break; diff --git a/src/event_manager.h b/src/event_manager.h index 7f307d41..d772676c 100644 --- a/src/event_manager.h +++ b/src/event_manager.h @@ -60,7 +60,7 @@ class EventManager : NonCopyableMovable { Poller* GetPoller() { return &poller_; } - // For the Balancer to pick a EventManager with lowest load + // For the Balancer to pick a EventManager with the lowest load uint32_t GetEventerAmount() const { LockGuard lock_guard(connection_map_mutex_lock_); return connection_map_.size(); diff --git a/src/reactor_manager.cc b/src/reactor_manager.cc index 288ed73e..aa66c269 100644 --- a/src/reactor_manager.cc +++ b/src/reactor_manager.cc @@ -104,9 +104,8 @@ void ServerReactorManager::AcceptNewConnectionCallback( int socket_fd, const NetAddress& peer_address) { auto new_connection = balancer_->PickOneEventManager()->InsertNewConnection( socket_fd, GetLocalAddress(socket_fd), - peer_address); // Pick a "Reactor" with lowest load and - // insert the new - // connection created just now into it + peer_address); // Pick a "Reactor" with the lowest load and insert the + // new connection created just now into it new_connection->RegisterOnConnectionCallback(ConnectionCallback_); new_connection->RegisterOnMessageCallback(MessageCallback_); new_connection->RegisterWriteCallback(WriteCompleteCallback_); diff --git a/src/timer.h b/src/timer.h index 6654a77a..beb60f31 100644 --- a/src/timer.h +++ b/src/timer.h @@ -38,7 +38,7 @@ class Timer : NonCopyableMovable { // Register a time task void AddTimeTask(const TimePoint& time_point, TimeCallback TimeTask); - // Get minium time duration for next epoll waiting + // Get minimum time duration for next epoll waiting int GetMinTimeDuration() const; // Get a set of expired time tasks