Skip to content

Commit

Permalink
fix coredump when destruct global RpcClient object
Browse files Browse the repository at this point in the history
  • Loading branch information
qinzuoyan committed Dec 7, 2015
1 parent 9e16b11 commit 6ea94ab
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ unit-test/test_ext_closure
unit-test/test_thread_group
unit-test/test_timeout_manager
unit-test/test_tran_buf_pool
unit-test/test_io_service_pool
*.a
sofa-pbrpc-client
depends.mk
Expand Down
6 changes: 3 additions & 3 deletions depends.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
## $(BOOST_HEADER_DIR)/boost/smart_ptr.hpp
##
#BOOST_HEADER_DIR=/home/users/qinzuoyan01/libs/boost_1_53_0
BOOST_HEADER_DIR=
BOOST_HEADER_DIR=/usr
################################################################

################################################################
Expand All @@ -28,7 +28,7 @@ BOOST_HEADER_DIR=
## $(PROTOBUF_DIR)/lib/libprotobuf.a
##
#PROTOBUF_DIR=/home/users/qinzuoyan01/libs/protobuf-2.4.1/output
PROTOBUF_DIR=/usr/local/
PROTOBUF_DIR=/usr/local
################################################################

################################################################
Expand All @@ -39,7 +39,7 @@ PROTOBUF_DIR=/usr/local/
## $(SNAPPY_DIR)/lib/libsnappy.a
##
#SNAPPY_DIR=/home/users/qinzuoyan01/libs/snappy-1.1.1/output
SNAPPY_DIR=
SNAPPY_DIR=/usr
################################################################

################################################################
Expand Down
9 changes: 4 additions & 5 deletions sample/echo/client_sync.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@
#include <sofa/pbrpc/pbrpc.h>
#include "echo_service.pb.h"

// Using global RpcClient object can help share resources such as threads and buffers.
sofa::pbrpc::RpcClient g_rpc_client;

int main()
{
SOFA_PBRPC_SET_LOG_LEVEL(NOTICE);

// Define an rpc client.
sofa::pbrpc::RpcClientOptions client_options;
sofa::pbrpc::RpcClient rpc_client(client_options);

// Define an rpc channel.
sofa::pbrpc::RpcChannelOptions channel_options;
sofa::pbrpc::RpcChannel rpc_channel(&rpc_client, "127.0.0.1:12321", channel_options);
sofa::pbrpc::RpcChannel rpc_channel(&g_rpc_client, "127.0.0.1:12321", channel_options);

// Prepare parameters.
sofa::pbrpc::RpcController* cntl = new sofa::pbrpc::RpcController();
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)
, _socket(io_service)
, _status(STATUS_INIT)
, _socket(io_service)
{
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
4 changes: 4 additions & 0 deletions src/sofa/pbrpc/rpc_message_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ class RpcMessageStream : public RpcByteStream
{
SOFA_PBRPC_FUNCTION_TRACE;

if (_status != STATUS_CONNECTED) return;

if (error)
{
if (error != boost::asio::error::eof)
Expand Down Expand Up @@ -286,6 +288,8 @@ class RpcMessageStream : public RpcByteStream
{
SOFA_PBRPC_FUNCTION_TRACE;

if (_status != STATUS_CONNECTED) return;

if (error)
{
#if defined( LOG )
Expand Down
4 changes: 4 additions & 0 deletions src/sofa/pbrpc/rpc_server_message_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ class RpcServerMessageStream : public RpcByteStream
{
SOFA_PBRPC_FUNCTION_TRACE;

if (_status != STATUS_CONNECTED) return;

if (error)
{
if (error != boost::asio::error::eof)
Expand Down Expand Up @@ -284,6 +286,8 @@ class RpcServerMessageStream : public RpcByteStream
{
SOFA_PBRPC_FUNCTION_TRACE;

if (_status != STATUS_CONNECTED) return;

if (error)
{
#if defined( LOG )
Expand Down

0 comments on commit 6ea94ab

Please sign in to comment.