Skip to content

Commit

Permalink
add sofa-pbrpc ver_1_0_0
Browse files Browse the repository at this point in the history
  • Loading branch information
qinzuoyan committed May 21, 2014
1 parent 0716d1e commit 99da1c0
Show file tree
Hide file tree
Showing 154 changed files with 43,265 additions and 16 deletions.
12 changes: 12 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Names should be added to this file like so:
# Name or Organization <email address>

Baidu.com, Inc.

# Initial version authors:
Qin Zuoyan <qinzuoyan01@baidu.com>

# Partial list of contributors:
Jiang Jinpeng <jiangjinpeng@baidu.com>
Yan Shiguang <yanshiguang02@baidu.com>

4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
2014-05-20 version 1.0.0:

* Submit version 1.0.0.

45 changes: 45 additions & 0 deletions INSTALL
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Copyright (c) 2014 Baidu.com, Inc. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Baidu Inc. nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

----------------------------------------------------------------------

Currently, sofa-pbrpc only support x86_64 platform, Linux OS, and GCC.

1. Modify file './depends.mk' to specify depending libs.
The necessary libs is boost, protobuf, snappy and zlib, please
refer to file './README' for details.
2. Run 'make' to build sofa-pbrpc.
The default optimization level is 'O2'.
To change it, modify the 'OPT' variable in file './Makefile'.
3. Run 'make install' to install sofa-pbrpc.
The default install directory is './output'.
To change it, modify the 'PREFIX' variable in file './Makefile'.

For any build problem, please contact <qinzuoyan01@baidu.com> or
<qinzuoyan@gmail.com>.

152 changes: 137 additions & 15 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,27 +1,149 @@
Copyright (c) 2014, BaiduPS
All rights reserved.
Copyright (c) 2014 Baidu.com, Inc. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Baidu Inc. nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

--------------------------------------------------------------------------------

Boost - free peer-reviewed portable C++ source libraries
Boost Software License - Version 1.0 - August 17th, 2003
http://www.boost.org/

Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

--------------------------------------------------------------------------------

Protocol Buffers - Google's data interchange format
Copyright 2008 Google Inc. All rights reserved.
http://code.google.com/p/protobuf/

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
--------------------------------------------------------------------------------

* Neither the name of the {organization} nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
protobuf-zerocopy-compression
Copyright (c) 2013, Johannes Ebke and Peter Waller. All rights reserved.
https://github.com/JohannesEbke/protobuf-zerocopy-compression

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer. Redistributions in binary
form must reproduce the above copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other materials provided with
the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

--------------------------------------------------------------------------------

LZ4 - Fast LZ compression algorithm
Copyright (C) 2011-2012, Yann Collet.
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

You can contact the author at :
- LZ4 homepage : http://fastcompression.blogspot.com/p/lz4.html
- LZ4 source repository : http://code.google.com/p/lz4/

96 changes: 96 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Copyright (c) 2014 Baidu.com, Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. See the AUTHORS file for names of contributors.

#-----------------------------------------------
# Modify prefix to specify the directory to install sofa-pbrpc.
#
PREFIX=./output
#-----------------------------------------------

#-----------------------------------------------
# Uncomment exactly one of the lines labelled (A), (B), and (C) below
# to switch between compilation modes.
#
OPT ?= -O2 # (A) Production use (optimized mode)
# OPT ?= -g2 # (B) Debug mode, generate full line-level debugging symbols
# OPT ?= -O2 -g2 # (C) Profiling mode: opt, but generate debugging symbols
#-----------------------------------------------

#-----------------------------------------------
# !!! Do not change the following lines !!!
#-----------------------------------------------

include depends.mk

INC=src/sofa/pbrpc/pbrpc.h src/sofa/pbrpc/closure_helper.h src/sofa/pbrpc/closure.h \
src/sofa/pbrpc/ext_closure.h src/sofa/pbrpc/common.h src/sofa/pbrpc/rpc_channel.h \
src/sofa/pbrpc/rpc_client.h src/sofa/pbrpc/rpc_controller.h src/sofa/pbrpc/rpc_error_code.h \
src/sofa/pbrpc/rpc_option.pb.h src/sofa/pbrpc/rpc_option.proto src/sofa/pbrpc/rpc_server.h \
src/sofa/pbrpc/string_utils.h src/sofa/pbrpc/mock_test_helper.h src/sofa/pbrpc/atomic.h \
src/sofa/pbrpc/counter.h src/sofa/pbrpc/thread_group.h src/sofa/pbrpc/timeout_manager.h \
src/sofa/pbrpc/locks.h src/sofa/pbrpc/mutex_lock.h src/sofa/pbrpc/spin_lock.h \
src/sofa/pbrpc/fast_lock.h src/sofa/pbrpc/rw_lock.h src/sofa/pbrpc/scoped_locker.h \
src/sofa/pbrpc/condition_variable.h src/sofa/pbrpc/wait_event.h \
src/sofa/pbrpc/builtin_service.proto src/sofa/pbrpc/builtin_service.pb.h

