提交 85ba42c6 编写于 作者: Y youngwolf

Hide more member functions and variables.

上级 ef634108
......@@ -132,8 +132,7 @@ int main(int argc, const char* argv[])
sp.stop_service();
else if (STATISTIC == str)
{
printf("link #: " ASCS_SF ", valid links: " ASCS_SF ", invalid links: " ASCS_SF "\n", client.size(), client.valid_size(), client.invalid_object_size());
puts("");
printf("link #: " ASCS_SF ", valid links: " ASCS_SF ", invalid links: " ASCS_SF "\n\n", client.size(), client.valid_size(), client.invalid_object_size());
puts(client.get_statistic().to_string().data());
}
else if (STATUS == str)
......
......@@ -85,8 +85,7 @@ int main(int argc, const char* argv[])
sp.stop_service();
else if (STATISTIC == str)
{
printf("link #: " ASCS_SF ", invalid links: " ASCS_SF "\n", echo_server_.size(), echo_server_.invalid_object_size());
puts("");
printf("link #: " ASCS_SF ", invalid links: " ASCS_SF "\n\n", echo_server_.size(), echo_server_.invalid_object_size());
puts(echo_server_.get_statistic().to_string().data());
}
else if (STATUS == str)
......
......@@ -449,8 +449,7 @@ int main(int argc, const char* argv[])
;
else if (STATISTIC == str)
{
printf("link #: " ASCS_SF ", valid links: " ASCS_SF ", invalid links: " ASCS_SF "\n", client.size(), client.valid_size(), client.invalid_object_size());
puts("");
printf("link #: " ASCS_SF ", valid links: " ASCS_SF ", invalid links: " ASCS_SF "\n\n", client.size(), client.valid_size(), client.invalid_object_size());
puts(client.get_statistic().to_string().data());
}
else if (STATUS == str)
......
......@@ -231,8 +231,7 @@ int main(int argc, const char* argv[])
else if (STATISTIC == str)
{
printf("normal server, link #: " ASCS_SF ", invalid links: " ASCS_SF "\n", server_.size(), server_.invalid_object_size());
printf("echo server, link #: " ASCS_SF ", invalid links: " ASCS_SF "\n", echo_server_.size(), echo_server_.invalid_object_size());
puts("");
printf("echo server, link #: " ASCS_SF ", invalid links: " ASCS_SF "\n\n", echo_server_.size(), echo_server_.invalid_object_size());
puts(echo_server_.get_statistic().to_string().data());
}
else if (STATUS == str)
......
......@@ -68,8 +68,7 @@ int main(int argc, const char* argv[])
}
else if (STATISTIC == str)
{
printf("link #: " ASCS_SF ", valid links: " ASCS_SF ", invalid links: " ASCS_SF "\n", client.size(), client.valid_size(), client.invalid_object_size());
puts("");
printf("link #: " ASCS_SF ", valid links: " ASCS_SF ", invalid links: " ASCS_SF "\n\n", client.size(), client.valid_size(), client.invalid_object_size());
puts(client.get_statistic().to_string().data());
}
else if (STATUS == str)
......
......@@ -62,8 +62,7 @@ int main(int argc, const char* argv[])
}
else if (STATISTIC == str)
{
printf("link #: " ASCS_SF ", invalid links: " ASCS_SF "\n", file_server_.size(), file_server_.invalid_object_size());
puts("");
printf("link #: " ASCS_SF ", invalid links: " ASCS_SF "\n\n", file_server_.size(), file_server_.invalid_object_size());
puts(file_server_.get_statistic().to_string().data());
}
else if (STATUS == str)
......
......@@ -25,11 +25,9 @@ file_socket::file_socket(i_server& server_) : server_socket(server_) {}
file_socket::~file_socket() {trans_end();}
void file_socket::reset() {trans_end(); server_socket::reset();}
void file_socket::take_over(std::shared_ptr<server_socket> socket_ptr)
{
auto raw_socket_ptr(std::dynamic_pointer_cast<file_socket>(socket_ptr)); //socket_ptr actually is a pointer of file_socket
printf("restore user data from invalid object (" ASCS_LLF ").\n", raw_socket_ptr->id());
}
//socket_ptr actually is a pointer of file_socket, use std::dynamic_pointer_cast to convert it.
void file_socket::take_over(std::shared_ptr<server_socket> socket_ptr) {printf("restore user data from invalid object (" ASCS_LLF ").\n", socket_ptr->id());}
//this works too, but brings warnings with -Woverloaded-virtual option.
//void file_socket::take_over(std::shared_ptr<file_socket> socket_ptr) {printf("restore user data from invalid object (" ASCS_LLF ").\n", socket_ptr->id());}
......
......@@ -157,8 +157,7 @@ int main(int argc, const char* argv[])
sp.stop_service();
else if (STATISTIC == str)
{
printf("link #: " ASCS_SF ", valid links: " ASCS_SF ", invalid links: " ASCS_SF "\n", client.size(), client.valid_size(), client.invalid_object_size());
puts("");
printf("link #: " ASCS_SF ", valid links: " ASCS_SF ", invalid links: " ASCS_SF "\n\n", client.size(), client.valid_size(), client.invalid_object_size());
puts(client.get_statistic().to_string().data());
}
else if (STATUS == str)
......
......@@ -93,8 +93,7 @@ int main(int argc, const char* argv[])
sp.stop_service();
else if (STATISTIC == str)
{
printf("link #: " ASCS_SF ", invalid links: " ASCS_SF "\n", echo_server_.size(), echo_server_.invalid_object_size());
puts("");
printf("link #: " ASCS_SF ", invalid links: " ASCS_SF "\n\n", echo_server_.size(), echo_server_.invalid_object_size());
puts(echo_server_.get_statistic().to_string().data());
}
else if (STATUS == str)
......
......@@ -473,7 +473,7 @@ bool FUNNAME(const char* const pstr[], const size_t len[], size_t num, bool can_
auto_duration dur(this->stat.pack_time_sum); \
auto msg = this->packer_->pack_msg(pstr, len, num, NATIVE); \
dur.end(); \
return this->SEND_FUNNAME(std::move(msg)); \
return SEND_FUNNAME(std::move(msg)); \
} \
TCP_SEND_MSG_CALL_SWITCH(FUNNAME, bool)
......@@ -507,7 +507,7 @@ sync_call_result FUNNAME(const char* const pstr[], const size_t len[], size_t nu
auto_duration dur(this->stat.pack_time_sum); \
auto msg = this->packer_->pack_msg(pstr, len, num, NATIVE); \
dur.end(); \
return this->SEND_FUNNAME(std::move(msg), duration); \
return SEND_FUNNAME(std::move(msg), duration); \
} \
TCP_SYNC_SEND_MSG_CALL_SWITCH(FUNNAME, sync_call_result)
......@@ -538,7 +538,7 @@ bool FUNNAME(const asio::ip::udp::endpoint& peer_addr, const char* const pstr[],
if (!can_overflow && !this->is_send_buffer_available()) \
return false; \
in_msg_type msg(peer_addr, this->packer_->pack_msg(pstr, len, num, NATIVE)); \
return this->SEND_FUNNAME(std::move(msg)); \
return SEND_FUNNAME(std::move(msg)); \
} \
UDP_SEND_MSG_CALL_SWITCH(FUNNAME, bool)
......@@ -572,7 +572,7 @@ sync_call_result FUNNAME(const asio::ip::udp::endpoint& peer_addr, const char* c
if (!can_overflow && !this->is_send_buffer_available()) \
return sync_call_result::NOT_APPLICABLE; \
in_msg_type msg(peer_addr, this->packer_->pack_msg(pstr, len, num, NATIVE)); \
return this->SEND_FUNNAME(std::move(msg), duration); \
return SEND_FUNNAME(std::move(msg), duration); \
} \
UDP_SYNC_SEND_MSG_CALL_SWITCH(FUNNAME, sync_call_result)
......
......@@ -130,6 +130,7 @@ protected:
//if you want to control the retry times and delay time after reconnecting failed, rewrite prepare_reconnect virtual function.
virtual void after_close() {if (need_reconnect) this->start();}
private:
bool prepare_next_reconnect(const asio::error_code& ec)
{
if (this->started() && !this->stopped())
......@@ -153,10 +154,8 @@ protected:
return false;
}
protected:
bool need_reconnect;
private:
bool need_reconnect;
asio::ip::tcp::endpoint server_addr;
};
......
......@@ -53,7 +53,7 @@ public:
auto_duration dur(stat.pack_time_sum);
auto msg = packer_->pack_heartbeat();
dur.end();
this->do_direct_send_msg(std::move(msg));
do_direct_send_msg(std::move(msg));
}
//reset all, be ensure that there's no any operations performed on this tcp::socket_base when invoke it
......@@ -202,11 +202,18 @@ private:
#endif
virtual void send_msg() {this->dispatch_strand(strand, [this]() {this->do_send_msg(false);});}
using super::close;
using super::handle_msg;
using super::do_direct_send_msg;
#ifdef ASCS_SYNC_SEND
using super::do_direct_sync_send_msg;
#endif
void shutdown()
{
if (!is_broken())
status = link_status::FORCE_SHUTTING_DOWN; //not thread safe because of this assignment
this->close();
close();
}
size_t completion_checker(const asio::error_code& ec, size_t bytes_transferred)
......@@ -252,7 +259,7 @@ private:
#ifdef ASCS_PASSIVE_RECV
reading = false; //clear reading flag before call handle_msg() to make sure that recv_msg() can be called successfully in on_msg_handle()
#endif
if (this->handle_msg()) //if macro ASCS_PASSIVE_RECV been defined, handle_msg will always return false
if (handle_msg()) //if macro ASCS_PASSIVE_RECV been defined, handle_msg will always return false
do_recv_msg(); //receive msg in sequence
}
else
......@@ -262,7 +269,7 @@ private:
#endif
if (ec)
this->on_recv_error(ec);
else if (this->handle_msg()) //if macro ASCS_PASSIVE_RECV been defined, handle_msg will always return false
else if (handle_msg()) //if macro ASCS_PASSIVE_RECV been defined, handle_msg will always return false
do_recv_msg(); //receive msg in sequence
}
}
......
......@@ -110,8 +110,7 @@ public:
if (reconnect)
unified_out::error_out("reconnecting mechanism is not available, please define macro ASCS_REUSE_SSL_STREAM");
this->need_reconnect = false; //ignore reconnect parameter
this->shutdown_ssl(sync);
shutdown_ssl(sync);
}
#endif
......@@ -126,15 +125,20 @@ protected:
#ifndef ASCS_REUSE_SSL_STREAM
virtual int prepare_reconnect(const asio::error_code& ec) {return -1;}
virtual void on_recv_error(const asio::error_code& ec) {this->need_reconnect = false; super::on_recv_error(ec);}
#endif
virtual void on_unpack_error() {unified_out::info_out("can not unpack msg."); this->force_shutdown();}
private:
using super::shutdown_ssl;
void handle_handshake(const asio::error_code& ec)
{
this->on_handshake(ec);
#ifndef ASCS_REUSE_SSL_STREAM
this->close_reconnect();
#endif
if (!ec)
super::connect_handler(ec); //return to tcp::client_socket_base::connect_handler
else
......@@ -173,7 +177,7 @@ public:
#ifndef ASCS_REUSE_SSL_STREAM
void disconnect() {force_shutdown();}
void force_shutdown() {graceful_shutdown();} //must with async mode (the default value), because server_base::uninit will call this function
void graceful_shutdown(bool sync = false) {this->shutdown_ssl(sync);}
void graceful_shutdown(bool sync = false) {shutdown_ssl(sync);}
#endif
protected:
......@@ -186,6 +190,8 @@ protected:
virtual void on_unpack_error() {unified_out::info_out("can not unpack msg."); this->force_shutdown();}
private:
using super::shutdown_ssl;
void handle_handshake(const asio::error_code& ec)
{
this->on_handshake(ec);
......
......@@ -39,7 +39,7 @@ public:
virtual void send_heartbeat()
{
in_msg_type msg(peer_addr, packer_->pack_heartbeat());
this->do_direct_send_msg(std::move(msg));
do_direct_send_msg(std::move(msg));
}
//reset all, be ensure that there's no any operations performed on this socket when invoke it
......@@ -150,10 +150,17 @@ private:
#endif
virtual void send_msg() {this->dispatch_strand(strand, [this]() {this->do_send_msg(false);});}
using super::close;
using super::handle_msg;
using super::do_direct_send_msg;
#ifdef ASCS_SYNC_SEND
using super::do_direct_sync_send_msg;
#endif
void shutdown()
{
this->stop_all_timer();
this->close();
close();
if (this->lowest_layer().is_open())
{
......@@ -196,7 +203,7 @@ private:
reading = false; //clear reading flag before call handle_msg() to make sure that recv_msg() can be called successfully in on_msg_handle()
#endif
ascs::do_something_to_all(msg_can, [this](typename Unpacker::msg_type& msg) {temp_msg_can.emplace_back(this->temp_addr, std::move(msg));});
if (this->handle_msg()) //if macro ASCS_PASSIVE_RECV been defined, handle_msg will always return false
if (handle_msg()) //if macro ASCS_PASSIVE_RECV been defined, handle_msg will always return false
do_recv_msg(); //receive msg in sequence
}
else
......@@ -210,7 +217,7 @@ private:
if (ec)
#endif
on_recv_error(ec);
else if (this->handle_msg()) //if macro ASCS_PASSIVE_RECV been defined, handle_msg will always return false
else if (handle_msg()) //if macro ASCS_PASSIVE_RECV been defined, handle_msg will always return false
do_recv_msg(); //receive msg in sequence
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册