Skip to content

Commit

Permalink
fix coredump when destruct global RpcClient object - continued
Browse files Browse the repository at this point in the history
  • Loading branch information
qinzuoyan committed Dec 8, 2015
1 parent a28f60a commit ae619f6
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 16 deletions.
2 changes: 1 addition & 1 deletion sample/compress_sample/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ OPT ?= -O2 # (A) Production use (optimized mode)
include ../../depends.mk

CXX=g++
INCPATH=-I. -I$(SOFA_PBRPC)/include -I$(BOOST_HEADER_DIR) -I$(PROTOBUF_DIR)/include \
INCPATH=-I. -I$(SOFA_PBRPC)/include -I$(PROTOBUF_DIR)/include \
-I$(SNAPPY_DIR)/include -I$(ZLIB_DIR)/include
CXXFLAGS += $(OPT) -pipe -W -Wall -fPIC -D_GNU_SOURCE -D__STDC_LIMIT_MACROS $(INCPATH)

Expand Down
2 changes: 1 addition & 1 deletion sample/echo/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ OPT ?= -O2 # (A) Production use (optimized mode)
include ../../depends.mk

CXX=g++
INCPATH=-I. -I$(SOFA_PBRPC)/include -I$(BOOST_HEADER_DIR) -I$(PROTOBUF_DIR)/include \
INCPATH=-I. -I$(SOFA_PBRPC)/include -I$(PROTOBUF_DIR)/include \
-I$(SNAPPY_DIR)/include -I$(ZLIB_DIR)/include
CXXFLAGS += $(OPT) -pipe -W -Wall -fPIC -D_GNU_SOURCE -D__STDC_LIMIT_MACROS $(INCPATH)

Expand Down
2 changes: 1 addition & 1 deletion sample/mock_sample/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ include ../../depends.mk
include depends.mk

CXX=g++
INCPATH=-I. -I$(SOFA_PBRPC)/include -I$(BOOST_HEADER_DIR) -I$(PROTOBUF_DIR)/include \
INCPATH=-I. -I$(SOFA_PBRPC)/include -I$(PROTOBUF_DIR)/include \
-I$(SNAPPY_DIR)/include -I$(ZLIB_DIR)/include -I$(GTEST_DIR)/include
CXXFLAGS += $(OPT) -pipe -W -Wall -fPIC -D_GNU_SOURCE -D__STDC_LIMIT_MACROS $(INCPATH)

Expand Down
2 changes: 1 addition & 1 deletion sample/mock_sample/depends.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
## $(GTEST_DIR)/src/gtest-all.cc
##
#GTEST_DIR=/home/users/qinzuoyan01/libs/gtest-1.7.0
GTEST_DIR=
GTEST_DIR=../../googletest/googletest
###############################################################

2 changes: 1 addition & 1 deletion sample/multi_server_sample/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ OPT ?= -O2 # (A) Production use (optimized mode)
include ../../depends.mk

CXX=g++
INCPATH=-I. -I$(SOFA_PBRPC)/include -I$(BOOST_HEADER_DIR) -I$(PROTOBUF_DIR)/include \
INCPATH=-I. -I$(SOFA_PBRPC)/include -I$(PROTOBUF_DIR)/include \
-I$(SNAPPY_DIR)/include -I$(ZLIB_DIR)/include
CXXFLAGS += $(OPT) -pipe -W -Wall -fPIC -D_GNU_SOURCE -D__STDC_LIMIT_MACROS $(INCPATH)

Expand Down
2 changes: 1 addition & 1 deletion sample/timeout_sample/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ OPT ?= -O2 # (A) Production use (optimized mode)
include ../../depends.mk

CXX=g++
INCPATH=-I. -I$(SOFA_PBRPC)/include -I$(BOOST_HEADER_DIR) -I$(PROTOBUF_DIR)/include \
INCPATH=-I. -I$(SOFA_PBRPC)/include -I$(PROTOBUF_DIR)/include \
-I$(SNAPPY_DIR)/include -I$(ZLIB_DIR)/include
CXXFLAGS += $(OPT) -pipe -W -Wall -fPIC -D_GNU_SOURCE -D__STDC_LIMIT_MACROS $(INCPATH)