LIB=libsofa-pbrpc.a
LIB_SRC=$(wildcard src/sofa/pbrpc/*.cc)
LIB_OBJ=$(patsubst %.cc,%.o,$(LIB_SRC))

BIN=sofa-pbrpc-client
BIN_SRC=$(wildcard src/sofa/pbrpc/http-agent/*.cc)
BIN_OBJ=$(patsubst %.cc,%.o,$(BIN_SRC))

#-----------------------------------------------

CXX=g++
INCPATH=-Isrc -I$(BOOST_HEADER_DIR) -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 -DHAVE_SNAPPY $(INCPATH)

LIBRARY=$(PROTOBUF_DIR)/lib/libprotobuf.a $(SNAPPY_DIR)/lib/libsnappy.a
LDFLAGS += -L$(ZLIB_DIR)/lib -lpthread -lrt -lz

all: build

.PHONY: check_depends build install clean

check_depends:
@if [ ! -f "$(BOOST_HEADER_DIR)/boost/smart_ptr.hpp" ]; then echo "ERROR: need boost header"; exit 1; fi
@if [ ! -f "$(PROTOBUF_DIR)/include/google/protobuf/message.h" ]; then echo "ERROR: need protobuf header"; exit 1; fi
@if [ ! -f "$(PROTOBUF_DIR)/lib/libprotobuf.a" ]; then echo "ERROR: need protobuf lib"; exit 1; fi
@if [ ! -f "$(SNAPPY_DIR)/include/snappy.h" ]; then echo "ERROR: need snappy header"; exit 1; fi
@if [ ! -f "$(SNAPPY_DIR)/lib/libsnappy.a" ]; then echo "ERROR: need snappy lib"; exit 1; fi

clean:
rm -f $(LIB) $(LIB_OBJ) $(BIN) $(BIN_OBJ)

rebuild: clean all

$(LIB): $(LIB_OBJ)
ar crs $@ $(LIB_OBJ)

$(BIN): $(LIB) $(BIN_OBJ)
$(CXX) $(LDFLAGS) $(BIN_OBJ) -o $@ $(LIB) $(LIBRARY)

%.o: %.cpp
$(CXX) $(CXXFLAGS) -c$< -o $@

build: check_depends $(LIB) $(BIN)
@echo
@echo 'Build succeed, run "make install" to install sofa-pbrpc.'

install: $(LIB) $(BIN)
mkdir -p $(PREFIX)/include/sofa/pbrpc
cp -r $(INC) --target-directory $(PREFIX)/include/sofa/pbrpc/
mkdir -p $(PREFIX)/include/sofa/pbrpc/smart_ptr
cp src/sofa/pbrpc/smart_ptr/*.hpp $(PREFIX)/include/sofa/pbrpc/smart_ptr
mkdir -p $(PREFIX)/include/sofa/pbrpc/smart_ptr/detail
cp src/sofa/pbrpc/smart_ptr/detail/*.hpp $(PREFIX)/include/sofa/pbrpc/smart_ptr/detail
mkdir -p $(PREFIX)/lib
cp $(LIB) $(PREFIX)/lib/
mkdir -p $(PREFIX)/bin
cp $(BIN) $(PREFIX)/bin/
@echo
@echo 'Install succeed, target directory is "'$(PREFIX)'".'

55 changes: 55 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
sofa-pbrpc
----------
A light-weight RPC implement of protobuf RPC framework.

Features
--------
* High performace.
* Easy to use. Refer to sample codes in './sample'.
* Support sync call and async call. Refer to './sample/echo'.
* Support three level (service/method/request) timeout. Refer to './sample/timeout_sample'.
* Support transparent compression. Refer to './sample/compress_sample'.
* Support mock test. Refer to './sample/mock_sample'.
* Support network flow control.
* Support auto connecting and reconnecting.
* Support keep alive time of idle connections.
* Support statistics for profiling.

Dependings
----------
The lib depends on boost-1.53.0 (only need header), protobuf-2.4.1, snappy and zlib:
boost - http://www.boost.org/
protobuf - http://code.google.com/p/protobuf/
snappy - http://code.google.com/p/snappy/
zlib - http://zlib.net/

ATTENTION: boost header is only needed when compiling the lib, but no need for user code.

Extrally, './unit-test' and './sample/mock_sample' also depends on gtest:
gtest - http://code.google.com/p/googletest/

Build
-----
1, Modify file './depends.mk' to specify depending libs.
The necessary libs is boost, protobuf, snappy and zlib.
2, Run 'make' to build sofa-pbrpc.
The default optimization level is 'O2'.
To change it, modify the 'OPT' variable in file './Makefile'.
3, Run 'make install' to install sofa-pbrpc.
The default install directory is './output'.
To change it, modify the 'PREFIX' variable in file './Makefile'.

Sample
------
For sample codes, please refer to './sample' and the wiki:
<URL:https://github.com/BaiduPS/sofa-pbrpc/wiki>

Performance
-----------
For performace details, please refer to the wiki:
<URL:https://github.com/BaiduPS/sofa-pbrpc/wiki>

Support
-------
qinzuoyan01@baidu.com (Qin Zuoyan, qinzuoyan@gmail.com)

Loading

0 comments on commit 99da1c0

Please sign in to comment.