提交 e00bbb93 编写于 作者: Y youngwolf

Fix the closure of UNIX domain UDP socket.

上级 458b86e3
......@@ -2,9 +2,6 @@
#include <iostream>
//configuration
#define ASCS_DELAY_CLOSE 1 //this demo not used object pool and doesn't need life cycle management,
//so, define this to avoid hooks for async call (and slightly improve efficiency),
//any value which is bigger than zero is okay.
//configuration
#include <ascs/ext/udp.h>
......
......@@ -385,7 +385,7 @@ protected:
#endif
//subclass notify shutdown event
bool close()
bool close(bool use_close = false) //if not use_close, shutdown (both direction) will be used
{
scope_atomic_lock lock(start_atomic);
while (!lock.locked())
......@@ -405,7 +405,7 @@ protected:
if (lowest_layer().is_open())
{
asio::error_code ec;
lowest_layer().shutdown(Family::socket::shutdown_both, ec);
use_close ? lowest_layer().close(ec) : lowest_layer().shutdown(Family::socket::shutdown_both, ec);
stat.break_time = time(nullptr);
}
......
......@@ -90,7 +90,7 @@ public:
const typename Family::endpoint& get_peer_addr() const {return peer_addr;}
void disconnect() {force_shutdown();}
void force_shutdown() {show_info("link:", "been shutting down."); this->dispatch_strand(rw_strand, [this]() {this->shutdown();});}
virtual void force_shutdown() {shutdown();}
void graceful_shutdown() {force_shutdown();}
std::string endpoint_to_string(const asio::ip::udp::endpoint& ep) const {return ep.address().to_string() + ':' + std::to_string(ep.port());}
......@@ -166,6 +166,8 @@ protected:
Matrix* get_matrix() {return matrix;}
const Matrix* get_matrix() const {return matrix;}
void shutdown(bool use_close = false) {show_info("link:", "been shutting down."); this->dispatch_strand(rw_strand, ASCS_COPY_ALL_AND_THIS() {this->close(use_close);});}
virtual bool bind(const typename Family::endpoint& local_addr) {return true;}
virtual bool do_start()
......@@ -224,8 +226,6 @@ private:
using super::do_direct_sync_send_msg;
#endif
void shutdown() {close();}
virtual void do_recv_msg()
{
#ifdef ASCS_PASSIVE_RECV
......@@ -405,6 +405,8 @@ public:
unix_socket_base(asio::io_context& io_context_) : super(io_context_) {}
unix_socket_base(Matrix& matrix_) : super(matrix_) {}
virtual void force_shutdown() {this->shutdown(true);}
protected:
virtual bool bind(const asio::local::datagram_protocol::endpoint& local_addr)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册