Expand Down
10 changes: 10 additions & 0 deletions src/sofa/pbrpc/common_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ typedef sofa::pbrpc::shared_ptr<IOServicePool> IOServicePoolPtr;
SOFA_PBRPC_DECLARE_RESOURCE_COUNTER(RpcByteStream);
SOFA_PBRPC_DECLARE_RESOURCE_COUNTER(RpcListener);

// Use for affecting global/static variables' construct/destruct order.
inline void touch_boost_error_category()
{
(void)boost::system::system_category();
(void)boost::system::generic_category();
(void)boost::asio::error::get_addrinfo_category();
(void)boost::asio::error::get_misc_category();
(void)boost::asio::error::get_netdb_category();
}

} // namespace pbrpc
} // namespace sofa

Expand Down
8 changes: 4 additions & 4 deletions src/sofa/pbrpc/rpc_byte_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class RpcByteStream : public sofa::pbrpc::enable_shared_from_this<RpcByteStream>
, _remote_endpoint(endpoint)
, _ticks(0)
, _last_rw_ticks(0)
, _status(STATUS_INIT)
, _socket(io_service)
, _status(STATUS_INIT)
{
SOFA_PBRPC_INC_RESOURCE_COUNTER(RpcByteStream);
memset(_error_message, 0, sizeof(_error_message));
Expand Down Expand Up @@ -341,16 +341,16 @@ class RpcByteStream : public sofa::pbrpc::enable_shared_from_this<RpcByteStream>
volatile int64 _ticks;
volatile int64 _last_rw_ticks;

private:
tcp::socket _socket;

enum {
STATUS_INIT = 0,
STATUS_CONNECTING = 1,
STATUS_CONNECTED = 2,
STATUS_CLOSED = 3,
};
volatile int _status;

private:
tcp::socket _socket;
}; // class RpcByteStream

} // namespace pbrpc
Expand Down
3 changes: 2 additions & 1 deletion src/sofa/pbrpc/rpc_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ namespace sofa {
namespace pbrpc {

RpcClient::RpcClient(const RpcClientOptions& options)
: _impl(new RpcClientImpl(options))
{
touch_boost_error_category();
_impl.reset(new RpcClientImpl(options));
_impl->Start();
}

Expand Down
4 changes: 2 additions & 2 deletions src/sofa/pbrpc/rpc_message_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class RpcMessageStream : public RpcByteStream
{
SOFA_PBRPC_FUNCTION_TRACE;

if (_status != STATUS_CONNECTED) return;
if (!is_connected()) return;

if (error)
{
Expand Down Expand Up @@ -288,7 +288,7 @@ class RpcMessageStream : public RpcByteStream
{
SOFA_PBRPC_FUNCTION_TRACE;

if (_status != STATUS_CONNECTED) return;
if (!is_connected()) return;

if (error)
{
Expand Down
3 changes: 2 additions & 1 deletion src/sofa/pbrpc/rpc_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ namespace sofa {
namespace pbrpc {

RpcServer::RpcServer(const RpcServerOptions& options, EventHandler* handler)
: _impl(new RpcServerImpl(options, handler))
{
touch_boost_error_category();
_impl.reset(new RpcServerImpl(options, handler));
}

RpcServer::~RpcServer()
Expand Down
4 changes: 2 additions & 2 deletions src/sofa/pbrpc/rpc_server_message_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class RpcServerMessageStream : public RpcByteStream
{
SOFA_PBRPC_FUNCTION_TRACE;

if (_status != STATUS_CONNECTED) return;
if (!is_connected()) return;

if (error)
{
Expand Down Expand Up @@ -286,7 +286,7 @@ class RpcServerMessageStream : public RpcByteStream
{
SOFA_PBRPC_FUNCTION_TRACE;

if (_status != STATUS_CONNECTED) return;
if (!is_connected()) return;

if (error)
{
Expand Down

0 comments on commit ae619f6

Please sign in to comment.