├── README.md ├── bin ├── Makefile ├── ctrl.config ├── default.conf ├── main.cpp ├── pyctrl │ ├── main.py │ ├── msg │ │ ├── __init__.py │ │ └── ffengine │ │ │ ├── __init__.py │ │ │ ├── constants.py │ │ │ └── ttypes.py │ └── msg_def │ │ ├── __init__.py │ │ ├── constants.py │ │ └── ttypes.py ├── pylib │ ├── event_bus.py │ ├── ffext.py │ ├── google │ │ ├── __init__.py │ │ └── protobuf │ │ │ ├── __init__.py │ │ │ ├── compiler │ │ │ ├── __init__.py │ │ │ └── plugin_pb2.py │ │ │ ├── descriptor.py │ │ │ ├── descriptor_database.py │ │ │ ├── descriptor_pb2.py │ │ │ ├── descriptor_pool.py │ │ │ ├── internal │ │ │ ├── __init__.py │ │ │ ├── api_implementation.py │ │ │ ├── containers.py │ │ │ ├── cpp_message.py │ │ │ ├── decoder.py │ │ │ ├── encoder.py │ │ │ ├── enum_type_wrapper.py │ │ │ ├── message_listener.py │ │ │ ├── python_message.py │ │ │ ├── type_checkers.py │ │ │ └── wire_format.py │ │ │ ├── message.py │ │ │ ├── message_factory.py │ │ │ ├── reflection.py │ │ │ ├── service.py │ │ │ ├── service_reflection.py │ │ │ └── text_format.py │ ├── id_generator.py │ ├── pkg_resources.py │ ├── protobuf_example │ │ ├── msg.proto │ │ ├── msg_pb2.py │ │ └── protobuf_example.py │ ├── thrift │ │ ├── TSCons.py │ │ ├── TSerialization.py │ │ ├── Thrift.py │ │ ├── __init__.py │ │ ├── protocol │ │ │ ├── TBase.py │ │ │ ├── TBinaryProtocol.py │ │ │ ├── TCompactProtocol.py │ │ │ ├── TJSONProtocol.py │ │ │ ├── TProtocol.py │ │ │ ├── __init__.py │ │ │ └── fastbinary.c │ │ ├── server │ │ │ ├── THttpServer.py │ │ │ ├── TNonblockingServer.py │ │ │ ├── TProcessPoolServer.py │ │ │ ├── TServer.py │ │ │ └── __init__.py │ │ └── transport │ │ │ ├── THttpClient.py │ │ │ ├── TSSLSocket.py │ │ │ ├── TSocket.py │ │ │ ├── TTransport.py │ │ │ ├── TTwisted.py │ │ │ ├── TZlibTransport.py │ │ │ └── __init__.py │ ├── thrift_example │ │ ├── __init__.py │ │ ├── ff │ │ │ ├── __init__.py │ │ │ ├── constants.py │ │ │ └── ttypes.py │ │ └── thrift_example.py │ └── wrods_filter.py └── pyproject │ ├── echo_msg_def │ ├── __init__.py │ ├── constants.py │ └── ttypes.py │ ├── handler │ ├── __init__.py │ └── player_handler.py │ ├── main-bk.py │ ├── main.py │ ├── model │ ├── __init__.py │ ├── db_service.py │ └── player_model.py │ ├── msg_def │ ├── __init__.py │ ├── constants.py │ └── ttypes.py │ └── user_data │ ├── __init__.py │ ├── constants.py │ └── ttypes.py ├── example ├── client │ ├── Makefile │ └── main.cpp ├── game │ ├── Makefile │ ├── ctrl.config │ ├── default.conf │ ├── main.cpp │ ├── main.lua │ ├── pyctrl │ │ ├── main.py │ │ ├── msg │ │ │ ├── __init__.py │ │ │ └── ffengine │ │ │ │ ├── __init__.py │ │ │ │ ├── constants.py │ │ │ │ └── ttypes.py │ │ └── msg_def │ │ │ ├── __init__.py │ │ │ ├── constants.py │ │ │ └── ttypes.py │ ├── pylib │ │ ├── event_bus.py │ │ ├── ffext.py │ │ ├── google │ │ │ ├── __init__.py │ │ │ └── protobuf │ │ │ │ ├── __init__.py │ │ │ │ ├── compiler │ │ │ │ ├── __init__.py │ │ │ │ └── plugin_pb2.py │ │ │ │ ├── descriptor.py │ │ │ │ ├── descriptor_database.py │ │ │ │ ├── descriptor_pb2.py │ │ │ │ ├── descriptor_pool.py │ │ │ │ ├── internal │ │ │ │ ├── __init__.py │ │ │ │ ├── api_implementation.py │ │ │ │ ├── containers.py │ │ │ │ ├── cpp_message.py │ │ │ │ ├── decoder.py │ │ │ │ ├── encoder.py │ │ │ │ ├── enum_type_wrapper.py │ │ │ │ ├── message_listener.py │ │ │ │ ├── python_message.py │ │ │ │ ├── type_checkers.py │ │ │ │ └── wire_format.py │ │ │ │ ├── message.py │ │ │ │ ├── message_factory.py │ │ │ │ ├── reflection.py │ │ │ │ ├── service.py │ │ │ │ ├── service_reflection.py │ │ │ │ └── text_format.py │ │ ├── id_generator.py │ │ ├── pkg_resources.py │ │ ├── protobuf_example │ │ │ ├── msg.proto │ │ │ ├── msg_pb2.py │ │ │ └── protobuf_example.py │ │ ├── thrift │ │ │ ├── TSCons.py │ │ │ ├── TSerialization.py │ │ │ ├── Thrift.py │ │ │ ├── __init__.py │ │ │ ├── protocol │ │ │ │ ├── TBase.py │ │ │ │ ├── TBinaryProtocol.py │ │ │ │ ├── TCompactProtocol.py │ │ │ │ ├── TJSONProtocol.py │ │ │ │ ├── TProtocol.py │ │ │ │ ├── __init__.py │ │ │ │ └── fastbinary.c │ │ │ ├── server │ │ │ │ ├── THttpServer.py │ │ │ │ ├── TNonblockingServer.py │ │ │ │ ├── TProcessPoolServer.py │ │ │ │ ├── TServer.py │ │ │ │ └── __init__.py │ │ │ └── transport │ │ │ │ ├── THttpClient.py │ │ │ │ ├── TSSLSocket.py │ │ │ │ ├── TSocket.py │ │ │ │ ├── TTransport.py │ │ │ │ ├── TTwisted.py │ │ │ │ ├── TZlibTransport.py │ │ │ │ └── __init__.py │ │ ├── thrift_example │ │ │ ├── __init__.py │ │ │ ├── ff │ │ │ │ ├── __init__.py │ │ │ │ ├── constants.py │ │ │ │ └── ttypes.py │ │ │ └── thrift_example.py │ │ └── wrods_filter.py │ └── pyproject │ │ ├── echo_msg_def │ │ ├── __init__.py │ │ ├── constants.py │ │ └── ttypes.py │ │ ├── handler │ │ ├── __init__.py │ │ └── player_handler.py │ │ ├── main-bk.py │ │ ├── main.py │ │ ├── model │ │ ├── __init__.py │ │ ├── db_service.py │ │ └── player_model.py │ │ ├── msg_def │ │ ├── __init__.py │ │ ├── constants.py │ │ └── ttypes.py │ │ └── user_data │ │ ├── __init__.py │ │ ├── constants.py │ │ └── ttypes.py ├── php_sdk │ ├── Thrift │ │ ├── Base │ │ │ └── TBase.php │ │ ├── ClassLoader │ │ │ └── ThriftClassLoader.php │ │ ├── Exception │ │ │ ├── TApplicationException.php │ │ │ ├── TException.php │ │ │ ├── TProtocolException.php │ │ │ └── TTransportException.php │ │ ├── Factory │ │ │ ├── TBinaryProtocolFactory.php │ │ │ ├── TCompactProtocolFactory.php │ │ │ ├── TJSONProtocolFactory.php │ │ │ ├── TProtocolFactory.php │ │ │ ├── TStringFuncFactory.php │ │ │ └── TTransportFactory.php │ │ ├── Protocol │ │ │ ├── JSON │ │ │ │ ├── BaseContext.php │ │ │ │ ├── ListContext.php │ │ │ │ ├── LookaheadReader.php │ │ │ │ └── PairContext.php │ │ │ ├── TBinaryProtocol.php │ │ │ ├── TBinaryProtocolAccelerated.php │ │ │ ├── TCompactProtocol.php │ │ │ ├── TJSONProtocol.php │ │ │ └── TProtocol.php │ │ ├── Serializer │ │ │ └── TBinarySerializer.php │ │ ├── Server │ │ │ ├── TForkingServer.php │ │ │ ├── TServer.php │ │ │ ├── TServerSocket.php │ │ │ ├── TServerTransport.php │ │ │ └── TSimpleServer.php │ │ ├── StringFunc │ │ │ ├── Core.php │ │ │ ├── Mbstring.php │ │ │ └── TStringFunc.php │ │ ├── Transport │ │ │ ├── TBufferedTransport.php │ │ │ ├── TFramedTransport.php │ │ │ ├── THttpClient.php │ │ │ ├── TMemoryBuffer.php │ │ │ ├── TNullTransport.php │ │ │ ├── TPhpStream.php │ │ │ ├── TSocket.php │ │ │ ├── TSocketPool.php │ │ │ └── TTransport.php │ │ ├── Type │ │ │ ├── TMessageType.php │ │ │ └── TType.php │ │ └── ffrpc_msg │ │ │ └── Types.php │ ├── ff │ │ └── Types.php │ └── ffrpc.php ├── python_sdk │ ├── ff │ │ ├── __init__.py │ │ ├── constants.py │ │ ├── gen-py │ │ │ ├── __init__.py │ │ │ └── echo │ │ │ │ ├── __init__.py │ │ │ │ ├── constants.py │ │ │ │ └── ttypes.py │ │ ├── server.py │ │ └── ttypes.py │ ├── ffrpc.py │ ├── gen_py │ │ ├── __init__.py │ │ ├── echo.thrift │ │ ├── echo │ │ │ ├── __init__.py │ │ │ ├── constants.py │ │ │ └── ttypes.py │ │ └── thrift-0.9.1.exe │ └── thrift │ │ ├── TSCons.py │ │ ├── TSerialization.py │ │ ├── Thrift.py │ │ ├── __init__.py │ │ ├── msg_def │ │ ├── __init__.py │ │ ├── constants.py │ │ └── ttypes.py │ │ ├── protocol │ │ ├── TBase.py │ │ ├── TBinaryProtocol.py │ │ ├── TCompactProtocol.py │ │ ├── TJSONProtocol.py │ │ ├── TProtocol.py │ │ ├── __init__.py │ │ └── fastbinary.c │ │ ├── server │ │ ├── THttpServer.py │ │ ├── TNonblockingServer.py │ │ ├── TProcessPoolServer.py │ │ ├── TServer.py │ │ └── __init__.py │ │ └── transport │ │ ├── THttpClient.py │ │ ├── TSSLSocket.py │ │ ├── TSocket.py │ │ ├── TTransport.py │ │ ├── TTwisted.py │ │ ├── TZlibTransport.py │ │ └── __init__.py └── tutorial │ ├── Makefile │ ├── echo.pb.cc │ ├── echo.pb.h │ ├── echo.proto │ ├── echo.thrift │ ├── echo_constants.cpp │ ├── echo_constants.h │ ├── echo_test.h │ ├── echo_types.cpp │ ├── echo_types.h │ ├── gen-php │ └── ff │ │ └── Types.php │ ├── main.cpp │ ├── protobuf.Makefile │ ├── protobuf_test.h │ ├── thrift-0.9.0.exe │ ├── thrift.Makefile │ └── thrift_test.h ├── fflib ├── base │ ├── arg_helper.h │ ├── atomic_op.h │ ├── daemon_tool.h │ ├── ffslot.h │ ├── fftype.h │ ├── lock.cpp │ ├── lock.h │ ├── log.cpp │ ├── log.h │ ├── obj_pool.h │ ├── os_tool.h │ ├── performance_daemon.cpp │ ├── performance_daemon.h │ ├── signal_helper.h │ ├── singleton.h │ ├── smart_ptr.h │ ├── strtool.h │ ├── task_queue_i.h │ ├── task_queue_impl.h │ ├── thread.cpp │ ├── thread.h │ ├── time_tool.h │ └── timer_service.h ├── db │ ├── db_ops.h │ ├── ffcrud.h │ ├── ffdb.cpp │ ├── ffdb.h │ ├── mysql_ops.cpp │ ├── mysql_ops.h │ ├── sqlite3.c │ ├── sqlite3.h │ ├── sqlite3ext.h │ ├── sqlite_ops.cpp │ └── sqlite_ops.h ├── lua │ ├── fflua.h │ ├── fflua_register.h │ └── fflua_type.h ├── net │ ├── acceptor_i.h │ ├── acceptor_impl.cpp │ ├── acceptor_impl.h │ ├── base_heartbeat.h │ ├── codec.cpp │ ├── codec.h │ ├── common_socket_controller.cpp │ ├── common_socket_controller.h │ ├── connector.h │ ├── epoll_i.h │ ├── epoll_impl.cpp │ ├── epoll_impl.h │ ├── gateway_acceptor.cpp │ ├── gateway_acceptor.h │ ├── gateway_socket_controller.cpp │ ├── gateway_socket_controller.h │ ├── http_acceptor.cpp │ ├── http_acceptor.h │ ├── message.h │ ├── msg_handler_i.h │ ├── msg_sender.h │ ├── net_factory.h │ ├── net_stat.cpp │ ├── net_stat.h │ ├── netbase.h │ ├── socket_controller_i.h │ ├── socket_i.h │ ├── socket_impl.cpp │ ├── socket_impl.h │ ├── socket_op.h │ ├── text_socket_controller_impl.cpp │ ├── text_socket_controller_impl.h │ └── udp_socket.h ├── python │ └── ffpython.h ├── rpc │ ├── ffbroker.cpp │ ├── ffbroker.h │ ├── ffrpc.cpp │ ├── ffrpc.h │ ├── ffrpc_ops.h │ └── msg_def │ │ ├── ffrpc_msg_constants.cpp │ │ ├── ffrpc_msg_constants.h │ │ ├── ffrpc_msg_types.cpp │ │ └── ffrpc_msg_types.h ├── server │ ├── db_mgr.cpp │ ├── db_mgr.h │ ├── ffcurl.cpp │ ├── ffcurl.h │ ├── ffgate.cpp │ ├── ffgate.h │ ├── fflua_json_traits.h │ ├── fflua_mod.cpp │ ├── fflua_mod.h │ ├── ffscene.cpp │ ├── ffscene.h │ ├── ffscene_lua.cpp │ ├── ffscene_lua.h │ ├── ffscene_python.cpp │ ├── ffscene_python.h │ └── fftask_processor.h └── xml │ ├── ffxml.cpp │ ├── ffxml.h │ ├── tinystr.cpp │ ├── tinystr.h │ ├── tinyxml.cpp │ ├── tinyxml.h │ ├── tinyxmlerror.cpp │ └── tinyxmlparser.cpp └── lib3party ├── rapidjson ├── document.h ├── filestream.h ├── internal │ ├── pow10.h │ ├── stack.h │ └── strfunc.h ├── prettywriter.h ├── rapidjson.h ├── reader.h ├── stringbuffer.h └── writer.h └── thrift ├── FFThrift.h ├── TApplicationException.h ├── Thrift.h ├── ThriftConfig.h ├── cxxfunctional.h ├── protocol ├── TBinaryProtocol.h ├── TProtocol.h ├── TProtocolException.h └── TVirtualProtocol.h └── transport ├── FFTransport.h ├── TTransport.h ├── TTransportException.h └── TVirtualTransport.h /bin/Makefile: -------------------------------------------------------------------------------- 1 | #交叉编译器路径 2 | CROSS= 3 | CP=/bin/cp 4 | RM=-/bin/rm -rf 5 | LN=/bin/ln -s 6 | #是否开启sqlite的支持,如需要关闭,设置为空字符串 7 | FF_ENABLE_SQLITE_FLAG =-DFF_ENABLE_SQLITE 8 | FF_ENABLE_CURL_FLAG = 9 | #-DFF_ENABLE_CURL 10 | CFLAGS=-g -Wall $(FF_ENABLE_CURL_FLAG) $(FF_ENABLE_SQLITE_FLAG) 11 | LDFLAGS= -O2 -lpthread -ldl -lpython2.6 -lmysqlclient 12 | #-lcurl 13 | #-llua 14 | #链接库名 15 | LIB_NAME= 16 | #链接库版本 17 | LIB_VER=1.0.0 18 | #平台 19 | ARCH= 20 | # 二进制目标 21 | BIN=app_ffengine 22 | 23 | #源文件目录 24 | SrcDir= . ../fflib/base ../fflib/net ../fflib/rpc ../fflib/rpc/msg_def ../fflib/db ../fflib/xml ../fflib/server 25 | #头文件目录 26 | IncDir= ../fflib/ ../lib3party /usr/include/python2.7/ /usr/include/python2.6/ 27 | #连接库目录 28 | LibDir= /usr/local/lib /usr/lib/mysql /usr/lib64/mysql 29 | SRCS=$(foreach dir,$(SrcDir),$(wildcard $(dir)/*.cpp)) 30 | #INCS=$(foreach dir,$(IncDir),$(wildcard $(dir)/*.h)) 31 | INCS=$(foreach dir,$(IncDir),$(addprefix -I,$(dir))) 32 | LINKS=$(foreach dir,$(LibDir),$(addprefix -L,$(dir))) 33 | CFLAGS := $(CFLAGS) $(INCS) 34 | LDFLAGS:= $(LINKS) $(LDFLAGS) 35 | CC=gcc 36 | ARCH=PC 37 | OBJS = $(SRCS:%.cpp=%.o) 38 | .PHONY:all clean 39 | 40 | all:$(BIN) 41 | $(BIN):$(OBJS) 42 | ifeq ($(FF_ENABLE_SQLITE_FLAG),-DFF_ENABLE_SQLITE) 43 | gcc -c ../fflib/db/sqlite3.c -o sqlite3.o 44 | g++ -o $(BIN) $(OBJS) sqlite3.o $(LDFLAGS) 45 | else 46 | g++ -o $(BIN) $(OBJS) $(LDFLAGS) 47 | endif 48 | @echo " OK! Compile $@ " 49 | # @$(LN) $(shell pwd)/$(LIB_NAME).$(LIB_VER) /lib/$(LIB_NAME) 50 | 51 | %.o:%.cpp 52 | @echo "[$(ARCH)] Compile $@..." 53 | @$(CC) $(CFLAGS) -c $< -o $@ 54 | 55 | .PHONY: clean 56 | clean: 57 | @echo "[$(ARCH)] Cleaning files..." 58 | @$(RM) $(OBJS) $(BIN) 59 | @$(RM) sqlite3.o 60 | -------------------------------------------------------------------------------- /bin/ctrl.config: -------------------------------------------------------------------------------- 1 | 2 | #关于broker相关的配置, master_broker如果被设置表示该broker为slave broker, 如果需要跨组通信需要设置bridge_broker 3 | -broker tcp://*:1281 4 | #-master_broker tcp://127.0.0.1:20241 5 | #-bridge_broker tcp://127.0.0.1:30241 6 | 7 | #关于gate相关的配置,-gate 为gate的名称, gate_listen为监听的ip端口 8 | #-gate gate@0 -gate_listen tcp://*:30242 -heartbeat_timeout 600 9 | 10 | #scene 相关的配置 scene 为scene的名称, python_path为python的路径 11 | -scene ffEngine@0 -python_path ./pyctrl 12 | #-lua_scene scene@1 -lua_path ./luaproject 13 | #-lua_mod fflua@1 14 | 15 | #日志相关的配置 级别最大为debug=6,trace=5, info=4, warn=3, error=2, fatal=1 16 | -log_path ./log -log_filename fflog 17 | #-log_class DB_MGR,XX,BROKER,FFSCENE,FFSCENE_PYTHON,FFNET,PY 18 | -log_class DB_MGR,FFSCENE_PYTHON,FFSCENE_LUA,PY,BROKER 19 | -log_print_screen true -log_print_file true 20 | -log_level 5 21 | 22 | 23 | #性能监控单位秒 24 | -perf_timeout 3600 25 | #是否启动为守护进程 26 | #-d 27 | ##数据库相关的配置 账号/密码/数据库 28 | -db mysql://127.0.0.1:3306/root/acegame/pcgame 29 | #如果使用单独的账号系统,使用此db配置 30 | #-user_db mysql://127.0.0.1:3306/root/acegame/pcgame 31 | -------------------------------------------------------------------------------- /bin/default.conf: -------------------------------------------------------------------------------- 1 | 2 | #关于broker相关的配置, master_broker如果被设置表示该broker为slave broker, 如果需要跨组通信需要设置bridge_broker 3 | -broker tcp://127.0.0.1:40241 4 | #-master_broker tcp://127.0.0.1:20241 5 | #-bridge_broker tcp://127.0.0.1:30241 6 | 7 | #关于gate相关的配置,-gate 为gate的名称, gate_listen为监听的ip端口 8 | -gate gate@0 -gate_listen tcp://*:30242 -heartbeat_timeout 600 9 | 10 | #scene 相关的配置 scene 为scene的名称, python_path为python的路径 11 | -scene scene@0 -python_path ./pyproject 12 | #-lua_scene scene@1 -lua_path ./luaproject 13 | #-lua_mod fflua@1 14 | 15 | #日志相关的配置 级别最大为debug=6,trace=5, info=4, warn=3, error=2, fatal=1 16 | -log_path ./log -log_filename fflog 17 | #-log_class DB_MGR,XX,BROKER,FFSCENE,FFSCENE_PYTHON,FFNET,PY 18 | -log_class DB_MGR,FFSCENE_PYTHON,FFGATE,FFSCENE,FFSCENE_LUA,PY 19 | -log_print_screen true -log_print_file true 20 | -log_level 5 21 | 22 | 23 | #性能监控单位秒 24 | -perf_timeout 3600 25 | #是否启动为守护进程 26 | #-d 27 | ##数据库相关的配置 账号/密码/数据库 28 | -db sqlite://./ff_demo.db 29 | -group_name demo 30 | -------------------------------------------------------------------------------- /bin/pyctrl/msg/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/bin/pyctrl/msg/__init__.py -------------------------------------------------------------------------------- /bin/pyctrl/msg/ffengine/__init__.py: -------------------------------------------------------------------------------- 1 | __all__ = ['ttypes', 'constants'] 2 | -------------------------------------------------------------------------------- /bin/pyctrl/msg/ffengine/constants.py: -------------------------------------------------------------------------------- 1 | # 2 | # Autogenerated by Thrift Compiler (0.9.0) 3 | # 4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | # 6 | # options string: py 7 | # 8 | 9 | from thrift.Thrift import TType, TMessageType, TException, TApplicationException 10 | from ttypes import * 11 | 12 | -------------------------------------------------------------------------------- /bin/pyctrl/msg_def/__init__.py: -------------------------------------------------------------------------------- 1 | __all__ = ['ttypes', 'constants'] 2 | -------------------------------------------------------------------------------- /bin/pyctrl/msg_def/constants.py: -------------------------------------------------------------------------------- 1 | # 2 | # Autogenerated by Thrift Compiler (0.9.0) 3 | # 4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | # 6 | # options string: py 7 | # 8 | 9 | from thrift.Thrift import TType, TMessageType, TException, TApplicationException 10 | from ttypes import * 11 | 12 | -------------------------------------------------------------------------------- /bin/pylib/event_bus.py: -------------------------------------------------------------------------------- 1 | # coding=UTF-8 2 | import traceback 3 | 4 | class event_bus_t(object): 5 | def __init__(self): 6 | #key event class, value is dict of consumer function 7 | self.event_consumer = {} 8 | #processing list, cache event 9 | self.event_cache_list = []#fifo 10 | def default_except_handler(exception_): 11 | traceback.print_exc() 12 | self.exception_handler = default_except_handler 13 | def set_exception_handler(func_): 14 | self.exception_handler = func_ 15 | def get_key_name(self, event_obj_): 16 | return event_obj_.__class__ 17 | def bind_event(self, event_class_, consumer_func): 18 | key = event_class_ 19 | consumer_name = consumer_func.__module__ + '.' + consumer_func.__name__ 20 | dest_dict = self.event_consumer.get(key) 21 | if dest_dict == None: 22 | dest_dict = {} 23 | self.event_consumer[key] = dest_dict 24 | dest_dict[consumer_name] = consumer_func 25 | def post(self, event_): 26 | self.event_cache_list.insert(0, event_) 27 | size = len(self.event_cache_list) 28 | if size > 1: 29 | return True 30 | 31 | while len(self.event_cache_list) > 0: 32 | next_event = self.event_cache_list[len(self.event_cache_list) - 1] 33 | key = self.get_key_name(next_event) 34 | dest_dict = self.event_consumer.get(key) 35 | if None != dest_dict: 36 | for k, func in dest_dict.iteritems(): 37 | try: 38 | func(event_) 39 | except Exception, e: 40 | self.exception_handler(e) 41 | except: 42 | pass 43 | self.event_cache_list.pop() 44 | 45 | def dump(self): 46 | print(self.event_consumer) 47 | 48 | event_bus = event_bus_t() 49 | def instance(): 50 | return event_bus 51 | 52 | def bind_event(event_class_): 53 | bind_list = [] 54 | if event_class_.__class__ == list: 55 | bind_list = event_class_ 56 | else: 57 | bind_list.append(event_class_) 58 | def wraper(func_): 59 | ebus = instance() 60 | for k in bind_list: 61 | ebus.bind_event(k, func_) 62 | return func_ 63 | return wraper 64 | 65 | def post(event_): 66 | instance().post(event_) 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /bin/pylib/google/__init__.py: -------------------------------------------------------------------------------- 1 | __import__('pkg_resources').declare_namespace(__name__) 2 | -------------------------------------------------------------------------------- /bin/pylib/google/protobuf/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/bin/pylib/google/protobuf/__init__.py -------------------------------------------------------------------------------- /bin/pylib/google/protobuf/compiler/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/bin/pylib/google/protobuf/compiler/__init__.py -------------------------------------------------------------------------------- /bin/pylib/google/protobuf/internal/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/bin/pylib/google/protobuf/internal/__init__.py -------------------------------------------------------------------------------- /bin/pylib/id_generator.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/bin/pylib/id_generator.py -------------------------------------------------------------------------------- /bin/pylib/protobuf_example/msg.proto: -------------------------------------------------------------------------------- 1 | 2 | message TestMsg 3 | { 4 | required int32 id=1; 5 | required int32 time=2; 6 | optional string note=3; 7 | } 8 | 9 | -------------------------------------------------------------------------------- /bin/pylib/protobuf_example/msg_pb2.py: -------------------------------------------------------------------------------- 1 | # Generated by the protocol buffer compiler. DO NOT EDIT! 2 | # source: msg.proto 3 | 4 | from google.protobuf import descriptor as _descriptor 5 | from google.protobuf import message as _message 6 | from google.protobuf import reflection as _reflection 7 | from google.protobuf import descriptor_pb2 8 | # @@protoc_insertion_point(imports) 9 | 10 | 11 | 12 | 13 | DESCRIPTOR = _descriptor.FileDescriptor( 14 | name='msg.proto', 15 | package='', 16 | serialized_pb='\n\tmsg.proto\"1\n\x07TestMsg\x12\n\n\x02id\x18\x01 \x02(\x05\x12\x0c\n\x04time\x18\x02 \x02(\x05\x12\x0c\n\x04note\x18\x03 \x01(\t') 17 | 18 | 19 | 20 | 21 | _TESTMSG = _descriptor.Descriptor( 22 | name='TestMsg', 23 | full_name='TestMsg', 24 | filename=None, 25 | file=DESCRIPTOR, 26 | containing_type=None, 27 | fields=[ 28 | _descriptor.FieldDescriptor( 29 | name='id', full_name='TestMsg.id', index=0, 30 | number=1, type=5, cpp_type=1, label=2, 31 | has_default_value=False, default_value=0, 32 | message_type=None, enum_type=None, containing_type=None, 33 | is_extension=False, extension_scope=None, 34 | options=None), 35 | _descriptor.FieldDescriptor( 36 | name='time', full_name='TestMsg.time', index=1, 37 | number=2, type=5, cpp_type=1, label=2, 38 | has_default_value=False, default_value=0, 39 | message_type=None, enum_type=None, containing_type=None, 40 | is_extension=False, extension_scope=None, 41 | options=None), 42 | _descriptor.FieldDescriptor( 43 | name='note', full_name='TestMsg.note', index=2, 44 | number=3, type=9, cpp_type=9, label=1, 45 | has_default_value=False, default_value=unicode("", "utf-8"), 46 | message_type=None, enum_type=None, containing_type=None, 47 | is_extension=False, extension_scope=None, 48 | options=None), 49 | ], 50 | extensions=[ 51 | ], 52 | nested_types=[], 53 | enum_types=[ 54 | ], 55 | options=None, 56 | is_extendable=False, 57 | extension_ranges=[], 58 | serialized_start=13, 59 | serialized_end=62, 60 | ) 61 | 62 | DESCRIPTOR.message_types_by_name['TestMsg'] = _TESTMSG 63 | 64 | class TestMsg(_message.Message): 65 | __metaclass__ = _reflection.GeneratedProtocolMessageType 66 | DESCRIPTOR = _TESTMSG 67 | 68 | # @@protoc_insertion_point(class_scope:TestMsg) 69 | 70 | 71 | # @@protoc_insertion_point(module_scope) 72 | -------------------------------------------------------------------------------- /bin/pylib/protobuf_example/protobuf_example.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/bin/pylib/protobuf_example/protobuf_example.py -------------------------------------------------------------------------------- /bin/pylib/thrift/TSCons.py: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | from os import path 21 | from SCons.Builder import Builder 22 | 23 | 24 | def scons_env(env, add=''): 25 | opath = path.dirname(path.abspath('$TARGET')) 26 | lstr = 'thrift --gen cpp -o ' + opath + ' ' + add + ' $SOURCE' 27 | cppbuild = Builder(action=lstr) 28 | env.Append(BUILDERS={'ThriftCpp': cppbuild}) 29 | 30 | 31 | def gen_cpp(env, dir, file): 32 | scons_env(env) 33 | suffixes = ['_types.h', '_types.cpp'] 34 | targets = map(lambda s: 'gen-cpp/' + file + s, suffixes) 35 | return env.ThriftCpp(targets, dir + file + '.thrift') 36 | -------------------------------------------------------------------------------- /bin/pylib/thrift/TSerialization.py: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | from protocol import TBinaryProtocol 21 | from transport import TTransport 22 | 23 | 24 | def serialize(thrift_object, 25 | protocol_factory=TBinaryProtocol.TBinaryProtocolFactory()): 26 | transport = TTransport.TMemoryBuffer() 27 | protocol = protocol_factory.getProtocol(transport) 28 | thrift_object.write(protocol) 29 | return transport.getvalue() 30 | 31 | 32 | def deserialize(base, 33 | buf, 34 | protocol_factory=TBinaryProtocol.TBinaryProtocolFactory()): 35 | transport = TTransport.TMemoryBuffer(buf) 36 | protocol = protocol_factory.getProtocol(transport) 37 | base.read(protocol) 38 | return base 39 | -------------------------------------------------------------------------------- /bin/pylib/thrift/__init__.py: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | __all__ = ['Thrift', 'TSCons'] 21 | -------------------------------------------------------------------------------- /bin/pylib/thrift/protocol/TBase.py: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | from thrift.Thrift import * 21 | from thrift.protocol import TBinaryProtocol 22 | from thrift.transport import TTransport 23 | 24 | try: 25 | from thrift.protocol import fastbinary 26 | except: 27 | fastbinary = None 28 | 29 | 30 | class TBase(object): 31 | __slots__ = [] 32 | 33 | def __repr__(self): 34 | L = ['%s=%r' % (key, getattr(self, key)) 35 | for key in self.__slots__] 36 | return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) 37 | 38 | def __eq__(self, other): 39 | if not isinstance(other, self.__class__): 40 | return False 41 | for attr in self.__slots__: 42 | my_val = getattr(self, attr) 43 | other_val = getattr(other, attr) 44 | if my_val != other_val: 45 | return False 46 | return True 47 | 48 | def __ne__(self, other): 49 | return not (self == other) 50 | 51 | def read(self, iprot): 52 | if (iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and 53 | isinstance(iprot.trans, TTransport.CReadableTransport) and 54 | self.thrift_spec is not None and 55 | fastbinary is not None): 56 | fastbinary.decode_binary(self, 57 | iprot.trans, 58 | (self.__class__, self.thrift_spec)) 59 | return 60 | iprot.readStruct(self, self.thrift_spec) 61 | 62 | def write(self, oprot): 63 | if (oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and 64 | self.thrift_spec is not None and 65 | fastbinary is not None): 66 | oprot.trans.write( 67 | fastbinary.encode_binary(self, (self.__class__, self.thrift_spec))) 68 | return 69 | oprot.writeStruct(self, self.thrift_spec) 70 | 71 | 72 | class TExceptionBase(Exception): 73 | # old style class so python2.4 can raise exceptions derived from this 74 | # This can't inherit from TBase because of that limitation. 75 | __slots__ = [] 76 | 77 | __repr__ = TBase.__repr__.im_func 78 | __eq__ = TBase.__eq__.im_func 79 | __ne__ = TBase.__ne__.im_func 80 | read = TBase.read.im_func 81 | write = TBase.write.im_func 82 | -------------------------------------------------------------------------------- /bin/pylib/thrift/protocol/__init__.py: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | __all__ = ['TProtocol', 'TBinaryProtocol', 'fastbinary', 'TBase'] 21 | -------------------------------------------------------------------------------- /bin/pylib/thrift/server/__init__.py: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | __all__ = ['TServer', 'TNonblockingServer'] 21 | -------------------------------------------------------------------------------- /bin/pylib/thrift/transport/__init__.py: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | __all__ = ['TTransport', 'TSocket', 'THttpClient', 'TZlibTransport'] 21 | -------------------------------------------------------------------------------- /bin/pylib/thrift_example/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/bin/pylib/thrift_example/__init__.py -------------------------------------------------------------------------------- /bin/pylib/thrift_example/ff/__init__.py: -------------------------------------------------------------------------------- 1 | __all__ = ['ttypes', 'constants'] 2 | -------------------------------------------------------------------------------- /bin/pylib/thrift_example/ff/constants.py: -------------------------------------------------------------------------------- 1 | # 2 | # Autogenerated by Thrift Compiler (0.9.0) 3 | # 4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | # 6 | # options string: py 7 | # 8 | 9 | from thrift.Thrift import TType, TMessageType, TException, TApplicationException 10 | from ttypes import * 11 | 12 | -------------------------------------------------------------------------------- /bin/pylib/thrift_example/ff/ttypes.py: -------------------------------------------------------------------------------- 1 | # 2 | # Autogenerated by Thrift Compiler (0.9.0) 3 | # 4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | # 6 | # options string: py 7 | # 8 | 9 | from thrift.Thrift import TType, TMessageType, TException, TApplicationException 10 | 11 | from thrift.transport import TTransport 12 | from thrift.protocol import TBinaryProtocol, TProtocol 13 | try: 14 | from thrift.protocol import fastbinary 15 | except: 16 | fastbinary = None 17 | 18 | 19 | 20 | class foo_t: 21 | """ 22 | Attributes: 23 | - num 24 | """ 25 | 26 | thrift_spec = ( 27 | None, # 0 28 | (1, TType.I32, 'num', None, 100, ), # 1 29 | ) 30 | 31 | def __init__(self, num=thrift_spec[1][4],): 32 | self.num = num 33 | 34 | def read(self, iprot): 35 | if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None: 36 | fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec)) 37 | return 38 | iprot.readStructBegin() 39 | while True: 40 | (fname, ftype, fid) = iprot.readFieldBegin() 41 | if ftype == TType.STOP: 42 | break 43 | if fid == 1: 44 | if ftype == TType.I32: 45 | self.num = iprot.readI32(); 46 | else: 47 | iprot.skip(ftype) 48 | else: 49 | iprot.skip(ftype) 50 | iprot.readFieldEnd() 51 | iprot.readStructEnd() 52 | 53 | def write(self, oprot): 54 | if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None: 55 | oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec))) 56 | return 57 | oprot.writeStructBegin('foo_t') 58 | if self.num is not None: 59 | oprot.writeFieldBegin('num', TType.I32, 1) 60 | oprot.writeI32(self.num) 61 | oprot.writeFieldEnd() 62 | oprot.writeFieldStop() 63 | oprot.writeStructEnd() 64 | 65 | def validate(self): 66 | return 67 | 68 | 69 | def __repr__(self): 70 | L = ['%s=%r' % (key, value) 71 | for key, value in self.__dict__.iteritems()] 72 | return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) 73 | 74 | def __eq__(self, other): 75 | return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ 76 | 77 | def __ne__(self, other): 78 | return not (self == other) 79 | -------------------------------------------------------------------------------- /bin/pylib/thrift_example/thrift_example.py: -------------------------------------------------------------------------------- 1 | 2 | import thrift.Thrift as Thrift 3 | import thrift.protocol.TBinaryProtocol as TBinaryProtocol 4 | import thrift.protocol.TCompactProtocol as TCompactProtocol 5 | 6 | import thrift.transport.TTransport as TTransport 7 | import gen.ff.ttypes as ttypes 8 | 9 | mb = TTransport.TMemoryBuffer() 10 | #bp = TBinaryProtocol.TBinaryProtocol(mb) 11 | bp = TCompactProtocol.TCompactProtocol(mb) 12 | 13 | foo= ttypes.foo_t() 14 | print(foo) 15 | foo.write(bp) 16 | 17 | 18 | ret = mb.getvalue() 19 | print(len(ret)) 20 | 21 | mb2 = TTransport.TMemoryBuffer(ret) 22 | #bp2 = TBinaryProtocol.TBinaryProtocol(mb2) 23 | bp2 = TCompactProtocol.TCompactProtocol(mb2) 24 | foo2= ttypes.foo_t() 25 | foo2.read(bp2); 26 | 27 | print(foo2) 28 | 29 | 30 | -------------------------------------------------------------------------------- /bin/pylib/wrods_filter.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | dest_code = 'utf-8' 4 | class words_filter_t: 5 | def __init__(self, words_list_): 6 | self.word_index = {}# {one word -> []} 7 | self.all_words = {} 8 | for w in words_list_: 9 | word = unicode(w, dest_code, 'ignore') 10 | word_len = len(word) 11 | if word_len == 0: 12 | continue 13 | dest_array = self.word_index.get(word[0]) 14 | if None == dest_array: 15 | dest_array = [] 16 | #print(__name__, 'filer') 17 | #print(word[0]) 18 | self.word_index[word[0]] = dest_array 19 | if word_len not in dest_array: 20 | dest_array.append(word_len) 21 | dest_array.sort(reverse=True) 22 | self.all_words[word] = True 23 | print(__name__, "load filter words %d"%(len(self.all_words))) 24 | def dump(self, ): 25 | print (self.word_index, self.all_words) 26 | 27 | def filter(self, src_, replace_ = '*'): 28 | ret = unicode('', dest_code, 'ignore') 29 | word_src = unicode(src_, dest_code, 'ignore') 30 | i = 0 31 | while i < len(word_src): 32 | w = word_src[i] 33 | #print(__name__, 'filer') 34 | #print(w) 35 | dest_list = self.word_index.get(w) 36 | if None == dest_list: 37 | i += 1 38 | ret += w 39 | continue 40 | replace_num = 0 41 | for dest_len in dest_list: 42 | check_word = word_src[i:i + dest_len] 43 | #print('check_word', check_word) 44 | if None != self.all_words.get(check_word): 45 | i += dest_len 46 | #print('del', check_word) 47 | replace_num = len(check_word)#len(check_word.encode(dest_code)) 48 | break 49 | if replace_num == 0: 50 | ret += w 51 | i += 1 52 | else: 53 | ret += replace_ * replace_num 54 | return ret.encode(dest_code) 55 | 56 | word_filter = None 57 | def init(src_file_): 58 | global word_filter 59 | wlist = [] 60 | f = open(src_file_) 61 | for line in f.readlines(): 62 | tmp = line.split('\n') 63 | wlist.append(tmp[0]) 64 | word_filter = words_filter_t(wlist) 65 | 66 | def filter(src, replace_ = '*'): 67 | global word_filter 68 | return word_filter.filter(src, replace_) 69 | 70 | 71 | #init('fw.txt') 72 | 73 | -------------------------------------------------------------------------------- /bin/pyproject/echo_msg_def/__init__.py: -------------------------------------------------------------------------------- 1 | __all__ = ['ttypes', 'constants'] 2 | -------------------------------------------------------------------------------- /bin/pyproject/echo_msg_def/constants.py: -------------------------------------------------------------------------------- 1 | # 2 | # Autogenerated by Thrift Compiler (0.9.1) 3 | # 4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | # 6 | # options string: py 7 | # 8 | 9 | from thrift.Thrift import TType, TMessageType, TException, TApplicationException 10 | from ttypes import * 11 | 12 | -------------------------------------------------------------------------------- /bin/pyproject/handler/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/bin/pyproject/handler/__init__.py -------------------------------------------------------------------------------- /bin/pyproject/main-bk.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/bin/pyproject/main-bk.py -------------------------------------------------------------------------------- /bin/pyproject/main.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import ffext 3 | import handler.player_handler 4 | from model import db_service 5 | 6 | import echo_msg_def.ttypes as ttypes 7 | 8 | def init(): 9 | print('init......') 10 | if db_service.init() == False: 11 | return -1 12 | 13 | return 0 14 | 15 | 16 | def cleanup(): 17 | print('cleanup.....') 18 | return 0 19 | 20 | 21 | @ffext.ff_reg_scene_interfacee(ttypes.echo_thrift_in_t, ttypes.echo_thrift_out_t) 22 | def test_echo(req): 23 | ret_msg = ttypes.echo_thrift_out_t() 24 | ret_msg.data = req.msg.data 25 | req.response(ret_msg) 26 | print('test_echo', req.msg) 27 | return 28 | -------------------------------------------------------------------------------- /bin/pyproject/model/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/bin/pyproject/model/__init__.py -------------------------------------------------------------------------------- /bin/pyproject/model/db_service.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import ffext 4 | import id_generator 5 | 6 | g_async_db = None 7 | def get_async_db(): 8 | global g_async_db 9 | return g_async_db 10 | 11 | def init(): 12 | global g_async_db 13 | #g_sync_db = ffext.ffdb_create('mysql://localhost:3306/root/acegame/pcgame') 14 | db_config = ffext.get_config('-db') 15 | print('db_config=%s'%(db_config)) 16 | g_async_db = ffext.ffdb_create(db_config) 17 | if None == g_async_db: 18 | return False 19 | sql = '''create table IF NOT EXISTS player_info 20 | ( 21 | UID bigint not null, 22 | NAME varchar(255) not null, 23 | X int not null, 24 | Y int not null, 25 | primary key(UID) 26 | )''' 27 | g_async_db.query(sql) 28 | return True 29 | 30 | def load_by_name(name_, callback): 31 | sql = "select * from player_info where NAME='%s' limit 1"%(name_) 32 | def cb(ret): 33 | retData = {} 34 | if ret.flag == False or len(ret.result) == 0: 35 | callback(retData) 36 | return 37 | for i in range(0, len(ret.column)): 38 | retData[ret.column[i]] = ret.result[0][i] 39 | callback(retData) 40 | return 41 | get_async_db().query(sql, cb) 42 | return 43 | 44 | def insert_player(field_data): 45 | sql = '' 46 | values = '' 47 | for k, v in field_data.iteritems(): 48 | if sql == '': 49 | sql = "insert into player_info ({0}".format(k) 50 | values = ") values ('{0}'".format(v) 51 | else: 52 | sql += ", {0}".format(k) 53 | values += ", '{0}'".format(v) 54 | sql += values + ')' 55 | print(sql) 56 | g_async_db.query(sql) 57 | return 58 | 59 | def update_player(uid, field_data): 60 | sql = '' 61 | for k, v in field_data.iteritems(): 62 | if sql == '': 63 | sql = "update player_info set {0} = '{1}'".format(k, v) 64 | else: 65 | sql += ", {0} = '{1}'".format(k, v) 66 | sql += " where uid = '{0}'".format(uid) 67 | print(sql) 68 | g_async_db.query(sql) 69 | return 70 | 71 | -------------------------------------------------------------------------------- /bin/pyproject/model/player_model.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | class player_t: 4 | def __init__(self): 5 | self.id = 0 6 | self.name = '' 7 | self.x = 0 8 | self.y = 0 9 | self.last_move_tm = time.time() 10 | 11 | -------------------------------------------------------------------------------- /bin/pyproject/msg_def/__init__.py: -------------------------------------------------------------------------------- 1 | __all__ = ['ttypes', 'constants'] 2 | -------------------------------------------------------------------------------- /bin/pyproject/msg_def/constants.py: -------------------------------------------------------------------------------- 1 | # 2 | # Autogenerated by Thrift Compiler (0.9.0) 3 | # 4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | # 6 | # options string: py 7 | # 8 | 9 | from thrift.Thrift import TType, TMessageType, TException, TApplicationException 10 | from ttypes import * 11 | 12 | -------------------------------------------------------------------------------- /bin/pyproject/user_data/__init__.py: -------------------------------------------------------------------------------- 1 | __all__ = ['ttypes', 'constants'] 2 | -------------------------------------------------------------------------------- /bin/pyproject/user_data/constants.py: -------------------------------------------------------------------------------- 1 | # 2 | # Autogenerated by Thrift Compiler (0.9.1) 3 | # 4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | # 6 | # options string: py 7 | # 8 | 9 | from thrift.Thrift import TType, TMessageType, TException, TApplicationException 10 | from ttypes import * 11 | 12 | -------------------------------------------------------------------------------- /example/client/Makefile: -------------------------------------------------------------------------------- 1 | #交叉编译器路径 2 | CROSS= 3 | CP=/bin/cp 4 | RM=-/bin/rm -rf 5 | LN=/bin/ln -s 6 | #是否开启sqlite的支持,如需要关闭,设置为空字符串 7 | FF_ENABLE_SQLITE_FLAG = 8 | #-DFF_ENABLE_SQLITE 9 | FF_ENABLE_CURL_FLAG = 10 | #-DFF_ENABLE_CURL 11 | CFLAGS=-g -Wall $(FF_ENABLE_CURL_FLAG) $(FF_ENABLE_SQLITE_FLAG) 12 | LDFLAGS= -O2 -lpthread -ldl -lpython2.6 -lmysqlclient 13 | #-lcurl 14 | #-llua 15 | #链接库名 16 | LIB_NAME= 17 | #链接库版本 18 | LIB_VER=1.0.0 19 | #平台 20 | ARCH= 21 | # 二进制目标 22 | BIN=app_game 23 | 24 | #源文件目录 25 | SrcDir= . ../../fflib/base ../../fflib/net ../../fflib/rpc ../../fflib/db ../../fflib/xml ../../fflib/server 26 | #头文件目录 27 | IncDir= ../../fflib/ ../../lib3party /usr/include/python2.7/ /usr/include/python2.6/ 28 | #连接库目录 29 | LibDir= /usr/local/lib /usr/lib/mysql /usr/lib64/mysql 30 | SRCS=$(foreach dir,$(SrcDir),$(wildcard $(dir)/*.cpp)) 31 | #INCS=$(foreach dir,$(IncDir),$(wildcard $(dir)/*.h)) 32 | INCS=$(foreach dir,$(IncDir),$(addprefix -I,$(dir))) 33 | LINKS=$(foreach dir,$(LibDir),$(addprefix -L,$(dir))) 34 | CFLAGS := $(CFLAGS) $(INCS) 35 | LDFLAGS:= $(LINKS) $(LDFLAGS) 36 | CC=gcc 37 | ARCH=PC 38 | OBJS = $(SRCS:%.cpp=%.o) 39 | .PHONY:all clean 40 | 41 | all:$(BIN) 42 | $(BIN):$(OBJS) 43 | ifeq ($(FF_ENABLE_SQLITE_FLAG),-DFF_ENABLE_SQLITE) 44 | gcc -c ../../fflib/db/sqlite3.c -o sqlite3.o 45 | g++ -o $(BIN) $(OBJS) sqlite3.o $(LDFLAGS) 46 | else 47 | g++ -o $(BIN) $(OBJS) $(LDFLAGS) 48 | endif 49 | @echo " OK! Compile $@ " 50 | # @$(LN) $(shell pwd)/$(LIB_NAME).$(LIB_VER) /lib/$(LIB_NAME) 51 | 52 | %.o:%.cpp 53 | @echo "[$(ARCH)] Compile $@..." 54 | @$(CC) $(CFLAGS) -c $< -o $@ 55 | 56 | .PHONY: clean 57 | clean: 58 | @echo "[$(ARCH)] Cleaning files..." 59 | @$(RM) $(OBJS) $(BIN) 60 | @$(RM) sqlite3.o 61 | -------------------------------------------------------------------------------- /example/game/Makefile: -------------------------------------------------------------------------------- 1 | #交叉编译器路径 2 | CROSS= 3 | CP=/bin/cp 4 | RM=-/bin/rm -rf 5 | LN=/bin/ln -s 6 | #是否开启sqlite的支持,如需要关闭,设置为空字符串 7 | FF_ENABLE_SQLITE_FLAG =-DFF_ENABLE_SQLITE 8 | FF_ENABLE_CURL_FLAG = 9 | #-DFF_ENABLE_CURL 10 | CFLAGS=-g -Wall $(FF_ENABLE_CURL_FLAG) $(FF_ENABLE_SQLITE_FLAG) 11 | LDFLAGS= -O2 -lpthread -ldl -lpython2.6 -lmysqlclient 12 | #-lcurl 13 | #-llua 14 | #链接库名 15 | LIB_NAME= 16 | #链接库版本 17 | LIB_VER=1.0.0 18 | #平台 19 | ARCH= 20 | # 二进制目标 21 | BIN=app_game 22 | 23 | #源文件目录 24 | SrcDir= . ../../fflib/base ../../fflib/net ../../fflib/rpc ../../fflib/rpc/msg_def ../../fflib/db ../../fflib/xml ../../fflib/server 25 | #头文件目录 26 | IncDir= ../../fflib/ ../../lib3party /usr/include/python2.7/ /usr/include/python2.6/ 27 | #连接库目录 28 | LibDir= /usr/local/lib /usr/lib/mysql /usr/lib64/mysql 29 | SRCS=$(foreach dir,$(SrcDir),$(wildcard $(dir)/*.cpp)) 30 | #INCS=$(foreach dir,$(IncDir),$(wildcard $(dir)/*.h)) 31 | INCS=$(foreach dir,$(IncDir),$(addprefix -I,$(dir))) 32 | LINKS=$(foreach dir,$(LibDir),$(addprefix -L,$(dir))) 33 | CFLAGS := $(CFLAGS) $(INCS) 34 | LDFLAGS:= $(LINKS) $(LDFLAGS) 35 | CC=gcc 36 | ARCH=PC 37 | OBJS = $(SRCS:%.cpp=%.o) 38 | .PHONY:all clean 39 | 40 | all:$(BIN) 41 | $(BIN):$(OBJS) 42 | ifeq ($(FF_ENABLE_SQLITE_FLAG),-DFF_ENABLE_SQLITE) 43 | gcc -c ../../fflib/db/sqlite3.c -o sqlite3.o 44 | g++ -o $(BIN) $(OBJS) sqlite3.o $(LDFLAGS) 45 | else 46 | g++ -o $(BIN) $(OBJS) $(LDFLAGS) 47 | endif 48 | @echo " OK! Compile $@ " 49 | # @$(LN) $(shell pwd)/$(LIB_NAME).$(LIB_VER) /lib/$(LIB_NAME) 50 | 51 | %.o:%.cpp 52 | @echo "[$(ARCH)] Compile $@..." 53 | @$(CC) $(CFLAGS) -c $< -o $@ 54 | 55 | .PHONY: clean 56 | clean: 57 | @echo "[$(ARCH)] Cleaning files..." 58 | @$(RM) $(OBJS) $(BIN) 59 | @$(RM) sqlite3.o 60 | -------------------------------------------------------------------------------- /example/game/ctrl.config: -------------------------------------------------------------------------------- 1 | 2 | #关于broker相关的配置, master_broker如果被设置表示该broker为slave broker, 如果需要跨组通信需要设置bridge_broker 3 | -broker tcp://*:1281 4 | #-master_broker tcp://127.0.0.1:20241 5 | #-bridge_broker tcp://127.0.0.1:30241 6 | 7 | #关于gate相关的配置,-gate 为gate的名称, gate_listen为监听的ip端口 8 | #-gate gate@0 -gate_listen tcp://*:30242 -heartbeat_timeout 600 9 | 10 | #scene 相关的配置 scene 为scene的名称, python_path为python的路径 11 | -scene ffEngine@0 -python_path ./pyctrl 12 | #-lua_scene scene@1 -lua_path ./luaproject 13 | #-lua_mod fflua@1 14 | 15 | #日志相关的配置 级别最大为debug=6,trace=5, info=4, warn=3, error=2, fatal=1 16 | -log_path ./log -log_filename fflog 17 | #-log_class DB_MGR,XX,BROKER,FFSCENE,FFSCENE_PYTHON,FFNET,PY 18 | -log_class DB_MGR,FFSCENE_PYTHON,FFSCENE_LUA,PY,BROKER 19 | -log_print_screen true -log_print_file true 20 | -log_level 5 21 | 22 | 23 | #性能监控单位秒 24 | -perf_timeout 3600 25 | #是否启动为守护进程 26 | #-d 27 | ##数据库相关的配置 账号/密码/数据库 28 | -db mysql://127.0.0.1:3306/root/acegame/pcgame 29 | #如果使用单独的账号系统,使用此db配置 30 | #-user_db mysql://127.0.0.1:3306/root/acegame/pcgame 31 | -------------------------------------------------------------------------------- /example/game/default.conf: -------------------------------------------------------------------------------- 1 | 2 | #关于broker相关的配置, master_broker如果被设置表示该broker为slave broker, 如果需要跨组通信需要设置bridge_broker 3 | -broker tcp://127.0.0.1:40241 4 | #-master_broker tcp://127.0.0.1:20241 5 | #-bridge_broker tcp://127.0.0.1:30241 6 | 7 | #关于gate相关的配置,-gate 为gate的名称, gate_listen为监听的ip端口 8 | -gate gate@0 -gate_listen tcp://*:30242 -heartbeat_timeout 600 9 | 10 | #scene 相关的配置 scene 为scene的名称, python_path为python的路径 11 | -scene scene@0 -python_path ./pyproject 12 | #-lua_scene scene@1 -lua_path ./luaproject 13 | #-lua_mod fflua@1 14 | 15 | #日志相关的配置 级别最大为debug=6,trace=5, info=4, warn=3, error=2, fatal=1 16 | -log_path ./log -log_filename fflog 17 | #-log_class DB_MGR,XX,BROKER,FFSCENE,FFSCENE_PYTHON,FFNET,PY 18 | -log_class DB_MGR,FFSCENE_PYTHON,FFGATE,FFSCENE,FFSCENE_LUA,PY 19 | -log_print_screen true -log_print_file true 20 | -log_level 5 21 | 22 | 23 | #性能监控单位秒 24 | -perf_timeout 3600 25 | #是否启动为守护进程 26 | #-d 27 | ##数据库相关的配置 账号/密码/数据库 28 | -db sqlite://./ff_demo.db 29 | -group_name demo 30 | -------------------------------------------------------------------------------- /example/game/main.lua: -------------------------------------------------------------------------------- 1 | 2 | 3 | function foo() 4 | end 5 | 6 | 7 | -------------------------------------------------------------------------------- /example/game/pyctrl/msg/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/example/game/pyctrl/msg/__init__.py -------------------------------------------------------------------------------- /example/game/pyctrl/msg/ffengine/__init__.py: -------------------------------------------------------------------------------- 1 | __all__ = ['ttypes', 'constants'] 2 | -------------------------------------------------------------------------------- /example/game/pyctrl/msg/ffengine/constants.py: -------------------------------------------------------------------------------- 1 | # 2 | # Autogenerated by Thrift Compiler (0.9.0) 3 | # 4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | # 6 | # options string: py 7 | # 8 | 9 | from thrift.Thrift import TType, TMessageType, TException, TApplicationException 10 | from ttypes import * 11 | 12 | -------------------------------------------------------------------------------- /example/game/pyctrl/msg_def/__init__.py: -------------------------------------------------------------------------------- 1 | __all__ = ['ttypes', 'constants'] 2 | -------------------------------------------------------------------------------- /example/game/pyctrl/msg_def/constants.py: -------------------------------------------------------------------------------- 1 | # 2 | # Autogenerated by Thrift Compiler (0.9.0) 3 | # 4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | # 6 | # options string: py 7 | # 8 | 9 | from thrift.Thrift import TType, TMessageType, TException, TApplicationException 10 | from ttypes import * 11 | 12 | -------------------------------------------------------------------------------- /example/game/pylib/event_bus.py: -------------------------------------------------------------------------------- 1 | # coding=UTF-8 2 | import traceback 3 | 4 | class event_bus_t(object): 5 | def __init__(self): 6 | #key event class, value is dict of consumer function 7 | self.event_consumer = {} 8 | #processing list, cache event 9 | self.event_cache_list = []#fifo 10 | def default_except_handler(exception_): 11 | traceback.print_exc() 12 | self.exception_handler = default_except_handler 13 | def set_exception_handler(func_): 14 | self.exception_handler = func_ 15 | def get_key_name(self, event_obj_): 16 | return event_obj_.__class__ 17 | def bind_event(self, event_class_, consumer_func): 18 | key = event_class_ 19 | consumer_name = consumer_func.__module__ + '.' + consumer_func.__name__ 20 | dest_dict = self.event_consumer.get(key) 21 | if dest_dict == None: 22 | dest_dict = {} 23 | self.event_consumer[key] = dest_dict 24 | dest_dict[consumer_name] = consumer_func 25 | def post(self, event_): 26 | self.event_cache_list.insert(0, event_) 27 | size = len(self.event_cache_list) 28 | if size > 1: 29 | return True 30 | 31 | while len(self.event_cache_list) > 0: 32 | next_event = self.event_cache_list[len(self.event_cache_list) - 1] 33 | key = self.get_key_name(next_event) 34 | dest_dict = self.event_consumer.get(key) 35 | if None != dest_dict: 36 | for k, func in dest_dict.iteritems(): 37 | try: 38 | func(event_) 39 | except Exception, e: 40 | self.exception_handler(e) 41 | except: 42 | pass 43 | self.event_cache_list.pop() 44 | 45 | def dump(self): 46 | print(self.event_consumer) 47 | 48 | event_bus = event_bus_t() 49 | def instance(): 50 | return event_bus 51 | 52 | def bind_event(event_class_): 53 | bind_list = [] 54 | if event_class_.__class__ == list: 55 | bind_list = event_class_ 56 | else: 57 | bind_list.append(event_class_) 58 | def wraper(func_): 59 | ebus = instance() 60 | for k in bind_list: 61 | ebus.bind_event(k, func_) 62 | return func_ 63 | return wraper 64 | 65 | def post(event_): 66 | instance().post(event_) 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /example/game/pylib/google/__init__.py: -------------------------------------------------------------------------------- 1 | __import__('pkg_resources').declare_namespace(__name__) 2 | -------------------------------------------------------------------------------- /example/game/pylib/google/protobuf/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/example/game/pylib/google/protobuf/__init__.py -------------------------------------------------------------------------------- /example/game/pylib/google/protobuf/compiler/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/example/game/pylib/google/protobuf/compiler/__init__.py -------------------------------------------------------------------------------- /example/game/pylib/google/protobuf/internal/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/example/game/pylib/google/protobuf/internal/__init__.py -------------------------------------------------------------------------------- /example/game/pylib/id_generator.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/example/game/pylib/id_generator.py -------------------------------------------------------------------------------- /example/game/pylib/protobuf_example/msg.proto: -------------------------------------------------------------------------------- 1 | 2 | message TestMsg 3 | { 4 | required int32 id=1; 5 | required int32 time=2; 6 | optional string note=3; 7 | } 8 | 9 | -------------------------------------------------------------------------------- /example/game/pylib/protobuf_example/msg_pb2.py: -------------------------------------------------------------------------------- 1 | # Generated by the protocol buffer compiler. DO NOT EDIT! 2 | # source: msg.proto 3 | 4 | from google.protobuf import descriptor as _descriptor 5 | from google.protobuf import message as _message 6 | from google.protobuf import reflection as _reflection 7 | from google.protobuf import descriptor_pb2 8 | # @@protoc_insertion_point(imports) 9 | 10 | 11 | 12 | 13 | DESCRIPTOR = _descriptor.FileDescriptor( 14 | name='msg.proto', 15 | package='', 16 | serialized_pb='\n\tmsg.proto\"1\n\x07TestMsg\x12\n\n\x02id\x18\x01 \x02(\x05\x12\x0c\n\x04time\x18\x02 \x02(\x05\x12\x0c\n\x04note\x18\x03 \x01(\t') 17 | 18 | 19 | 20 | 21 | _TESTMSG = _descriptor.Descriptor( 22 | name='TestMsg', 23 | full_name='TestMsg', 24 | filename=None, 25 | file=DESCRIPTOR, 26 | containing_type=None, 27 | fields=[ 28 | _descriptor.FieldDescriptor( 29 | name='id', full_name='TestMsg.id', index=0, 30 | number=1, type=5, cpp_type=1, label=2, 31 | has_default_value=False, default_value=0, 32 | message_type=None, enum_type=None, containing_type=None, 33 | is_extension=False, extension_scope=None, 34 | options=None), 35 | _descriptor.FieldDescriptor( 36 | name='time', full_name='TestMsg.time', index=1, 37 | number=2, type=5, cpp_type=1, label=2, 38 | has_default_value=False, default_value=0, 39 | message_type=None, enum_type=None, containing_type=None, 40 | is_extension=False, extension_scope=None, 41 | options=None), 42 | _descriptor.FieldDescriptor( 43 | name='note', full_name='TestMsg.note', index=2, 44 | number=3, type=9, cpp_type=9, label=1, 45 | has_default_value=False, default_value=unicode("", "utf-8"), 46 | message_type=None, enum_type=None, containing_type=None, 47 | is_extension=False, extension_scope=None, 48 | options=None), 49 | ], 50 | extensions=[ 51 | ], 52 | nested_types=[], 53 | enum_types=[ 54 | ], 55 | options=None, 56 | is_extendable=False, 57 | extension_ranges=[], 58 | serialized_start=13, 59 | serialized_end=62, 60 | ) 61 | 62 | DESCRIPTOR.message_types_by_name['TestMsg'] = _TESTMSG 63 | 64 | class TestMsg(_message.Message): 65 | __metaclass__ = _reflection.GeneratedProtocolMessageType 66 | DESCRIPTOR = _TESTMSG 67 | 68 | # @@protoc_insertion_point(class_scope:TestMsg) 69 | 70 | 71 | # @@protoc_insertion_point(module_scope) 72 | -------------------------------------------------------------------------------- /example/game/pylib/protobuf_example/protobuf_example.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/example/game/pylib/protobuf_example/protobuf_example.py -------------------------------------------------------------------------------- /example/game/pylib/thrift/TSCons.py: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | from os import path 21 | from SCons.Builder import Builder 22 | 23 | 24 | def scons_env(env, add=''): 25 | opath = path.dirname(path.abspath('$TARGET')) 26 | lstr = 'thrift --gen cpp -o ' + opath + ' ' + add + ' $SOURCE' 27 | cppbuild = Builder(action=lstr) 28 | env.Append(BUILDERS={'ThriftCpp': cppbuild}) 29 | 30 | 31 | def gen_cpp(env, dir, file): 32 | scons_env(env) 33 | suffixes = ['_types.h', '_types.cpp'] 34 | targets = map(lambda s: 'gen-cpp/' + file + s, suffixes) 35 | return env.ThriftCpp(targets, dir + file + '.thrift') 36 | -------------------------------------------------------------------------------- /example/game/pylib/thrift/TSerialization.py: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | from protocol import TBinaryProtocol 21 | from transport import TTransport 22 | 23 | 24 | def serialize(thrift_object, 25 | protocol_factory=TBinaryProtocol.TBinaryProtocolFactory()): 26 | transport = TTransport.TMemoryBuffer() 27 | protocol = protocol_factory.getProtocol(transport) 28 | thrift_object.write(protocol) 29 | return transport.getvalue() 30 | 31 | 32 | def deserialize(base, 33 | buf, 34 | protocol_factory=TBinaryProtocol.TBinaryProtocolFactory()): 35 | transport = TTransport.TMemoryBuffer(buf) 36 | protocol = protocol_factory.getProtocol(transport) 37 | base.read(protocol) 38 | return base 39 | -------------------------------------------------------------------------------- /example/game/pylib/thrift/__init__.py: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | __all__ = ['Thrift', 'TSCons'] 21 | -------------------------------------------------------------------------------- /example/game/pylib/thrift/protocol/TBase.py: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | from thrift.Thrift import * 21 | from thrift.protocol import TBinaryProtocol 22 | from thrift.transport import TTransport 23 | 24 | try: 25 | from thrift.protocol import fastbinary 26 | except: 27 | fastbinary = None 28 | 29 | 30 | class TBase(object): 31 | __slots__ = [] 32 | 33 | def __repr__(self): 34 | L = ['%s=%r' % (key, getattr(self, key)) 35 | for key in self.__slots__] 36 | return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) 37 | 38 | def __eq__(self, other): 39 | if not isinstance(other, self.__class__): 40 | return False 41 | for attr in self.__slots__: 42 | my_val = getattr(self, attr) 43 | other_val = getattr(other, attr) 44 | if my_val != other_val: 45 | return False 46 | return True 47 | 48 | def __ne__(self, other): 49 | return not (self == other) 50 | 51 | def read(self, iprot): 52 | if (iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and 53 | isinstance(iprot.trans, TTransport.CReadableTransport) and 54 | self.thrift_spec is not None and 55 | fastbinary is not None): 56 | fastbinary.decode_binary(self, 57 | iprot.trans, 58 | (self.__class__, self.thrift_spec)) 59 | return 60 | iprot.readStruct(self, self.thrift_spec) 61 | 62 | def write(self, oprot): 63 | if (oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and 64 | self.thrift_spec is not None and 65 | fastbinary is not None): 66 | oprot.trans.write( 67 | fastbinary.encode_binary(self, (self.__class__, self.thrift_spec))) 68 | return 69 | oprot.writeStruct(self, self.thrift_spec) 70 | 71 | 72 | class TExceptionBase(Exception): 73 | # old style class so python2.4 can raise exceptions derived from this 74 | # This can't inherit from TBase because of that limitation. 75 | __slots__ = [] 76 | 77 | __repr__ = TBase.__repr__.im_func 78 | __eq__ = TBase.__eq__.im_func 79 | __ne__ = TBase.__ne__.im_func 80 | read = TBase.read.im_func 81 | write = TBase.write.im_func 82 | -------------------------------------------------------------------------------- /example/game/pylib/thrift/protocol/__init__.py: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | __all__ = ['TProtocol', 'TBinaryProtocol', 'fastbinary', 'TBase'] 21 | -------------------------------------------------------------------------------- /example/game/pylib/thrift/server/__init__.py: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | __all__ = ['TServer', 'TNonblockingServer'] 21 | -------------------------------------------------------------------------------- /example/game/pylib/thrift/transport/__init__.py: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | __all__ = ['TTransport', 'TSocket', 'THttpClient', 'TZlibTransport'] 21 | -------------------------------------------------------------------------------- /example/game/pylib/thrift_example/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/example/game/pylib/thrift_example/__init__.py -------------------------------------------------------------------------------- /example/game/pylib/thrift_example/ff/__init__.py: -------------------------------------------------------------------------------- 1 | __all__ = ['ttypes', 'constants'] 2 | -------------------------------------------------------------------------------- /example/game/pylib/thrift_example/ff/constants.py: -------------------------------------------------------------------------------- 1 | # 2 | # Autogenerated by Thrift Compiler (0.9.0) 3 | # 4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | # 6 | # options string: py 7 | # 8 | 9 | from thrift.Thrift import TType, TMessageType, TException, TApplicationException 10 | from ttypes import * 11 | 12 | -------------------------------------------------------------------------------- /example/game/pylib/thrift_example/ff/ttypes.py: -------------------------------------------------------------------------------- 1 | # 2 | # Autogenerated by Thrift Compiler (0.9.0) 3 | # 4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | # 6 | # options string: py 7 | # 8 | 9 | from thrift.Thrift import TType, TMessageType, TException, TApplicationException 10 | 11 | from thrift.transport import TTransport 12 | from thrift.protocol import TBinaryProtocol, TProtocol 13 | try: 14 | from thrift.protocol import fastbinary 15 | except: 16 | fastbinary = None 17 | 18 | 19 | 20 | class foo_t: 21 | """ 22 | Attributes: 23 | - num 24 | """ 25 | 26 | thrift_spec = ( 27 | None, # 0 28 | (1, TType.I32, 'num', None, 100, ), # 1 29 | ) 30 | 31 | def __init__(self, num=thrift_spec[1][4],): 32 | self.num = num 33 | 34 | def read(self, iprot): 35 | if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None: 36 | fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec)) 37 | return 38 | iprot.readStructBegin() 39 | while True: 40 | (fname, ftype, fid) = iprot.readFieldBegin() 41 | if ftype == TType.STOP: 42 | break 43 | if fid == 1: 44 | if ftype == TType.I32: 45 | self.num = iprot.readI32(); 46 | else: 47 | iprot.skip(ftype) 48 | else: 49 | iprot.skip(ftype) 50 | iprot.readFieldEnd() 51 | iprot.readStructEnd() 52 | 53 | def write(self, oprot): 54 | if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None: 55 | oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec))) 56 | return 57 | oprot.writeStructBegin('foo_t') 58 | if self.num is not None: 59 | oprot.writeFieldBegin('num', TType.I32, 1) 60 | oprot.writeI32(self.num) 61 | oprot.writeFieldEnd() 62 | oprot.writeFieldStop() 63 | oprot.writeStructEnd() 64 | 65 | def validate(self): 66 | return 67 | 68 | 69 | def __repr__(self): 70 | L = ['%s=%r' % (key, value) 71 | for key, value in self.__dict__.iteritems()] 72 | return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) 73 | 74 | def __eq__(self, other): 75 | return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ 76 | 77 | def __ne__(self, other): 78 | return not (self == other) 79 | -------------------------------------------------------------------------------- /example/game/pylib/thrift_example/thrift_example.py: -------------------------------------------------------------------------------- 1 | 2 | import thrift.Thrift as Thrift 3 | import thrift.protocol.TBinaryProtocol as TBinaryProtocol 4 | import thrift.protocol.TCompactProtocol as TCompactProtocol 5 | 6 | import thrift.transport.TTransport as TTransport 7 | import gen.ff.ttypes as ttypes 8 | 9 | mb = TTransport.TMemoryBuffer() 10 | #bp = TBinaryProtocol.TBinaryProtocol(mb) 11 | bp = TCompactProtocol.TCompactProtocol(mb) 12 | 13 | foo= ttypes.foo_t() 14 | print(foo) 15 | foo.write(bp) 16 | 17 | 18 | ret = mb.getvalue() 19 | print(len(ret)) 20 | 21 | mb2 = TTransport.TMemoryBuffer(ret) 22 | #bp2 = TBinaryProtocol.TBinaryProtocol(mb2) 23 | bp2 = TCompactProtocol.TCompactProtocol(mb2) 24 | foo2= ttypes.foo_t() 25 | foo2.read(bp2); 26 | 27 | print(foo2) 28 | 29 | 30 | -------------------------------------------------------------------------------- /example/game/pylib/wrods_filter.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | dest_code = 'utf-8' 4 | class words_filter_t: 5 | def __init__(self, words_list_): 6 | self.word_index = {}# {one word -> []} 7 | self.all_words = {} 8 | for w in words_list_: 9 | word = unicode(w, dest_code, 'ignore') 10 | word_len = len(word) 11 | if word_len == 0: 12 | continue 13 | dest_array = self.word_index.get(word[0]) 14 | if None == dest_array: 15 | dest_array = [] 16 | #print(__name__, 'filer') 17 | #print(word[0]) 18 | self.word_index[word[0]] = dest_array 19 | if word_len not in dest_array: 20 | dest_array.append(word_len) 21 | dest_array.sort(reverse=True) 22 | self.all_words[word] = True 23 | print(__name__, "load filter words %d"%(len(self.all_words))) 24 | def dump(self, ): 25 | print (self.word_index, self.all_words) 26 | 27 | def filter(self, src_, replace_ = '*'): 28 | ret = unicode('', dest_code, 'ignore') 29 | word_src = unicode(src_, dest_code, 'ignore') 30 | i = 0 31 | while i < len(word_src): 32 | w = word_src[i] 33 | #print(__name__, 'filer') 34 | #print(w) 35 | dest_list = self.word_index.get(w) 36 | if None == dest_list: 37 | i += 1 38 | ret += w 39 | continue 40 | replace_num = 0 41 | for dest_len in dest_list: 42 | check_word = word_src[i:i + dest_len] 43 | #print('check_word', check_word) 44 | if None != self.all_words.get(check_word): 45 | i += dest_len 46 | #print('del', check_word) 47 | replace_num = len(check_word)#len(check_word.encode(dest_code)) 48 | break 49 | if replace_num == 0: 50 | ret += w 51 | i += 1 52 | else: 53 | ret += replace_ * replace_num 54 | return ret.encode(dest_code) 55 | 56 | word_filter = None 57 | def init(src_file_): 58 | global word_filter 59 | wlist = [] 60 | f = open(src_file_) 61 | for line in f.readlines(): 62 | tmp = line.split('\n') 63 | wlist.append(tmp[0]) 64 | word_filter = words_filter_t(wlist) 65 | 66 | def filter(src, replace_ = '*'): 67 | global word_filter 68 | return word_filter.filter(src, replace_) 69 | 70 | 71 | #init('fw.txt') 72 | 73 | -------------------------------------------------------------------------------- /example/game/pyproject/echo_msg_def/__init__.py: -------------------------------------------------------------------------------- 1 | __all__ = ['ttypes', 'constants'] 2 | -------------------------------------------------------------------------------- /example/game/pyproject/echo_msg_def/constants.py: -------------------------------------------------------------------------------- 1 | # 2 | # Autogenerated by Thrift Compiler (0.9.1) 3 | # 4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | # 6 | # options string: py 7 | # 8 | 9 | from thrift.Thrift import TType, TMessageType, TException, TApplicationException 10 | from ttypes import * 11 | 12 | -------------------------------------------------------------------------------- /example/game/pyproject/handler/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/example/game/pyproject/handler/__init__.py -------------------------------------------------------------------------------- /example/game/pyproject/main-bk.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/example/game/pyproject/main-bk.py -------------------------------------------------------------------------------- /example/game/pyproject/main.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import ffext 3 | import handler.player_handler 4 | from model import db_service 5 | 6 | import echo_msg_def.ttypes as ttypes 7 | 8 | def init(): 9 | print('init......') 10 | if db_service.init() == False: 11 | return -1 12 | 13 | return 0 14 | 15 | 16 | def cleanup(): 17 | print('cleanup.....') 18 | return 0 19 | 20 | 21 | @ffext.ff_reg_scene_interfacee(ttypes.echo_thrift_in_t, ttypes.echo_thrift_out_t) 22 | def test_echo(req): 23 | ret_msg = ttypes.echo_thrift_out_t() 24 | ret_msg.data = req.msg.data 25 | req.response(ret_msg) 26 | print('test_echo', req.msg) 27 | return 28 | -------------------------------------------------------------------------------- /example/game/pyproject/model/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/example/game/pyproject/model/__init__.py -------------------------------------------------------------------------------- /example/game/pyproject/model/db_service.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import ffext 4 | import id_generator 5 | 6 | g_async_db = None 7 | def get_async_db(): 8 | global g_async_db 9 | return g_async_db 10 | 11 | def init(): 12 | global g_async_db 13 | #g_sync_db = ffext.ffdb_create('mysql://localhost:3306/root/acegame/pcgame') 14 | db_config = ffext.get_config('-db') 15 | print('db_config=%s'%(db_config)) 16 | g_async_db = ffext.ffdb_create(db_config) 17 | if None == g_async_db: 18 | return False 19 | sql = '''create table IF NOT EXISTS player_info 20 | ( 21 | UID bigint not null, 22 | NAME varchar(255) not null, 23 | X int not null, 24 | Y int not null, 25 | primary key(UID) 26 | )''' 27 | g_async_db.query(sql) 28 | return True 29 | 30 | def load_by_name(name_, callback): 31 | sql = "select * from player_info where NAME='%s' limit 1"%(name_) 32 | def cb(ret): 33 | retData = {} 34 | if ret.flag == False or len(ret.result) == 0: 35 | callback(retData) 36 | return 37 | for i in range(0, len(ret.column)): 38 | retData[ret.column[i]] = ret.result[0][i] 39 | callback(retData) 40 | return 41 | get_async_db().query(sql, cb) 42 | return 43 | 44 | def insert_player(field_data): 45 | sql = '' 46 | values = '' 47 | for k, v in field_data.iteritems(): 48 | if sql == '': 49 | sql = "insert into player_info ({0}".format(k) 50 | values = ") values ('{0}'".format(v) 51 | else: 52 | sql += ", {0}".format(k) 53 | values += ", '{0}'".format(v) 54 | sql += values + ')' 55 | print(sql) 56 | g_async_db.query(sql) 57 | return 58 | 59 | def update_player(uid, field_data): 60 | sql = '' 61 | for k, v in field_data.iteritems(): 62 | if sql == '': 63 | sql = "update player_info set {0} = '{1}'".format(k, v) 64 | else: 65 | sql += ", {0} = '{1}'".format(k, v) 66 | sql += " where uid = '{0}'".format(uid) 67 | print(sql) 68 | g_async_db.query(sql) 69 | return 70 | 71 | -------------------------------------------------------------------------------- /example/game/pyproject/model/player_model.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | class player_t: 4 | def __init__(self): 5 | self.id = 0 6 | self.name = '' 7 | self.x = 0 8 | self.y = 0 9 | self.last_move_tm = time.time() 10 | 11 | -------------------------------------------------------------------------------- /example/game/pyproject/msg_def/__init__.py: -------------------------------------------------------------------------------- 1 | __all__ = ['ttypes', 'constants'] 2 | -------------------------------------------------------------------------------- /example/game/pyproject/msg_def/constants.py: -------------------------------------------------------------------------------- 1 | # 2 | # Autogenerated by Thrift Compiler (0.9.0) 3 | # 4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | # 6 | # options string: py 7 | # 8 | 9 | from thrift.Thrift import TType, TMessageType, TException, TApplicationException 10 | from ttypes import * 11 | 12 | -------------------------------------------------------------------------------- /example/game/pyproject/user_data/__init__.py: -------------------------------------------------------------------------------- 1 | __all__ = ['ttypes', 'constants'] 2 | -------------------------------------------------------------------------------- /example/game/pyproject/user_data/constants.py: -------------------------------------------------------------------------------- 1 | # 2 | # Autogenerated by Thrift Compiler (0.9.1) 3 | # 4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | # 6 | # options string: py 7 | # 8 | 9 | from thrift.Thrift import TType, TMessageType, TException, TApplicationException 10 | from ttypes import * 11 | 12 | -------------------------------------------------------------------------------- /example/php_sdk/Thrift/Exception/TApplicationException.php: -------------------------------------------------------------------------------- 1 | array('var' => 'message', 31 | 'type' => TType::STRING), 32 | 2 => array('var' => 'code', 33 | 'type' => TType::I32)); 34 | 35 | const UNKNOWN = 0; 36 | const UNKNOWN_METHOD = 1; 37 | const INVALID_MESSAGE_TYPE = 2; 38 | const WRONG_METHOD_NAME = 3; 39 | const BAD_SEQUENCE_ID = 4; 40 | const MISSING_RESULT = 5; 41 | const INTERNAL_ERROR = 6; 42 | const PROTOCOL_ERROR = 7; 43 | const INVALID_TRANSFORM = 8; 44 | const INVALID_PROTOCOL = 9; 45 | const UNSUPPORTED_CLIENT_TYPE = 10; 46 | 47 | function __construct($message=null, $code=0) { 48 | parent::__construct($message, $code); 49 | } 50 | 51 | public function read($output) { 52 | return $this->_read('TApplicationException', self::$_TSPEC, $output); 53 | } 54 | 55 | public function write($output) { 56 | $xfer = 0; 57 | $xfer += $output->writeStructBegin('TApplicationException'); 58 | if ($message = $this->getMessage()) { 59 | $xfer += $output->writeFieldBegin('message', TType::STRING, 1); 60 | $xfer += $output->writeString($message); 61 | $xfer += $output->writeFieldEnd(); 62 | } 63 | if ($code = $this->getCode()) { 64 | $xfer += $output->writeFieldBegin('type', TType::I32, 2); 65 | $xfer += $output->writeI32($code); 66 | $xfer += $output->writeFieldEnd(); 67 | } 68 | $xfer += $output->writeFieldStop(); 69 | $xfer += $output->writeStructEnd(); 70 | return $xfer; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /example/php_sdk/Thrift/Exception/TProtocolException.php: -------------------------------------------------------------------------------- 1 | strictRead_ = $strictRead; 37 | $this->strictWrite_ = $strictWrite; 38 | } 39 | 40 | public function getProtocol($trans) { 41 | return new TBinaryProtocol($trans, $this->strictRead_, $this->strictWrite_); 42 | } 43 | } -------------------------------------------------------------------------------- /example/php_sdk/Thrift/Factory/TCompactProtocolFactory.php: -------------------------------------------------------------------------------- 1 | p_ = $p; 35 | } 36 | 37 | public function write() { 38 | if ($this->first_) { 39 | $this->first_ = false; 40 | } else { 41 | $this->p_->getTransport()->write(TJSONProtocol::COMMA); 42 | } 43 | } 44 | 45 | public function read() { 46 | if ($this->first_) { 47 | $this->first_ = false; 48 | } else { 49 | $this->p_->readJSONSyntaxChar(TJSONProtocol::COMMA); 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /example/php_sdk/Thrift/Protocol/JSON/LookaheadReader.php: -------------------------------------------------------------------------------- 1 | p_ = $p; 34 | } 35 | 36 | public function read() { 37 | if ($this->hasData_) { 38 | $this->hasData_ = false; 39 | } else { 40 | $this->data_ = $this->p_->getTransport()->readAll(1); 41 | } 42 | 43 | return substr($this->data_, 0, 1); 44 | } 45 | 46 | public function peek() { 47 | if (!$this->hasData_) { 48 | $this->data_ = $this->p_->getTransport()->readAll(1); 49 | } 50 | 51 | $this->hasData_ = true; 52 | return substr($this->data_, 0, 1); 53 | } 54 | } -------------------------------------------------------------------------------- /example/php_sdk/Thrift/Protocol/JSON/PairContext.php: -------------------------------------------------------------------------------- 1 | p_ = $p; 35 | } 36 | 37 | public function write() { 38 | if ($this->first_) { 39 | $this->first_ = false; 40 | $this->colon_ = true; 41 | } else { 42 | $this->p_->getTransport()->write($this->colon_ ? TJSONProtocol::COLON : TJSONProtocol::COMMA); 43 | $this->colon_ = !$this->colon_; 44 | } 45 | } 46 | 47 | public function read() { 48 | if ($this->first_) { 49 | $this->first_ = false; 50 | $this->colon_ = true; 51 | } else { 52 | $this->p_->readJSONSyntaxChar($this->colon_ ? TJSONProtocol::COLON : TJSONProtocol::COMMA); 53 | $this->colon_ = !$this->colon_; 54 | } 55 | } 56 | 57 | public function escapeNum() { 58 | return $this->colon_; 59 | } 60 | } -------------------------------------------------------------------------------- /example/php_sdk/Thrift/Protocol/TBinaryProtocolAccelerated.php: -------------------------------------------------------------------------------- 1 | strictRead_; 43 | } 44 | public function isStrictWrite() { 45 | return $this->strictWrite_; 46 | } 47 | } -------------------------------------------------------------------------------- /example/php_sdk/Thrift/Server/TServer.php: -------------------------------------------------------------------------------- 1 | processor_ = $processor; 77 | $this->transport_ = $transport; 78 | $this->inputTransportFactory_ = $inputTransportFactory; 79 | $this->outputTransportFactory_ = $outputTransportFactory; 80 | $this->inputProtocolFactory_ = $inputProtocolFactory; 81 | $this->outputProtocolFactory_ = $outputProtocolFactory; 82 | } 83 | 84 | /** 85 | * Serves the server. This should never return 86 | * unless a problem permits it to do so or it 87 | * is interrupted intentionally 88 | * 89 | * @abstract 90 | * @return void 91 | */ 92 | abstract public function serve(); 93 | 94 | /** 95 | * Stops the server serving 96 | * 97 | * @abstract 98 | * @return void 99 | */ 100 | abstract public function stop(); 101 | } 102 | -------------------------------------------------------------------------------- /example/php_sdk/Thrift/Server/TServerSocket.php: -------------------------------------------------------------------------------- 1 | host_ = $host; 52 | $this->port_ = $port; 53 | } 54 | 55 | /** 56 | * Sets the accept timeout 57 | * 58 | * @param int $acceptTimeout 59 | * @return void 60 | */ 61 | public function setAcceptTimeout($acceptTimeout) { 62 | $this->acceptTimeout_ = $acceptTimeout; 63 | } 64 | 65 | /** 66 | * Opens a new socket server handle 67 | * 68 | * @return void 69 | */ 70 | public function listen() { 71 | $this->listener_ = stream_socket_server('tcp://' . $this->host_ . ':' . $this->port_); 72 | } 73 | 74 | /** 75 | * Closes the socket server handle 76 | * 77 | * @return void 78 | */ 79 | public function close() { 80 | @fclose($this->listener_); 81 | $this->listener_ = null; 82 | } 83 | 84 | /** 85 | * Implementation of accept. If not client is accepted in the given time 86 | * 87 | * @return TSocket 88 | */ 89 | protected function acceptImpl() { 90 | $handle = @stream_socket_accept($this->listener_, $this->acceptTimeout_ / 1000.0); 91 | if(!$handle) return null; 92 | 93 | $socket = new TSocket(); 94 | $socket->setHandle($handle); 95 | 96 | return $socket; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /example/php_sdk/Thrift/Server/TServerTransport.php: -------------------------------------------------------------------------------- 1 | acceptImpl(); 47 | 48 | if ($transport == null) { 49 | throw new TTransportException("accept() may not return NULL"); 50 | } 51 | 52 | return $transport; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /example/php_sdk/Thrift/Server/TSimpleServer.php: -------------------------------------------------------------------------------- 1 | transport_->listen(); 30 | 31 | while (!$this->stop_) { 32 | try { 33 | $transport = $this->transport_->accept(); 34 | 35 | if ($transport != null) { 36 | $inputTransport = $this->inputTransportFactory_->getTransport($transport); 37 | $outputTransport = $this->outputTransportFactory_->getTransport($transport); 38 | $inputProtocol = $this->inputProtocolFactory_->getProtocol($inputTransport); 39 | $outputProtocol = $this->outputProtocolFactory_->getProtocol($outputTransport); 40 | while ($this->processor_->process($inputProtocol, $outputProtocol)) { } 41 | } 42 | } 43 | catch (TTransportException $e) { } 44 | } 45 | } 46 | 47 | /** 48 | * Stops the server running. Kills the transport 49 | * and then stops the main serving loop 50 | * 51 | * @return void 52 | */ 53 | public function stop() { 54 | $this->transport_->close(); 55 | $this->stop_ = true; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /example/php_sdk/Thrift/StringFunc/Core.php: -------------------------------------------------------------------------------- 1 | strlen($str) - $start; 37 | } 38 | 39 | return mb_substr($str, $start, $length, '8bit'); 40 | } 41 | 42 | public function strlen($str) { 43 | return mb_strlen($str, '8bit'); 44 | } 45 | } -------------------------------------------------------------------------------- /example/php_sdk/Thrift/StringFunc/TStringFunc.php: -------------------------------------------------------------------------------- 1 | buf_ = $buf; 45 | } 46 | 47 | protected $buf_ = ''; 48 | 49 | public function isOpen() { 50 | return true; 51 | } 52 | 53 | public function open() {} 54 | 55 | public function close() {} 56 | 57 | public function write($buf) { 58 | $this->buf_ .= $buf; 59 | } 60 | 61 | public function read($len) { 62 | $bufLength = TStringFuncFactory::create()->strlen($this->buf_); 63 | 64 | if ($bufLength === 0) { 65 | throw new TTransportException('TMemoryBuffer: Could not read ' . 66 | $len . ' bytes from buffer.', 67 | TTransportException::UNKNOWN); 68 | } 69 | 70 | if ($bufLength <= $len) { 71 | $ret = $this->buf_; 72 | $this->buf_ = ''; 73 | return $ret; 74 | } 75 | 76 | $ret = TStringFuncFactory::create()->substr($this->buf_, 0, $len); 77 | $this->buf_ = TStringFuncFactory::create()->substr($this->buf_, $len); 78 | 79 | return $ret; 80 | } 81 | 82 | function getBuffer() { 83 | return $this->buf_; 84 | } 85 | 86 | public function available() { 87 | return TStringFuncFactory::create()->strlen($this->buf_); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /example/php_sdk/Thrift/Transport/TNullTransport.php: -------------------------------------------------------------------------------- 1 | read($len); 70 | 71 | $data = ''; 72 | $got = 0; 73 | while (($got = TStringFuncFactory::create()->strlen($data)) < $len) { 74 | $data .= $this->read($len - $got); 75 | } 76 | return $data; 77 | } 78 | 79 | /** 80 | * Writes the given data out. 81 | * 82 | * @param string $buf The data to write 83 | * @throws TTransportException if writing fails 84 | */ 85 | public abstract function write($buf); 86 | 87 | /** 88 | * Flushes any pending data out of a buffer 89 | * 90 | * @throws TTransportException if a writing error occurs 91 | */ 92 | public function flush() {} 93 | } 94 | -------------------------------------------------------------------------------- /example/php_sdk/Thrift/Type/TMessageType.php: -------------------------------------------------------------------------------- 1 | ' 13 | 14 | while 1: 15 | print 'waiting for connection' 16 | clientsock, addr = serversock.accept() 17 | print 'connected from:', addr 18 | 19 | data = '' 20 | while 1: 21 | try: 22 | data = clientsock.recv(BUFSIZ) 23 | except: 24 | print('error') 25 | break 26 | if not data: break 27 | print('*'*20, datetime.datetime.now()) 28 | print('recv len:', len(data)) 29 | clientsock.send(data) 30 | 31 | clientsock.close() 32 | 33 | serversock.close() 34 | -------------------------------------------------------------------------------- /example/python_sdk/ff/ttypes.py: -------------------------------------------------------------------------------- 1 | # 2 | # Autogenerated by Thrift Compiler (0.9.0) 3 | # 4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | # 6 | # options string: py 7 | # 8 | 9 | from thrift.Thrift import TType, TMessageType, TException, TApplicationException 10 | 11 | from thrift.transport import TTransport 12 | from thrift.protocol import TBinaryProtocol, TProtocol 13 | try: 14 | from thrift.protocol import fastbinary 15 | except: 16 | fastbinary = None 17 | 18 | 19 | 20 | class foo_t: 21 | """ 22 | Attributes: 23 | - num 24 | """ 25 | 26 | thrift_spec = ( 27 | None, # 0 28 | (1, TType.I32, 'num', None, 100, ), # 1 29 | ) 30 | 31 | def __init__(self, num=thrift_spec[1][4],): 32 | self.num = num 33 | 34 | def read(self, iprot): 35 | if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None: 36 | fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec)) 37 | return 38 | iprot.readStructBegin() 39 | while True: 40 | (fname, ftype, fid) = iprot.readFieldBegin() 41 | if ftype == TType.STOP: 42 | break 43 | if fid == 1: 44 | if ftype == TType.I32: 45 | self.num = iprot.readI32(); 46 | else: 47 | iprot.skip(ftype) 48 | else: 49 | iprot.skip(ftype) 50 | iprot.readFieldEnd() 51 | iprot.readStructEnd() 52 | 53 | def write(self, oprot): 54 | if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None: 55 | oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec))) 56 | return 57 | oprot.writeStructBegin('foo_t') 58 | if self.num is not None: 59 | oprot.writeFieldBegin('num', TType.I32, 1) 60 | oprot.writeI32(self.num) 61 | oprot.writeFieldEnd() 62 | oprot.writeFieldStop() 63 | oprot.writeStructEnd() 64 | 65 | def validate(self): 66 | return 67 | 68 | 69 | def __repr__(self): 70 | L = ['%s=%r' % (key, value) 71 | for key, value in self.__dict__.iteritems()] 72 | return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) 73 | 74 | def __eq__(self, other): 75 | return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ 76 | 77 | def __ne__(self, other): 78 | return not (self == other) 79 | -------------------------------------------------------------------------------- /example/python_sdk/gen_py/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/example/python_sdk/gen_py/__init__.py -------------------------------------------------------------------------------- /example/python_sdk/gen_py/echo.thrift: -------------------------------------------------------------------------------- 1 | namespace cpp ff 2 | 3 | struct echo_thrift_in_t { 4 | 1: string data 5 | } 6 | 7 | struct echo_thrift_out_t { 8 | 1: string data 9 | } 10 | 11 | -------------------------------------------------------------------------------- /example/python_sdk/gen_py/echo/__init__.py: -------------------------------------------------------------------------------- 1 | __all__ = ['ttypes', 'constants'] 2 | -------------------------------------------------------------------------------- /example/python_sdk/gen_py/echo/constants.py: -------------------------------------------------------------------------------- 1 | # 2 | # Autogenerated by Thrift Compiler (0.9.1) 3 | # 4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | # 6 | # options string: py 7 | # 8 | 9 | from thrift.Thrift import TType, TMessageType, TException, TApplicationException 10 | from ttypes import * 11 | 12 | -------------------------------------------------------------------------------- /example/python_sdk/gen_py/thrift-0.9.1.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/example/python_sdk/gen_py/thrift-0.9.1.exe -------------------------------------------------------------------------------- /example/python_sdk/thrift/TSCons.py: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | from os import path 21 | from SCons.Builder import Builder 22 | 23 | 24 | def scons_env(env, add=''): 25 | opath = path.dirname(path.abspath('$TARGET')) 26 | lstr = 'thrift --gen cpp -o ' + opath + ' ' + add + ' $SOURCE' 27 | cppbuild = Builder(action=lstr) 28 | env.Append(BUILDERS={'ThriftCpp': cppbuild}) 29 | 30 | 31 | def gen_cpp(env, dir, file): 32 | scons_env(env) 33 | suffixes = ['_types.h', '_types.cpp'] 34 | targets = map(lambda s: 'gen-cpp/' + file + s, suffixes) 35 | return env.ThriftCpp(targets, dir + file + '.thrift') 36 | -------------------------------------------------------------------------------- /example/python_sdk/thrift/TSerialization.py: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | from protocol import TBinaryProtocol 21 | from transport import TTransport 22 | 23 | 24 | def serialize(thrift_object, 25 | protocol_factory=TBinaryProtocol.TBinaryProtocolFactory()): 26 | transport = TTransport.TMemoryBuffer() 27 | protocol = protocol_factory.getProtocol(transport) 28 | thrift_object.write(protocol) 29 | return transport.getvalue() 30 | 31 | 32 | def deserialize(base, 33 | buf, 34 | protocol_factory=TBinaryProtocol.TBinaryProtocolFactory()): 35 | transport = TTransport.TMemoryBuffer(buf) 36 | protocol = protocol_factory.getProtocol(transport) 37 | base.read(protocol) 38 | return base 39 | -------------------------------------------------------------------------------- /example/python_sdk/thrift/__init__.py: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | __all__ = ['Thrift', 'TSCons'] 21 | -------------------------------------------------------------------------------- /example/python_sdk/thrift/msg_def/__init__.py: -------------------------------------------------------------------------------- 1 | __all__ = ['ttypes', 'constants'] 2 | -------------------------------------------------------------------------------- /example/python_sdk/thrift/msg_def/constants.py: -------------------------------------------------------------------------------- 1 | # 2 | # Autogenerated by Thrift Compiler (0.9.0) 3 | # 4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | # 6 | # options string: py 7 | # 8 | 9 | from thrift.Thrift import TType, TMessageType, TException, TApplicationException 10 | from ttypes import * 11 | 12 | -------------------------------------------------------------------------------- /example/python_sdk/thrift/protocol/__init__.py: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | __all__ = ['TProtocol', 'TBinaryProtocol', 'fastbinary', 'TBase'] 21 | -------------------------------------------------------------------------------- /example/python_sdk/thrift/server/__init__.py: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | __all__ = ['TServer', 'TNonblockingServer'] 21 | -------------------------------------------------------------------------------- /example/python_sdk/thrift/transport/__init__.py: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | __all__ = ['TTransport', 'TSocket', 'THttpClient', 'TZlibTransport'] 21 | -------------------------------------------------------------------------------- /example/tutorial/Makefile: -------------------------------------------------------------------------------- 1 | #交叉编译器路径 2 | CROSS= 3 | CP=/bin/cp 4 | RM=-/bin/rm -rf 5 | LN=/bin/ln -s 6 | CFLAGS=-g -Wall 7 | LDFLAGS= -lpthread 8 | #链接库名 9 | LIB_NAME= 10 | #链接库版本 11 | LIB_VER=1.0.0 12 | #平台 13 | ARCH= 14 | # 二进制目标 15 | BIN=app_rpc 16 | 17 | #源文件目录 18 | SrcDir= ./gen-cpp/ . ../../fflib/base ../../fflib/net ../../fflib/rpc 19 | #头文件目录 20 | IncDir= ../../lib3party ../../fflib/ ./ 21 | #连接库目录 22 | LibDir= /usr/local/lib 23 | SRCS=$(foreach dir,$(SrcDir),$(wildcard $(dir)/*.cpp)) 24 | #INCS=$(foreach dir,$(IncDir),$(wildcard $(dir)/*.h)) 25 | INCS=$(foreach dir,$(IncDir),$(addprefix -I,$(dir))) 26 | LINKS=$(foreach dir,$(LibDir),$(addprefix -L,$(dir))) 27 | CFLAGS := $(CFLAGS) $(INCS) 28 | LDFLAGS:= $(LINKS) $(LDFLAGS) 29 | CC=gcc 30 | ARCH=PC 31 | OBJS = $(SRCS:%.cpp=%.o) 32 | .PHONY:all clean 33 | 34 | all:$(BIN) 35 | $(BIN):$(OBJS) 36 | g++ -o $(BIN) $(OBJS) $(LDFLAGS) 37 | @echo -e " OK!\tCompile $@ " 38 | # @$(LN) $(shell pwd)/$(LIB_NAME).$(LIB_VER) /lib/$(LIB_NAME) 39 | 40 | %.o:%.cpp 41 | @echo -e "[$(ARCH)] \t\tCompile $@..." 42 | @$(CC) $(CFLAGS) -c $< -o $@ 43 | 44 | .PHONY: clean 45 | clean: 46 | @echo -e "[$(ARCH)] \tCleaning files..." 47 | @$(RM) $(OBJS) $(BIN) 48 | -------------------------------------------------------------------------------- /example/tutorial/echo.proto: -------------------------------------------------------------------------------- 1 | // See README.txt for information and build instructions. 2 | 3 | package ff; 4 | 5 | message pb_echo_in_t { 6 | required string data = 1; 7 | } 8 | message pb_echo_out_t { 9 | required string data = 1; 10 | } 11 | -------------------------------------------------------------------------------- /example/tutorial/echo.thrift: -------------------------------------------------------------------------------- 1 | namespace cpp ff 2 | namespace py ff 3 | namespace php ff 4 | 5 | struct echo_thrift_in_t { 6 | 1: string data 7 | } 8 | 9 | struct echo_thrift_out_t { 10 | 1: string data 11 | } 12 | 13 | -------------------------------------------------------------------------------- /example/tutorial/echo_constants.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift Compiler (0.9.1) 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #include "echo_constants.h" 8 | 9 | namespace ff { 10 | 11 | const echoConstants g_echo_constants; 12 | 13 | echoConstants::echoConstants() { 14 | } 15 | 16 | } // namespace 17 | 18 | -------------------------------------------------------------------------------- /example/tutorial/echo_constants.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift Compiler (0.9.1) 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #ifndef echo_CONSTANTS_H 8 | #define echo_CONSTANTS_H 9 | 10 | #include "echo_types.h" 11 | 12 | namespace ff { 13 | 14 | class echoConstants { 15 | public: 16 | echoConstants(); 17 | 18 | }; 19 | 20 | extern const echoConstants g_echo_constants; 21 | 22 | } // namespace 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /example/tutorial/echo_test.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/example/tutorial/echo_test.h -------------------------------------------------------------------------------- /example/tutorial/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "base/daemon_tool.h" 3 | #include "base/arg_helper.h" 4 | #include "base/strtool.h" 5 | #include "base/smart_ptr.h" 6 | 7 | #include "rpc/ffrpc.h" 8 | #include "rpc/ffbroker.h" 9 | #include "base/log.h" 10 | #include "base/signal_helper.h" 11 | #include "echo_test.h" 12 | #include "protobuf_test.h" 13 | #include "thrift_test.h" 14 | 15 | using namespace ff; 16 | 17 | int main(int argc, char* argv[]) 18 | { 19 | //! 美丽的日志组件,shell输出是彩色滴!! 20 | LOG.start("-log_path ./log -log_filename log -log_class XX,BROKER,FFRPC -log_print_screen true -log_print_file false -log_level 4"); 21 | 22 | if (argc == 1) 23 | { 24 | printf("usage: %s -broker tcp://127.0.0.1:10241\n", argv[0]); 25 | return 1; 26 | } 27 | arg_helper_t arg_helper(argc, argv); 28 | 29 | //! 启动broker,负责网络相关的操作,如消息转发,节点注册,重连等 30 | 31 | ffbroker_t ffbroker; 32 | if (ffbroker.open(arg_helper)) 33 | { 34 | return -1; 35 | } 36 | 37 | sleep(1); 38 | if (arg_helper.is_enable_option("-echo_test")) 39 | { 40 | run_echo_test(arg_helper); 41 | } 42 | else if (arg_helper.is_enable_option("-protobuf_test")) 43 | { 44 | run_protobuf_test(arg_helper); 45 | } 46 | else if (arg_helper.is_enable_option("-thrift_test")) 47 | { 48 | run_thrift_test(arg_helper); 49 | } 50 | else 51 | { 52 | printf("usage %s -broker tcp://127.0.0.1:10241 -echo_test\n", argv[0]); 53 | return -1; 54 | } 55 | 56 | ffbroker.close(); 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /example/tutorial/protobuf.Makefile: -------------------------------------------------------------------------------- 1 | #交叉编译器路径 2 | CROSS= 3 | CP=/bin/cp 4 | RM=-/bin/rm -rf 5 | LN=/bin/ln -s 6 | CFLAGS=-g -Wall -DFF_ENABLE_PROTOCOLBUF 7 | LDFLAGS= -lpthread -lprotobuf 8 | #链接库名 9 | LIB_NAME= 10 | #链接库版本 11 | LIB_VER=1.0.0 12 | #平台 13 | ARCH= 14 | # 二进制目标 15 | BIN=app_rpc 16 | 17 | #源文件目录 18 | SrcDir= . ../../fflib/base ../../fflib/net ../../fflib/rpc 19 | #头文件目录 20 | IncDir= ../../fflib/ ../../lib3party ./ 21 | #连接库目录 22 | LibDir= /usr/local/lib 23 | SRCS=$(foreach dir,$(SrcDir),$(wildcard $(dir)/*.cpp)) 24 | #INCS=$(foreach dir,$(IncDir),$(wildcard $(dir)/*.h)) 25 | INCS=$(foreach dir,$(IncDir),$(addprefix -I,$(dir))) 26 | LINKS=$(foreach dir,$(LibDir),$(addprefix -L,$(dir))) 27 | CFLAGS := $(CFLAGS) $(INCS) 28 | LDFLAGS:= $(LINKS) $(LDFLAGS) 29 | CC=gcc 30 | ARCH=PC 31 | OBJS = $(SRCS:%.cpp=%.o) 32 | .PHONY:all clean 33 | 34 | all:$(BIN) 35 | $(BIN):$(OBJS) 36 | @$(CC) $(CFLAGS) -c echo.pb.cc -o echo.pb.o 37 | g++ -o $(BIN) $(OBJS) echo.pb.o $(LDFLAGS) 38 | @echo -e " OK!\tCompile $@ " 39 | # @$(LN) $(shell pwd)/$(LIB_NAME).$(LIB_VER) /lib/$(LIB_NAME) 40 | 41 | %.o:%.cpp 42 | @echo -e "[$(ARCH)] \t\tCompile $@..." 43 | @$(CC) $(CFLAGS) -c $< -o $@ 44 | 45 | .PHONY: clean 46 | clean: 47 | @echo -e "[$(ARCH)] \tCleaning files..." 48 | @$(RM) $(OBJS) $(BIN) 49 | -------------------------------------------------------------------------------- /example/tutorial/protobuf_test.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/example/tutorial/protobuf_test.h -------------------------------------------------------------------------------- /example/tutorial/thrift-0.9.0.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/example/tutorial/thrift-0.9.0.exe -------------------------------------------------------------------------------- /example/tutorial/thrift.Makefile: -------------------------------------------------------------------------------- 1 | #交叉编译器路径 2 | CROSS= 3 | CP=/bin/cp 4 | RM=-/bin/rm -rf 5 | LN=/bin/ln -s 6 | CFLAGS=-g -Wall -DFF_ENABLE_THRIFT 7 | LDFLAGS= -lpthread 8 | #链接库名 9 | LIB_NAME= 10 | #链接库版本 11 | LIB_VER=1.0.0 12 | #平台 13 | ARCH= 14 | # 二进制目标 15 | BIN=app_rpc 16 | 17 | #源文件目录 18 | SrcDir= . ../../fflib/base ../../fflib/net ../../fflib/rpc 19 | #头文件目录 20 | IncDir= ../../fflib/ ../../lib3party ./ 21 | #连接库目录 22 | LibDir= /usr/local/lib 23 | SRCS=$(foreach dir,$(SrcDir),$(wildcard $(dir)/*.cpp)) 24 | #INCS=$(foreach dir,$(IncDir),$(wildcard $(dir)/*.h)) 25 | INCS=$(foreach dir,$(IncDir),$(addprefix -I,$(dir))) 26 | LINKS=$(foreach dir,$(LibDir),$(addprefix -L,$(dir))) 27 | CFLAGS := $(CFLAGS) $(INCS) 28 | LDFLAGS:= $(LINKS) $(LDFLAGS) 29 | CC=gcc 30 | ARCH=PC 31 | OBJS = $(SRCS:%.cpp=%.o) 32 | .PHONY:all clean 33 | 34 | all:$(BIN) 35 | $(BIN):$(OBJS) 36 | g++ -o $(BIN) $(OBJS) $(LDFLAGS) 37 | @echo -e " OK!\tCompile $@ " 38 | # @$(LN) $(shell pwd)/$(LIB_NAME).$(LIB_VER) /lib/$(LIB_NAME) 39 | 40 | %.o:%.cpp 41 | @echo -e "[$(ARCH)] \t\tCompile $@..." 42 | @$(CC) $(CFLAGS) -c $< -o $@ 43 | 44 | .PHONY: clean 45 | clean: 46 | @echo -e "[$(ARCH)] \tCleaning files..." 47 | @$(RM) $(OBJS) $(BIN) 48 | -------------------------------------------------------------------------------- /example/tutorial/thrift_test.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/example/tutorial/thrift_test.h -------------------------------------------------------------------------------- /fflib/base/arg_helper.h: -------------------------------------------------------------------------------- 1 | #ifndef _ARG_HELPER_H_ 2 | #define _ARG_HELPER_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | #include "base/strtool.h" 10 | 11 | class arg_helper_t 12 | { 13 | public: 14 | arg_helper_t(int argc, char* argv[]) 15 | { 16 | for (int i = 0; i < argc; ++i) 17 | { 18 | m_args.push_back(argv[i]); 19 | } 20 | if (is_enable_option("-f")) 21 | { 22 | load_from_file(get_option_value("-f")); 23 | } 24 | } 25 | arg_helper_t(string arg_str_) 26 | { 27 | vector v; 28 | strtool::split(arg_str_, v, " "); 29 | m_args.insert(m_args.end(), v.begin(), v.end()); 30 | if (is_enable_option("-f")) 31 | { 32 | load_from_file(get_option_value("-f")); 33 | } 34 | } 35 | string get_option(int idx_) const 36 | { 37 | if ((size_t)idx_ >= m_args.size()) 38 | { 39 | return ""; 40 | } 41 | return m_args[idx_]; 42 | } 43 | bool is_enable_option(string opt_) const 44 | { 45 | for (size_t i = 0; i < m_args.size(); ++i) 46 | { 47 | if (opt_ == m_args[i]) 48 | { 49 | return true; 50 | } 51 | } 52 | return false; 53 | } 54 | 55 | string get_option_value(string opt_) const 56 | { 57 | string ret; 58 | for (size_t i = 0; i < m_args.size(); ++i) 59 | { 60 | if (opt_ == m_args[i]) 61 | { 62 | size_t value_idx = ++ i; 63 | if (value_idx >= m_args.size()) 64 | { 65 | return ret; 66 | } 67 | ret = m_args[value_idx]; 68 | return ret; 69 | } 70 | } 71 | return ret; 72 | } 73 | int load_from_file(const string& file_) 74 | { 75 | ifstream inf(file_.c_str()); 76 | string all; 77 | string tmp; 78 | while (inf.eof() == false) 79 | { 80 | if (!getline(inf, tmp)) 81 | { 82 | break; 83 | } 84 | if (tmp.empty() == false && tmp[0] == '#')//!过滤注释 85 | { 86 | continue; 87 | } 88 | //printf("get:%s\n", tmp.c_str()); 89 | //sleep(1); 90 | all += tmp + " "; 91 | tmp.clear(); 92 | } 93 | vector v; 94 | strtool::split(all, v, " "); 95 | m_args.insert(m_args.end(), v.begin(), v.end()); 96 | return 0; 97 | } 98 | private: 99 | vector m_args; 100 | }; 101 | 102 | #endif 103 | 104 | -------------------------------------------------------------------------------- /fflib/base/atomic_op.h: -------------------------------------------------------------------------------- 1 | #ifndef _FF_ATOMIC_H_ 2 | #define _FF_ATOMIC_H_ 3 | 4 | namespace ff { 5 | //! windows.h 6 | //! InterlockedIncrement 7 | //! InterlockedDecrement 8 | 9 | #define ATOMIC_ADD(src_ptr, v) (void)__sync_add_and_fetch(src_ptr, v) 10 | #define ATOMIC_SUB_AND_FETCH(src_ptr, v) __sync_sub_and_fetch(src_ptr, v) 11 | #define ATOMIC_ADD_AND_FETCH(src_ptr, v) __sync_add_and_fetch(src_ptr, v) 12 | #define ATOMIC_FETCH(src_ptr) __sync_add_and_fetch(src_ptr, 0) 13 | #define ATOMIC_SET(src_ptr, v) (void)__sync_bool_compare_and_swap(src_ptr, *(src_ptr), v) 14 | 15 | class ref_count_t 16 | { 17 | typedef volatile long atomic_t; 18 | public: 19 | ref_count_t(): 20 | m_ref_num(0) 21 | {} 22 | ~ref_count_t() 23 | {} 24 | 25 | inline void inc(int n = 1) 26 | { 27 | ATOMIC_ADD(&m_ref_num, n); 28 | } 29 | inline bool dec_and_check_zero(int n = 1) 30 | { 31 | return 0 == ATOMIC_SUB_AND_FETCH(&m_ref_num, n); 32 | } 33 | inline atomic_t inc_and_fetch(int n = 1) 34 | { 35 | return ATOMIC_ADD_AND_FETCH(&m_ref_num, n); 36 | } 37 | inline atomic_t value() 38 | { 39 | return ATOMIC_FETCH(&m_ref_num); 40 | } 41 | 42 | private: 43 | atomic_t m_ref_num; 44 | }; 45 | 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /fflib/base/daemon_tool.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _DAEMON_TOOL_H_ 3 | #define _DAEMON_TOOL_H_ 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | namespace ff 17 | { 18 | class daemon_tool_t 19 | { 20 | public: 21 | static void daemon() 22 | { 23 | daemon(NULL); 24 | } 25 | 26 | static void daemon(const char* uname_) 27 | { 28 | pid_t pid, sid; 29 | 30 | if ((pid = fork()) < 0) 31 | { 32 | printf("daemon fork failed:%s\n", strerror(errno)); 33 | exit(EXIT_FAILURE); 34 | } 35 | else if(pid != 0) 36 | { 37 | exit(EXIT_SUCCESS); 38 | } 39 | 40 | char buffer[1024]; 41 | getcwd(buffer, sizeof(buffer)); 42 | 43 | if(chdir(buffer) == -1) 44 | { 45 | printf("chdir failed:%s", strerror(errno)); 46 | exit(EXIT_FAILURE); 47 | } 48 | 49 | if(uname_ != NULL) 50 | { 51 | int uid = get_uid(uname_); 52 | if(uid == -1) 53 | { 54 | printf("get_uid failed:%s", strerror(errno)); 55 | exit(EXIT_FAILURE); 56 | } 57 | if(setuid(uid) == -1) 58 | { 59 | printf("setuid failed:%s", strerror(errno)); 60 | exit(EXIT_FAILURE); 61 | } 62 | } 63 | 64 | sid = setsid(); 65 | if (sid < 0) 66 | { 67 | printf("daemon setsid failed:%s", strerror(errno)); 68 | exit (EXIT_FAILURE); 69 | } 70 | 71 | umask (022); 72 | 73 | for (int i = getdtablesize() - 1; i >= 0; --i) 74 | { 75 | (void)close(i); 76 | } 77 | 78 | int fd_dev = open("/dev/null", O_RDWR); 79 | (void)dup(fd_dev); 80 | (void)dup(fd_dev); 81 | } 82 | 83 | static int get_uid(const char* uname_) 84 | { 85 | struct passwd *user = NULL; 86 | user = getpwnam(uname_); 87 | if(user == NULL) 88 | { 89 | return -1; 90 | } 91 | return user->pw_uid; 92 | } 93 | }; 94 | 95 | } 96 | #endif 97 | 98 | -------------------------------------------------------------------------------- /fflib/base/obj_pool.h: -------------------------------------------------------------------------------- 1 | #ifndef _OBJ_POOL_H_ 2 | #define _OBJ_POOL_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | namespace ff { 10 | 11 | template 12 | class ff_obj_pool_t 13 | { 14 | public: 15 | ff_obj_pool_t(){ 16 | } 17 | virtual ~ff_obj_pool_t() { 18 | for (typename list::iterator it = m_free.begin(); it != m_free.end(); ++it){ 19 | ::free(*it); 20 | } 21 | m_free.clear(); 22 | } 23 | T* alloc(){ 24 | if (false == m_free.empty()){ 25 | T* pret = m_free.front(); 26 | m_free.pop_front(); 27 | pret = new (pret) T; 28 | return pret; 29 | } 30 | else{ 31 | void* p = ::malloc(sizeof(T)); 32 | T* pret = new (p) T; 33 | return pret; 34 | } 35 | return NULL; 36 | } 37 | void release(T* p){ 38 | p->~T(); 39 | ::memset((void*)p, 0, sizeof(T)); 40 | m_free.push_back(p); 41 | } 42 | 43 | protected: 44 | list m_free; 45 | }; 46 | 47 | 48 | } 49 | 50 | #endif 51 | 52 | //! 53 | -------------------------------------------------------------------------------- /fflib/base/os_tool.h: -------------------------------------------------------------------------------- 1 | #ifndef _FF_OS_TOOL_H_ 2 | #define _FF_OS_TOOL_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | using namespace std; 13 | 14 | namespace ff 15 | { 16 | 17 | struct os_tool_t 18 | { 19 | static int ls(const string& path_, vector& ret_) 20 | { 21 | const char* dir = path_.c_str(); 22 | DIR *dp; 23 | struct dirent *entry; 24 | 25 | if((dp = opendir(dir)) == NULL) { 26 | fprintf(stderr,"cannot open directory: %s\n", dir); 27 | return -1; 28 | } 29 | 30 | while((entry = readdir(dp)) != NULL) { 31 | if(strcmp(".",entry->d_name) == 0 || strcmp("..",entry->d_name) == 0) 32 | continue; 33 | ret_.push_back(entry->d_name); 34 | } 35 | closedir(dp); 36 | return 0; 37 | } 38 | static bool is_dir(const string& name_) 39 | { 40 | struct stat s; 41 | if(lstat(name_.c_str(), &s) < 0){ 42 | return false; 43 | } 44 | return S_ISDIR(s.st_mode); 45 | } 46 | }; 47 | } 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /fflib/base/signal_helper.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SIGNAL_HELPER_H_ 3 | #define _SIGNAL_HELPER_H_ 4 | 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | using namespace std; 11 | 12 | class signal_helper_t 13 | { 14 | public: 15 | static int bloack() 16 | { 17 | sigset_t mask_sig; 18 | 19 | ::sigfillset(&mask_sig); 20 | return ::pthread_sigmask(SIG_BLOCK, &mask_sig, NULL); 21 | } 22 | static int wait(string option_ = "") 23 | { 24 | sigset_t mask_sig; 25 | sigemptyset(&mask_sig); 26 | sigaddset(&mask_sig, SIGINT); 27 | sigaddset(&mask_sig, SIGQUIT); 28 | sigaddset(&mask_sig, SIGTERM); 29 | 30 | int sig_num = 0; 31 | pthread_sigmask(SIG_BLOCK, &mask_sig, 0); 32 | 33 | ::sigwait(&mask_sig, &sig_num); 34 | return sig_num; 35 | } 36 | }; 37 | 38 | #endif 39 | 40 | -------------------------------------------------------------------------------- /fflib/base/singleton.h: -------------------------------------------------------------------------------- 1 | #ifndef _SINGLETON_H_ 2 | #define _SINGLETON_H_ 3 | 4 | #include 5 | #include 6 | 7 | template 8 | class singleton_t 9 | { 10 | public: 11 | static T& instance() 12 | { 13 | pthread_once(&m_ponce, &singleton_t::init); 14 | return *m_instance; 15 | } 16 | 17 | static T* instance_ptr() 18 | { 19 | return m_instance; 20 | } 21 | private: 22 | static void init() 23 | { 24 | m_instance = new T(); 25 | atexit(destroy); 26 | } 27 | static void destroy() 28 | { 29 | if(m_instance) 30 | { 31 | delete m_instance; 32 | m_instance = 0; 33 | } 34 | } 35 | 36 | private: 37 | static T* volatile m_instance; 38 | static pthread_once_t m_ponce; 39 | }; 40 | 41 | template 42 | T* volatile singleton_t::m_instance = NULL; 43 | 44 | template 45 | pthread_once_t singleton_t::m_ponce = PTHREAD_ONCE_INIT; 46 | 47 | #endif 48 | 49 | -------------------------------------------------------------------------------- /fflib/base/strtool.h: -------------------------------------------------------------------------------- 1 | #ifndef _STRTOOL_H_ 2 | #define _STRTOOL_H_ 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | struct strtool 11 | { 12 | static string trim(const string& str) 13 | { 14 | string::size_type pos = str.find_first_not_of(' '); 15 | if (pos == string::npos) 16 | { 17 | return str; 18 | } 19 | string::size_type pos2 = str.find_last_not_of(' '); 20 | if (pos2 != string::npos) 21 | { 22 | return str.substr(pos, pos2 - pos + 1); 23 | } 24 | return str.substr(pos); 25 | } 26 | 27 | static int split(const string& str, vector& ret_, string sep = ",") 28 | { 29 | if (str.empty()) 30 | { 31 | return 0; 32 | } 33 | 34 | string tmp; 35 | string::size_type pos_begin = str.find_first_not_of(sep); 36 | string::size_type comma_pos = 0; 37 | 38 | while (pos_begin != string::npos) 39 | { 40 | comma_pos = str.find(sep, pos_begin); 41 | if (comma_pos != string::npos) 42 | { 43 | tmp = str.substr(pos_begin, comma_pos - pos_begin); 44 | pos_begin = comma_pos + sep.length(); 45 | } 46 | else 47 | { 48 | tmp = str.substr(pos_begin); 49 | pos_begin = comma_pos; 50 | } 51 | 52 | if (!tmp.empty()) 53 | { 54 | ret_.push_back(tmp); 55 | tmp.clear(); 56 | } 57 | } 58 | return 0; 59 | } 60 | 61 | static string replace(const string& str, const string& src, const string& dest) 62 | { 63 | string ret; 64 | 65 | string::size_type pos_begin = 0; 66 | string::size_type pos = str.find(src); 67 | while (pos != string::npos) 68 | { 69 | //cout <<"replacexxx:" << pos_begin <<" " << pos <<"\n"; 70 | ret.append(str.c_str() + pos_begin, pos - pos_begin); 71 | ret += dest; 72 | pos_begin = pos + src.length(); 73 | pos = str.find(src, pos_begin); 74 | } 75 | if (pos_begin < str.length()) 76 | { 77 | ret.append(str.begin() + pos_begin, str.end()); 78 | } 79 | return ret; 80 | } 81 | 82 | size_t utf8_words_num(const char* s_) 83 | { 84 | size_t ret = 0; 85 | const char* p = s_; 86 | for (unsigned char c = (unsigned char)(*p); c != 0; c = (unsigned char)(*p)) 87 | { 88 | ++ret; 89 | if (c <= 127) 90 | { 91 | p += 1; 92 | } 93 | else if (c < 192) 94 | { 95 | p += 2; 96 | } 97 | else if (c < 223) 98 | { 99 | p += 3; 100 | } 101 | else 102 | { 103 | p += 4; 104 | } 105 | } 106 | return ret; 107 | } 108 | }; 109 | 110 | typedef strtool strtool_t; 111 | #endif 112 | 113 | -------------------------------------------------------------------------------- /fflib/base/thread.cpp: -------------------------------------------------------------------------------- 1 | #include "base/thread.h" 2 | 3 | using namespace ff; 4 | 5 | void* thread_t::thread_func(void* p_) 6 | { 7 | task_t* t = (task_t*)p_; 8 | t->run(); 9 | delete t; 10 | return 0; 11 | } 12 | 13 | int thread_t::create_thread(task_t func, int num) 14 | { 15 | for (int i = 0; i < num; ++i) 16 | { 17 | pthread_t ntid; 18 | task_t* t = new task_t(func); 19 | if (0 == ::pthread_create(&ntid, NULL, thread_func, t)) 20 | { 21 | m_tid_list.push_back(ntid); 22 | } 23 | } 24 | return 0; 25 | } 26 | 27 | int thread_t::join() 28 | { 29 | list::iterator it = m_tid_list.begin(); 30 | for (; it != m_tid_list.end(); ++it) 31 | { 32 | pthread_join((*it), NULL); 33 | } 34 | m_tid_list.clear(); 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /fflib/base/thread.h: -------------------------------------------------------------------------------- 1 | #ifndef _THREAD_H_ 2 | #define _THREAD_H_ 3 | 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | #include "base/task_queue_i.h" 9 | #include "base/task_queue_impl.h" 10 | 11 | namespace ff { 12 | 13 | class thread_t 14 | { 15 | static void* thread_func(void* p_); 16 | 17 | public: 18 | int create_thread(task_t func, int num = 1); 19 | int join(); 20 | 21 | private: 22 | list m_tid_list; 23 | }; 24 | 25 | } 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /fflib/base/time_tool.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _FF_TIME_TOOL_H_ 3 | #define _FF_TIME_TOOL_H_ 4 | 5 | #include 6 | #include 7 | #include 8 | #include "time.h" 9 | #include 10 | #include 11 | #include 12 | #include 13 | using namespace std; 14 | 15 | //! 获取特定时间的unix 时间戳 16 | struct time_tool_t 17 | { 18 | static long today_at_zero()//!今日零点时间戳 19 | { 20 | time_t now = ::time(NULL); 21 | tm tm_val = *::localtime(&now); 22 | long ret = (long)now - tm_val.tm_hour*3600 - tm_val.tm_min*60 - tm_val.tm_sec; 23 | return ret; 24 | } 25 | static long next_month()//!下个月开始时间戳 26 | { 27 | time_t now = ::time(NULL); 28 | tm tm_val = *::localtime(&now); 29 | 30 | //! 计算这个月有多少天 31 | static int help_month[] = {31,28,31,30,31,30,31,31,30,31,30,31}; 32 | int month_day_num = help_month[tm_val.tm_mon]; 33 | if (1 == tm_val.tm_mon)//! 检查2月闰月 34 | { 35 | if ((tm_val.tm_year + 1900) % 4 == 0) ++ month_day_num; 36 | } 37 | 38 | long ret = (long)now + (month_day_num - tm_val.tm_mday)*86400 + (23 - tm_val.tm_hour)*3600 + 39 | (59 - tm_val.tm_min)*60 + (60 - tm_val.tm_sec); 40 | return ret; 41 | } 42 | }; 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /fflib/db/db_ops.h: -------------------------------------------------------------------------------- 1 | #ifndef _FF_DB_OPS_H_ 2 | #define _FF_DB_OPS_H_ 3 | 4 | #include 5 | using namespace std; 6 | 7 | namespace ff 8 | { 9 | 10 | class db_each_row_callback_i 11 | { 12 | public: 13 | virtual ~db_each_row_callback_i() {} 14 | virtual void callback(int col_num_, char** col_datas_, char** col_names_, long* col_length_) = 0; 15 | }; 16 | 17 | class db_ops_i 18 | { 19 | public: 20 | virtual ~db_ops_i(){} 21 | 22 | virtual int connect(const string& args_) = 0; 23 | virtual bool is_connected() = 0; 24 | virtual int exe_sql(const string& sql_, db_each_row_callback_i* cb_) = 0; 25 | virtual void close() = 0; 26 | virtual int affect_rows() = 0; 27 | virtual const char* error_msg() = 0; 28 | 29 | virtual int ping() = 0; 30 | virtual void begin_transaction() = 0; 31 | virtual void commit_transaction() = 0; 32 | virtual void rollback_transaction() = 0; 33 | }; 34 | 35 | } 36 | #endif 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /fflib/db/ffdb.h: -------------------------------------------------------------------------------- 1 | 2 | //! 封装db的操作 3 | #ifndef _FFDB_H_ 4 | #define _FFDB_H_ 5 | 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | #include "db/db_ops.h" 11 | 12 | namespace ff 13 | { 14 | 15 | class each_row_common_cb_t: public db_each_row_callback_i 16 | { 17 | public: 18 | each_row_common_cb_t(vector >* data_, vector* col_name_): 19 | m_all_data(data_), 20 | m_col_name(col_name_) 21 | {} 22 | virtual void callback(int col_num_, char** col_datas_, char** col_names_, long* col_length_) 23 | { 24 | (*m_all_data).push_back(vector()); 25 | vector& data = (*m_all_data)[(*m_all_data).size() - 1]; 26 | data.resize(col_num_); 27 | for (int i = 0; i < col_num_; ++i) 28 | { 29 | if (col_datas_[i]) 30 | { 31 | data[i].assign(col_datas_[i], col_length_[i]); 32 | } 33 | } 34 | if (m_col_name && (*m_col_name).empty()) 35 | { 36 | (*m_col_name).resize(col_num_); 37 | for (int i = 0; i < col_num_; ++i) 38 | { 39 | if (col_names_[i]) 40 | (*m_col_name)[i].assign(col_names_[i]); 41 | } 42 | } 43 | } 44 | private: 45 | vector >* m_all_data; 46 | vector* m_col_name; 47 | }; 48 | 49 | class ffdb_t 50 | { 51 | public: 52 | ffdb_t(); 53 | ~ffdb_t(); 54 | 55 | static string escape(const string& src_); 56 | static void dump(vector >& ret_data, vector& col_names_); 57 | 58 | int connect(const string& args_); 59 | bool is_connected(); 60 | void close(); 61 | int affect_rows(); 62 | const char* error_msg(); 63 | 64 | int exe_sql(const string& sql_, db_each_row_callback_i* cb_ = NULL); 65 | int exe_sql(const string& sql_, vector >& ret_data_); 66 | int exe_sql(const string& sql_, vector >& ret_data_, vector& col_names_); 67 | 68 | int ping(); 69 | private: 70 | db_ops_i* m_db_ops; 71 | }; 72 | 73 | } 74 | #endif 75 | 76 | -------------------------------------------------------------------------------- /fflib/db/mysql_ops.h: -------------------------------------------------------------------------------- 1 | #ifndef _MYSQL_OPS_H_ 2 | #define _MYSQL_OPS_H_ 3 | 4 | extern "C"{ 5 | #include 6 | #include 7 | } 8 | 9 | #include 10 | using namespace std; 11 | 12 | #include "db/db_ops.h" 13 | #include "base/lock.h" 14 | 15 | namespace ff 16 | { 17 | 18 | class mysql_ops_t : public db_ops_i 19 | { 20 | static mutex_t g_mutex; 21 | 22 | public: 23 | mysql_ops_t(); 24 | virtual ~mysql_ops_t(); 25 | 26 | virtual int connect(const string& args_); 27 | virtual bool is_connected(); 28 | virtual int exe_sql(const string& sql_, db_each_row_callback_i* cb_); 29 | virtual void close(); 30 | virtual int affect_rows() { return m_affect_rows_num; } 31 | virtual const char* error_msg(); 32 | 33 | virtual void begin_transaction(); 34 | virtual void commit_transaction(); 35 | virtual void rollback_transaction(); 36 | virtual int ping(); 37 | 38 | private: 39 | void clear_env(); 40 | private: 41 | string m_host_arg; 42 | MYSQL m_mysql; 43 | bool m_connected; 44 | string m_error; 45 | int m_affect_rows_num; 46 | 47 | }; 48 | } 49 | #endif 50 | 51 | -------------------------------------------------------------------------------- /fflib/db/sqlite_ops.cpp: -------------------------------------------------------------------------------- 1 | #ifdef FF_ENABLE_SQLITE 2 | 3 | #include "db/sqlite_ops.h" 4 | #include 5 | 6 | using namespace ff; 7 | 8 | sqlite_ops_t::sqlite_ops_t(): 9 | m_sqlite(NULL), 10 | m_connected(false), 11 | m_affect_rows_num(0) 12 | { 13 | m_callback_info.obj = this; 14 | } 15 | sqlite_ops_t::~sqlite_ops_t() 16 | { 17 | close(); 18 | } 19 | void sqlite_ops_t::clear_env() 20 | { 21 | m_affect_rows_num = 0; 22 | m_error.clear(); 23 | } 24 | 25 | int sqlite_ops_t::connect(const string& args_) 26 | { 27 | clear_env(); 28 | close(); 29 | if (SQLITE_OK != ::sqlite3_open(args_.c_str(), &m_sqlite)) 30 | { 31 | m_connected = false; 32 | m_error = sqlite3_errmsg(m_sqlite); 33 | return -1; 34 | } 35 | m_connected = true; 36 | return 0; 37 | } 38 | 39 | bool sqlite_ops_t::is_connected() 40 | { 41 | return m_connected; 42 | } 43 | 44 | static int default_callback(void* p_, int col_num_, char** col_datas_, char** col_names_) 45 | { 46 | sqlite_ops_t::callback_info_t* info = (sqlite_ops_t::callback_info_t*)(p_); 47 | info->obj->inc_affect_row_num(); 48 | if (info->callback) 49 | { 50 | for (int i = 0; i < col_num_; ++i) 51 | { 52 | if (col_datas_[i]) 53 | info->length_buff.push_back(::strlen(col_datas_[i])); 54 | else 55 | info->length_buff.push_back(0); 56 | } 57 | long* ptr_length = col_num_ == 0? NULL: &(info->length_buff[0]); 58 | info->callback->callback(col_num_, col_datas_, col_names_, ptr_length); 59 | info->length_buff.clear(); 60 | } 61 | return 0; 62 | } 63 | 64 | int sqlite_ops_t::exe_sql(const string& sql_, db_each_row_callback_i* cb_) 65 | { 66 | char* msg = NULL; 67 | clear_env(); 68 | m_callback_info.callback = cb_; 69 | if (::sqlite3_exec(m_sqlite, sql_.c_str(), &default_callback, &m_callback_info, &msg)) 70 | { 71 | if (msg) 72 | { 73 | m_error = msg; 74 | ::sqlite3_free(msg); 75 | } 76 | return -1; 77 | } 78 | return 0; 79 | } 80 | void sqlite_ops_t::close() 81 | { 82 | if (m_sqlite) 83 | { 84 | ::sqlite3_close(m_sqlite); 85 | m_sqlite = NULL; 86 | } 87 | } 88 | const char* sqlite_ops_t::error_msg() 89 | { 90 | return m_error.c_str(); 91 | } 92 | 93 | 94 | void sqlite_ops_t::begin_transaction() 95 | { 96 | exe_sql("begin transaction", NULL); 97 | } 98 | 99 | void sqlite_ops_t::commit_transaction() 100 | { 101 | exe_sql("commit transaction", NULL); 102 | } 103 | 104 | void sqlite_ops_t::rollback_transaction() 105 | { 106 | exe_sql("rollback transaction", NULL); 107 | } 108 | 109 | #endif 110 | -------------------------------------------------------------------------------- /fflib/db/sqlite_ops.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _FF_SQLITE_OPS_H_ 3 | #define _FF_SQLITE_OPS_H_ 4 | 5 | #include "db/db_ops.h" 6 | #include "db/sqlite3.h" 7 | 8 | #include 9 | using namespace std; 10 | 11 | namespace ff 12 | { 13 | 14 | class sqlite_ops_t : public db_ops_i 15 | { 16 | public: 17 | struct callback_info_t 18 | { 19 | callback_info_t(sqlite_ops_t* p = NULL): 20 | obj(p), 21 | callback(NULL) 22 | {} 23 | sqlite_ops_t* obj; 24 | db_each_row_callback_i* callback; 25 | vector length_buff; 26 | }; 27 | public: 28 | sqlite_ops_t(); 29 | virtual ~sqlite_ops_t(); 30 | 31 | virtual int connect(const string& args_); 32 | virtual bool is_connected(); 33 | virtual int exe_sql(const string& sql_, db_each_row_callback_i* cb_); 34 | virtual void close(); 35 | virtual int affect_rows() { return m_affect_rows_num; } 36 | virtual const char* error_msg(); 37 | 38 | void inc_affect_row_num() { ++ m_affect_rows_num; } 39 | 40 | 41 | virtual void begin_transaction(); 42 | virtual void commit_transaction(); 43 | virtual void rollback_transaction(); 44 | virtual int ping() { return 0; } 45 | private: 46 | void clear_env(); 47 | private: 48 | sqlite3* m_sqlite; 49 | bool m_connected; 50 | string m_error; 51 | int m_affect_rows_num; 52 | callback_info_t m_callback_info; 53 | }; 54 | } 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /fflib/lua/fflua.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/fflib/lua/fflua.h -------------------------------------------------------------------------------- /fflib/net/acceptor_i.h: -------------------------------------------------------------------------------- 1 | #ifndef _ACCEPTOR_I_ 2 | #define _ACCEPTOR_I_ 3 | 4 | #include 5 | using namespace std; 6 | 7 | #include "netbase.h" 8 | 9 | namespace ff { 10 | 11 | class acceptor_i: public fd_i 12 | { 13 | public: 14 | virtual ~acceptor_i(){} 15 | virtual int open(const string& address_) = 0; 16 | 17 | int handle_epoll_write(){ return -1; } 18 | }; 19 | 20 | } 21 | #endif 22 | -------------------------------------------------------------------------------- /fflib/net/acceptor_impl.h: -------------------------------------------------------------------------------- 1 | #ifndef _ACCEPTOR_IMPL_H_ 2 | #define _ACCEPTOR_IMPL_H_ 3 | 4 | #include "net/acceptor_i.h" 5 | 6 | namespace ff { 7 | 8 | #define LISTEN_BACKLOG 5 9 | 10 | class epoll_i; 11 | class socket_i; 12 | class msg_handler_i; 13 | class task_queue_pool_t; 14 | 15 | class acceptor_impl_t: public acceptor_i 16 | { 17 | public: 18 | acceptor_impl_t(epoll_i*, msg_handler_i*, task_queue_pool_t* tq_); 19 | ~acceptor_impl_t(); 20 | int open(const string& address_); 21 | void close(); 22 | 23 | int socket() {return m_listen_fd;} 24 | int handle_epoll_read(); 25 | int handle_epoll_del() ; 26 | 27 | protected: 28 | virtual socket_i* create_socket(int); 29 | 30 | protected: 31 | int m_listen_fd; 32 | epoll_i* m_epoll; 33 | msg_handler_i* m_msg_handler; 34 | task_queue_pool_t* m_tq; 35 | }; 36 | 37 | } 38 | 39 | #endif 40 | 41 | -------------------------------------------------------------------------------- /fflib/net/codec.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "net/codec.h" 3 | 4 | #include 5 | using namespace ff; 6 | 7 | void ffthrift_codec_tool_t::write(msg_i& msg, ::apache::thrift::protocol::TProtocol* iprot) 8 | { 9 | string tmp = msg.encode_data(); 10 | ::apache::thrift::protocol::TTransport* trans_ = iprot->getTransport(); 11 | trans_->write((const uint8_t*)tmp.c_str(), tmp.size()); 12 | } 13 | void ffthrift_codec_tool_t::read(msg_i& msg, ::apache::thrift::protocol::TProtocol* iprot) 14 | { 15 | ::apache::thrift::protocol::TTransport* trans_ = iprot->getTransport(); 16 | apache::thrift::transport::FFTMemoryBuffer* pmem = (apache::thrift::transport::FFTMemoryBuffer*)trans_; 17 | msg.decode_data(pmem->get_rbuff()); 18 | } 19 | 20 | -------------------------------------------------------------------------------- /fflib/net/common_socket_controller.cpp: -------------------------------------------------------------------------------- 1 | #include "net/common_socket_controller.h" 2 | #include "net/socket_i.h" 3 | #include "base/strtool.h" 4 | #include "base/task_queue_impl.h" 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | using namespace std; 12 | 13 | using namespace ff; 14 | 15 | common_socket_controller_t::common_socket_controller_t(msg_handler_ptr_t msg_handler_): 16 | m_msg_handler(msg_handler_), 17 | m_have_recv_size(0) 18 | { 19 | } 20 | 21 | common_socket_controller_t::~common_socket_controller_t() 22 | { 23 | } 24 | 25 | //! when socket broken(whenever), this function will be called 26 | //! this func just callback logic layer to process this event 27 | //! each socket broken event only can happen once 28 | //! logic layer has responsibily to deconstruct the socket object 29 | int common_socket_controller_t::handle_error(socket_i* sp_) 30 | { 31 | if (m_msg_handler->get_tq_ptr()){ 32 | m_msg_handler->get_tq_ptr()->produce(task_binder_t::gen(&msg_handler_i::handle_broken, m_msg_handler, sp_)); 33 | } 34 | else{ 35 | m_msg_handler->handle_broken(sp_); 36 | } 37 | return 0; 38 | } 39 | 40 | int common_socket_controller_t::handle_read(socket_i* sp_, char* buff, size_t len) 41 | { 42 | size_t left_len = len; 43 | size_t tmp = 0; 44 | 45 | while (left_len > 0) 46 | { 47 | if (false == m_message.have_recv_head(m_have_recv_size)) 48 | { 49 | tmp = m_message.append_head(m_have_recv_size, buff, left_len); 50 | 51 | m_have_recv_size += tmp; 52 | left_len -= tmp; 53 | buff += tmp; 54 | } 55 | 56 | tmp = m_message.append_msg(buff, left_len); 57 | m_have_recv_size += tmp; 58 | left_len -= tmp; 59 | buff += tmp; 60 | 61 | if (m_message.get_body().size() == m_message.size()) 62 | { 63 | if (m_msg_handler->get_tq_ptr()){ 64 | m_msg_handler->get_tq_ptr()->produce(task_binder_t::gen(&msg_handler_i::handle_msg, 65 | m_msg_handler, m_message, sp_)); 66 | } 67 | else{ 68 | m_msg_handler->handle_msg(m_message, sp_); 69 | } 70 | m_have_recv_size = 0; 71 | m_message.clear(); 72 | } 73 | } 74 | 75 | return 0; 76 | } 77 | 78 | //! 当数据全部发送完毕后,此函数会被回调 79 | int common_socket_controller_t::handle_write_completed(socket_i* sp_) 80 | { 81 | return 0; 82 | } 83 | 84 | int common_socket_controller_t::check_pre_send(socket_i* sp_, ff_buffer_t* buff_) 85 | { 86 | if (sp_->socket() < 0) 87 | { 88 | return -1; 89 | } 90 | return 0; 91 | } 92 | -------------------------------------------------------------------------------- /fflib/net/common_socket_controller.h: -------------------------------------------------------------------------------- 1 | #ifndef _COMMON_SOCKET_CONTROLLER_H_ 2 | #define _COMMON_SOCKET_CONTROLLER_H_ 3 | 4 | #include 5 | using namespace std; 6 | 7 | #include "net/socket_controller_i.h" 8 | #include "net/message.h" 9 | #include "net/msg_handler_i.h" 10 | 11 | namespace ff { 12 | 13 | class socket_i; 14 | 15 | class common_socket_controller_t: public socket_controller_i 16 | { 17 | public: 18 | common_socket_controller_t(msg_handler_ptr_t msg_handler_); 19 | ~common_socket_controller_t(); 20 | virtual int handle_error(socket_i*); 21 | virtual int handle_read(socket_i*, char* buff, size_t len); 22 | virtual int handle_write_completed(socket_i*); 23 | 24 | virtual int check_pre_send(socket_i*, ff_buffer_t*); 25 | 26 | protected: 27 | msg_handler_ptr_t m_msg_handler; 28 | size_t m_have_recv_size; 29 | message_t m_message; 30 | }; 31 | 32 | } 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /fflib/net/connector.h: -------------------------------------------------------------------------------- 1 | 2 | //!  连接器 3 | #ifndef _CONNECTOR_H_ 4 | #define _CONNECTOR_H_ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "net/socket_impl.h" 16 | #include "base/strtool.h" 17 | #include "net/msg_handler_i.h" 18 | #include "net/common_socket_controller.h" 19 | 20 | namespace ff { 21 | 22 | class connector_t 23 | { 24 | public: 25 | static socket_ptr_t connect(const string& host_, epoll_i* e_, msg_handler_i* msg_handler_, task_queue_i* tq_) 26 | { 27 | socket_ptr_t ret = NULL; 28 | //! example tcp://192.168.1.1:1024 29 | vector vt; 30 | strtool::split(host_, vt, "://"); 31 | if (vt.size() != 2) return NULL; 32 | 33 | vector vt2; 34 | strtool::split(vt[1], vt2, ":"); 35 | if (vt2.size() != 2) return NULL; 36 | if (vt2[0] == "*") 37 | { 38 | vt2[0] = "127.0.0.1"; 39 | } 40 | int s; 41 | struct sockaddr_in addr; 42 | 43 | if((s = socket(AF_INET,SOCK_STREAM,0)) < 0) 44 | { 45 | perror("socket"); 46 | return ret; 47 | } 48 | /* 填写sockaddr_in结构*/ 49 | bzero(&addr,sizeof(addr)); 50 | addr.sin_family = AF_INET; 51 | addr.sin_port = htons(atoi(vt2[1].c_str())); 52 | addr.sin_addr.s_addr = inet_addr(vt2[0].c_str()); 53 | /* 尝试连线*/ 54 | if(::connect(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) 55 | { 56 | perror("connect"); 57 | return ret; 58 | } 59 | 60 | ret = new socket_impl_t(e_, new common_socket_controller_t(msg_handler_), s, tq_); 61 | ret->open(); 62 | return ret; 63 | } 64 | 65 | }; 66 | 67 | } 68 | #endif 69 | -------------------------------------------------------------------------------- /fflib/net/epoll_i.h: -------------------------------------------------------------------------------- 1 | #ifndef _EPOLL_I_ 2 | #define _EPOLL_I_ 3 | 4 | #include "net/netbase.h" 5 | namespace ff { 6 | 7 | 8 | class epoll_i: public io_demultiplexer_i 9 | { 10 | }; 11 | } 12 | #endif 13 | -------------------------------------------------------------------------------- /fflib/net/epoll_impl.h: -------------------------------------------------------------------------------- 1 | #ifndef _EPOLL_IMPL_H_ 2 | #define _EPOLL_IMPL_H_ 3 | 4 | #include 5 | using namespace std; 6 | 7 | #include "net/epoll_i.h" 8 | #include "base/task_queue_i.h" 9 | #include "base/lock.h" 10 | 11 | namespace ff { 12 | 13 | #define CREATE_EPOLL_SIZE 4096 14 | #define EPOLL_EVENTS_SIZE 128 15 | //! 100 ms 16 | #define EPOLL_WAIT_TIME -1 17 | 18 | class epoll_impl_t: public epoll_i 19 | { 20 | public: 21 | epoll_impl_t(); 22 | ~epoll_impl_t(); 23 | 24 | virtual int event_loop(); 25 | virtual int close(); 26 | virtual int register_fd(fd_i*); 27 | virtual int unregister_fd(fd_i*); 28 | virtual int mod_fd(fd_i*); 29 | 30 | int interupt_loop();//! 中断事件循环 31 | protected: 32 | void fd_del_callback(); 33 | 34 | private: 35 | volatile bool m_running; 36 | int m_efd; 37 | task_queue_i* m_task_queue; 38 | int m_interupt_sockets[2]; 39 | //! 待销毁的error socket 40 | list m_error_fd_set; 41 | mutex_t m_mutex; 42 | }; 43 | 44 | } 45 | #endif 46 | -------------------------------------------------------------------------------- /fflib/net/gateway_acceptor.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "net/gateway_acceptor.h" 3 | #include "net/socket_impl.h" 4 | #include "net/gateway_socket_controller.h" 5 | 6 | using namespace ff; 7 | 8 | gateway_acceptor_t::gateway_acceptor_t(epoll_i* e_, msg_handler_i* mh_, task_queue_pool_t* tq_): 9 | acceptor_impl_t(e_, mh_, tq_) 10 | { 11 | 12 | } 13 | 14 | gateway_acceptor_t::~gateway_acceptor_t() 15 | { 16 | 17 | } 18 | 19 | int gateway_acceptor_t::open(const string& args_) 20 | { 21 | arg_helper_t arg_helper(args_); 22 | m_net_stat.start(arg_helper); 23 | 24 | return acceptor_impl_t::open(arg_helper.get_option_value("-gate_listen")); 25 | } 26 | 27 | int gateway_acceptor_t::open(arg_helper_t& arg_helper) 28 | { 29 | m_net_stat.start(arg_helper); 30 | return acceptor_impl_t::open(arg_helper.get_option_value("-gate_listen")); 31 | } 32 | socket_i* gateway_acceptor_t::create_socket(int new_fd_) 33 | { 34 | return new socket_impl_t(m_epoll, new gateway_socket_controller_t(m_msg_handler, &m_net_stat), new_fd_, m_tq->alloc(new_fd_)); 35 | } 36 | -------------------------------------------------------------------------------- /fflib/net/gateway_acceptor.h: -------------------------------------------------------------------------------- 1 | #ifndef _GATEWAY_ACCEPTOR_H_ 2 | #define _GATEWAY_ACCEPTOR_H_ 3 | 4 | #include "net/acceptor_impl.h" 5 | #include "net/common_socket_controller.h" 6 | #include "net/net_stat.h" 7 | #include "base/arg_helper.h" 8 | 9 | namespace ff { 10 | 11 | class gateway_acceptor_t: public acceptor_impl_t 12 | { 13 | public: 14 | gateway_acceptor_t(epoll_i*, msg_handler_i*, task_queue_pool_t* tq_); 15 | ~gateway_acceptor_t(); 16 | 17 | int open(const string& address_); 18 | int open(arg_helper_t& arg_helper); 19 | 20 | protected: 21 | virtual socket_i* create_socket(int new_fd_); 22 | 23 | private: 24 | //! data field 25 | net_stat_t m_net_stat; 26 | }; 27 | 28 | } 29 | #endif 30 | -------------------------------------------------------------------------------- /fflib/net/gateway_socket_controller.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "net/gateway_socket_controller.h" 3 | #include "net/net_stat.h" 4 | #include "base/log.h" 5 | 6 | #include 7 | using namespace ff; 8 | #define FFNET "FFNET" 9 | 10 | gateway_socket_controller_t::gateway_socket_controller_t(msg_handler_ptr_t msg_handler_, net_stat_t* ns_): 11 | common_socket_controller_t(msg_handler_), 12 | m_first_pkg(true), 13 | m_crossfile_req(false), 14 | m_net_stat(ns_), 15 | m_last_update_tm(0) 16 | { 17 | 18 | } 19 | 20 | gateway_socket_controller_t::~gateway_socket_controller_t() 21 | { 22 | 23 | } 24 | 25 | int gateway_socket_controller_t::handle_open(socket_i* s_) 26 | { 27 | m_last_update_tm = m_net_stat->get_heartbeat().tick(); 28 | m_net_stat->get_heartbeat().add(s_); 29 | return 0; 30 | } 31 | 32 | int gateway_socket_controller_t::handle_read(socket_i* s_, char* buff, size_t len) 33 | { 34 | LOGTRACE((FFNET, "gateway_socket_controller_t::handle_read begin len<%u>", len)); 35 | if (m_first_pkg) 36 | { 37 | m_first_pkg = false; 38 | const char* cross_file_req = ""; 39 | size_t tmp = len > 22? 22: len; 40 | size_t i = 0; 41 | for (; i < tmp; ++i) 42 | { 43 | if (buff[i] != cross_file_req[i]) 44 | { 45 | break; 46 | } 47 | } 48 | if (i == tmp) 49 | { 50 | LOGINFO((FFNET, "gateway_socket_controller_t::handle_read begin crossfile len<%u>", len)); 51 | m_crossfile_req = true; 52 | string ret = ""; 53 | ret.append("\0", 1); 54 | s_->async_send(ret); 55 | } 56 | } 57 | if (m_crossfile_req) 58 | { 59 | return 0; 60 | } 61 | common_socket_controller_t::handle_read(s_, buff, len); 62 | 63 | //! 判断消息包是否超过限制 64 | 65 | if (true == m_message.have_recv_head(m_have_recv_size) && m_message.size() > (size_t)m_net_stat->get_max_packet_size()) 66 | { 67 | s_->close(); 68 | } 69 | 70 | //! 更新心跳 71 | if (m_last_update_tm != m_net_stat->get_heartbeat().tick()) 72 | { 73 | m_last_update_tm = m_net_stat->get_heartbeat().tick(); 74 | m_net_stat->get_heartbeat().update(s_); 75 | } 76 | 77 | LOGTRACE((FFNET, "gateway_socket_controller_t::handle_read end msg size<%u>", m_message.size())); 78 | return 0; 79 | } 80 | 81 | int gateway_socket_controller_t::handle_error(socket_i* s_) 82 | { 83 | m_net_stat->get_heartbeat().del(s_); 84 | common_socket_controller_t::handle_error(s_); 85 | return 0; 86 | } 87 | -------------------------------------------------------------------------------- /fflib/net/gateway_socket_controller.h: -------------------------------------------------------------------------------- 1 | #ifndef _GATEWAY_SOCKET_CONTROLLER_H_ 2 | #define _GATEWAY_SOCKET_CONTROLLER_H_ 3 | 4 | #include "net/common_socket_controller.h" 5 | 6 | namespace ff { 7 | 8 | class net_stat_t; 9 | 10 | class gateway_socket_controller_t: public common_socket_controller_t 11 | { 12 | public: 13 | gateway_socket_controller_t(msg_handler_ptr_t msg_handler_, net_stat_t*); 14 | ~gateway_socket_controller_t(); 15 | 16 | virtual int handle_open(socket_i*); 17 | virtual int handle_read(socket_i*, char* buff, size_t len); 18 | virtual int handle_error(socket_i*); 19 | 20 | private: 21 | bool m_first_pkg;//! first packet, need to check cross file 22 | bool m_crossfile_req;//! 23 | net_stat_t* m_net_stat; 24 | time_t m_last_update_tm; 25 | }; 26 | 27 | } 28 | #endif 29 | -------------------------------------------------------------------------------- /fflib/net/http_acceptor.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "net/http_acceptor.h" 3 | #include "net/socket_impl.h" 4 | #include "net/text_socket_controller_impl.h" 5 | #include "base/arg_helper.h" 6 | 7 | using namespace ff; 8 | 9 | http_acceptor_t::http_acceptor_t(epoll_i* e_, msg_handler_i* mh_, task_queue_pool_t* tq_): 10 | acceptor_impl_t(e_, mh_, tq_) 11 | { 12 | 13 | } 14 | 15 | http_acceptor_t::~http_acceptor_t() 16 | { 17 | 18 | } 19 | 20 | socket_i* http_acceptor_t::create_socket(int new_fd_) 21 | { 22 | return new socket_impl_t(m_epoll, new text_socket_controller_impl_t(m_msg_handler), new_fd_, m_tq->alloc(new_fd_)); 23 | } 24 | -------------------------------------------------------------------------------- /fflib/net/http_acceptor.h: -------------------------------------------------------------------------------- 1 | #ifndef _HTTP_ACCEPTOR_H_ 2 | #define _HTTP_ACCEPTOR_H_ 3 | 4 | #include "net/acceptor_impl.h" 5 | #include "net/common_socket_controller.h" 6 | #include "net/net_stat.h" 7 | 8 | namespace ff { 9 | 10 | class http_acceptor_t: public acceptor_impl_t 11 | { 12 | public: 13 | http_acceptor_t(epoll_i*, msg_handler_i*, task_queue_pool_t* tq_); 14 | ~http_acceptor_t(); 15 | 16 | protected: 17 | virtual socket_i* create_socket(int new_fd_); 18 | 19 | private: 20 | }; 21 | 22 | } 23 | #endif 24 | -------------------------------------------------------------------------------- /fflib/net/message.h: -------------------------------------------------------------------------------- 1 | #ifndef _MESSAGE_H_ 2 | #define _MESSAGE_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | #include 9 | namespace ff { 10 | 11 | struct message_head_t 12 | { 13 | message_head_t(): 14 | size(0), 15 | cmd(0), 16 | flag(0) 17 | {} 18 | explicit message_head_t(uint16_t cmd_): 19 | size(0), 20 | cmd(cmd_), 21 | flag(0) 22 | {} 23 | void hton() 24 | { 25 | size = ::htonl(size); 26 | cmd = ::htons(cmd); 27 | flag = ::htons(flag); 28 | } 29 | void ntoh() 30 | { 31 | size = ::ntohl(size); 32 | cmd = ::ntohs(cmd); 33 | flag = ::ntohs(flag); 34 | } 35 | uint32_t size; 36 | uint16_t cmd; 37 | uint16_t flag; 38 | }; 39 | 40 | class message_t 41 | { 42 | public: 43 | message_t() 44 | { 45 | } 46 | 47 | uint16_t get_cmd() const { return m_head.cmd; } 48 | const string& get_body() const { return m_body;} 49 | size_t size() const { return m_head.size; } 50 | uint16_t get_flag() const { return m_head.flag; } 51 | 52 | size_t append_head(size_t index_, char* buff, size_t len) 53 | { 54 | size_t will_append = sizeof(m_head) - index_; 55 | if (will_append > len) 56 | { 57 | will_append = len; 58 | ::memcpy((char*)&m_head + index_, buff, will_append); 59 | } 60 | else 61 | { 62 | ::memcpy((char*)&m_head + index_, buff, will_append); 63 | m_head.ntoh(); 64 | } 65 | return will_append; 66 | } 67 | size_t append_msg(char* buff, size_t len) 68 | { 69 | size_t will_append = m_head.size - m_body.size(); 70 | if (will_append > len) will_append = len; 71 | m_body.append(buff, will_append); 72 | return will_append; 73 | } 74 | void clear() 75 | { 76 | ::memset(&m_head, 0, sizeof(m_head)); 77 | m_body.clear(); 78 | } 79 | void append_to_body(const char* buff, size_t len) 80 | { 81 | m_body.append(buff, len); 82 | } 83 | //! for parse 84 | bool have_recv_head(size_t have_recv_size_) { return have_recv_size_ >= sizeof(message_head_t);} 85 | private: 86 | message_head_t m_head; 87 | string m_body; 88 | }; 89 | 90 | } 91 | #endif 92 | -------------------------------------------------------------------------------- /fflib/net/msg_handler_i.h: -------------------------------------------------------------------------------- 1 | #ifndef _MSG_HANDLER_XX_H_ 2 | #define _MSG_HANDLER_XX_H_ 3 | 4 | #include "net/message.h" 5 | #include "net/socket_i.h" 6 | 7 | namespace ff { 8 | class task_queue_i; 9 | 10 | class msg_handler_i 11 | { 12 | public: 13 | virtual ~msg_handler_i() {} ; 14 | 15 | virtual int handle_broken(socket_ptr_t sock_) = 0; 16 | virtual int handle_msg(const message_t& msg_, socket_ptr_t sock_) = 0; 17 | 18 | virtual task_queue_i* get_tq_ptr() = 0; 19 | }; 20 | 21 | typedef msg_handler_i* msg_handler_ptr_t; 22 | } 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /fflib/net/msg_sender.h: -------------------------------------------------------------------------------- 1 | //! 消息发送器 2 | 3 | #ifndef _MSG_SENDER_H_ 4 | #define _MSG_SENDER_H_ 5 | 6 | namespace ff { 7 | 8 | #include "net/socket_i.h" 9 | #include "net/message.h" 10 | #include "net/codec.h" 11 | //! #include "zlib_util.h" 12 | 13 | class msg_sender_t 14 | { 15 | public: 16 | static void send(socket_ptr_t socket_ptr_, uint16_t cmd_, const string& str_) 17 | { 18 | if (socket_ptr_) 19 | { 20 | message_head_t h(cmd_); 21 | h.size = str_.size(); 22 | h.hton(); 23 | string dest((const char*)&h, sizeof(h)); 24 | dest += str_; 25 | socket_ptr_->async_send(dest); 26 | } 27 | } 28 | static void send(socket_ptr_t socket_ptr_, uint16_t cmd_, codec_i& msg_) 29 | { 30 | if (socket_ptr_) 31 | { 32 | string body = msg_.encode_data(); 33 | message_head_t h(cmd_); 34 | h.size = body.size(); 35 | h.hton(); 36 | string dest((const char*)&h, sizeof(h)); 37 | dest += body; 38 | 39 | socket_ptr_->async_send(dest); 40 | } 41 | } 42 | static void send(socket_ptr_t socket_ptr_, const string& str_) 43 | { 44 | if (socket_ptr_) 45 | { 46 | socket_ptr_->async_send(str_); 47 | } 48 | } 49 | static void send_to_client(socket_ptr_t socket_ptr_, codec_i& msg_) 50 | { 51 | if (socket_ptr_) 52 | { 53 | string body = msg_.encode_data(); 54 | message_head_t h(0); 55 | h.size = body.size(); 56 | h.hton(); 57 | string dest((const char*)&h, sizeof(h)); 58 | dest += body; 59 | socket_ptr_->async_send(body); 60 | } 61 | } 62 | }; 63 | 64 | } 65 | #endif 66 | -------------------------------------------------------------------------------- /fflib/net/net_stat.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "net/net_stat.h" 3 | using namespace ff; 4 | 5 | net_stat_t::net_stat_t(): 6 | m_timer_service(NULL), 7 | m_max_packet_size(1000*1000) 8 | { 9 | } 10 | 11 | net_stat_t::~net_stat_t() 12 | { 13 | if (m_timer_service) 14 | { 15 | delete m_timer_service; 16 | m_timer_service = NULL; 17 | } 18 | } 19 | 20 | static void timer_close(socket_ptr_t s_) 21 | { 22 | s_->close(); 23 | } 24 | 25 | static void timer_check(void* p_) 26 | { 27 | ((net_stat_t*)p_)->handle_timer_check(); 28 | } 29 | 30 | int net_stat_t::start(arg_helper_t& arg_helper_) 31 | { 32 | if (arg_helper_.is_enable_option("-max_packet_size")) 33 | { 34 | m_max_packet_size = ::atoi(arg_helper_.get_option_value("-max_packet_size").c_str()); 35 | } 36 | 37 | m_heartbeat.set_option(arg_helper_, timer_close); 38 | 39 | m_timer_service = new timer_service_t(); 40 | 41 | m_timer_service->timer_callback(m_heartbeat.timeout(), task_t(&timer_check, (void*)this)); 42 | return 0; 43 | } 44 | 45 | void net_stat_t::handle_timer_check() 46 | { 47 | m_heartbeat.timer_check(); 48 | if (m_timer_service) 49 | { 50 | m_timer_service->timer_callback(m_heartbeat.timeout(), task_t(&timer_check, (void*)this)); 51 | } 52 | } 53 | 54 | int net_stat_t::stop() 55 | { 56 | if (m_timer_service) 57 | { 58 | delete m_timer_service; 59 | m_timer_service = NULL; 60 | } 61 | return 0; 62 | } 63 | 64 | -------------------------------------------------------------------------------- /fflib/net/net_stat.h: -------------------------------------------------------------------------------- 1 | #ifndef _NET_STAT_H_ 2 | #define _NET_STAT_H_ 3 | 4 | #include "net/socket_i.h" 5 | #include "base/arg_helper.h" 6 | #include "base/timer_service.h" 7 | #include "base_heartbeat.h" 8 | 9 | #include 10 | #include 11 | using namespace std; 12 | 13 | namespace ff { 14 | 15 | class net_stat_t 16 | { 17 | public: 18 | net_stat_t(); 19 | ~net_stat_t(); 20 | 21 | int start(arg_helper_t& arg_helper_); 22 | int stop(); 23 | 24 | //! 最大消息包大小 25 | int get_max_packet_size() const { return m_max_packet_size; } 26 | 27 | //! 获取心跳模块引用 28 | base_heartbeat_t& get_heartbeat() { return m_heartbeat;} 29 | 30 | //! 处理timer 回调 31 | void handle_timer_check(); 32 | private: 33 | timer_service_t* m_timer_service; 34 | int m_max_packet_size; 35 | base_heartbeat_t m_heartbeat; 36 | }; 37 | 38 | } 39 | #endif 40 | -------------------------------------------------------------------------------- /fflib/net/netbase.h: -------------------------------------------------------------------------------- 1 | #ifndef _NET_BASE_H_ 2 | #define _NET_BASE_H_ 3 | 4 | namespace ff { 5 | 6 | //! 文件描述符相关接口 7 | typedef int socket_fd_t; 8 | class fd_i 9 | { 10 | public: 11 | virtual ~fd_i(){} 12 | 13 | virtual socket_fd_t socket() = 0; 14 | virtual int handle_epoll_read() = 0; 15 | virtual int handle_epoll_write() = 0; 16 | virtual int handle_epoll_del() = 0; 17 | 18 | virtual void close() = 0; 19 | }; 20 | 21 | //! 事件分发器 22 | class io_demultiplexer_i 23 | { 24 | public: 25 | virtual ~io_demultiplexer_i(){} 26 | 27 | virtual int event_loop() = 0; 28 | virtual int close() = 0; 29 | virtual int register_fd(fd_i*) = 0; 30 | virtual int unregister_fd(fd_i*) = 0; 31 | virtual int mod_fd(fd_i*) = 0; 32 | }; 33 | 34 | //typedef fd_i epoll_fd_i; 35 | } 36 | 37 | #endif 38 | 39 | 40 | -------------------------------------------------------------------------------- /fflib/net/socket_controller_i.h: -------------------------------------------------------------------------------- 1 | #ifndef _SOCKET_CONTROLLER_I_ 2 | #define _SOCKET_CONTROLLER_I_ 3 | 4 | #include 5 | using namespace std; 6 | 7 | namespace ff { 8 | 9 | class socket_i; 10 | class ff_buffer_t; 11 | 12 | class socket_controller_i 13 | { 14 | public: 15 | virtual ~socket_controller_i(){} 16 | 17 | virtual int handle_open(socket_i*) {return 0;} 18 | virtual int check_pre_send(socket_i*, ff_buffer_t*) {return 0;} 19 | 20 | virtual int handle_error(socket_i*) = 0; 21 | virtual int handle_read(socket_i*, char* buff, size_t len) = 0; 22 | virtual int handle_write_completed(socket_i*) {return 0;} 23 | 24 | }; 25 | 26 | } 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /fflib/net/socket_i.h: -------------------------------------------------------------------------------- 1 | #ifndef _SOCKET_I_ 2 | #define _SOCKET_I_ 3 | 4 | #include 5 | using namespace std; 6 | 7 | #include "netbase.h" 8 | 9 | namespace ff { 10 | 11 | class ff_buffer_t 12 | { 13 | public: 14 | virtual ~ff_buffer_t() {} 15 | virtual const char* data() = 0; 16 | virtual const char* cur_data() = 0; 17 | virtual int total_size() = 0; 18 | virtual int left_size() = 0; 19 | virtual void seek(int n) = 0; 20 | virtual void consume(int n)= 0; 21 | virtual void release() = 0; 22 | }; 23 | 24 | class socket_i: public fd_i 25 | { 26 | public: 27 | socket_i(): 28 | m_data(NULL) {} 29 | virtual ~socket_i(){} 30 | 31 | virtual void open() = 0; 32 | virtual void async_send(const string& buff_) = 0; 33 | virtual void async_send(ff_buffer_t* buff_) = 0; 34 | virtual void async_recv() = 0; 35 | virtual void safe_delete() { delete this; } 36 | virtual void set_data(void* p) { m_data = p; } 37 | template 38 | T* get_data() const { return (T*)m_data; } 39 | 40 | private: 41 | void* m_data; 42 | }; 43 | 44 | typedef socket_i* socket_ptr_t; 45 | 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /fflib/net/socket_op.h: -------------------------------------------------------------------------------- 1 | #ifndef _SOCKET_OP_H_ 2 | #define _SOCKET_OP_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | using namespace std; 14 | 15 | namespace ff { 16 | 17 | struct socket_op_t 18 | { 19 | static int set_nonblock(int fd_) 20 | { 21 | int flags; 22 | flags = fcntl(fd_, F_GETFL, 0); 23 | if ((flags = fcntl(fd_, F_SETFL, flags | O_NONBLOCK)) < 0) 24 | { 25 | return -1; 26 | } 27 | 28 | return 0; 29 | } 30 | static string getpeername(int sockfd) 31 | { 32 | string ret; 33 | struct sockaddr_in sa; 34 | ::socklen_t len = sizeof(sa); 35 | if(!::getpeername(sockfd, (struct sockaddr *)&sa, &len)) 36 | { 37 | ret = ::inet_ntoa(sa.sin_addr); 38 | } 39 | return ret; 40 | } 41 | 42 | static int set_no_delay(int sockfd, bool flag_ = true) 43 | { 44 | int on = flag_? 1: 0; 45 | return ::setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY,&on,sizeof(on)); 46 | } 47 | 48 | }; 49 | 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /fflib/net/text_socket_controller_impl.h: -------------------------------------------------------------------------------- 1 | #ifndef _TEXT_SOCKET_CONTROLLER_IMPL_H_ 2 | #define _TEXT_SOCKET_CONTROLLER_IMPL_H_ 3 | 4 | #include 5 | using namespace std; 6 | 7 | #include "net/socket_controller_i.h" 8 | #include "net/message.h" 9 | #include "net/msg_handler_i.h" 10 | 11 | namespace ff { 12 | 13 | class socket_i; 14 | 15 | class text_socket_controller_impl_t: public socket_controller_i 16 | { 17 | enum protocol_e 18 | { 19 | TXT_PROTOCOL = 0, 20 | HTTP_PROTOCOL, 21 | UNKNOWN_PROTOCOL, 22 | }; 23 | public: 24 | text_socket_controller_impl_t(msg_handler_ptr_t msg_handler_); 25 | ~text_socket_controller_impl_t(); 26 | virtual int handle_error(socket_i*); 27 | virtual int handle_read(socket_i*, char* buff, size_t len); 28 | virtual int handle_write_completed(socket_i*); 29 | 30 | virtual int check_pre_send(socket_i*, string& buff_); 31 | private: 32 | int parse_msg_head(); 33 | int append_msg_body(socket_i* sp_, char* buff_begin_, size_t& left_); 34 | 35 | //! check which protocol does peer use 36 | protocol_e analyze_protocol(char* buff, size_t len); 37 | //! parse http protocol request 38 | int parse_http_protocol(socket_i* sp_, char* buff, size_t len); 39 | //! parse simple text protocol request 40 | int parse_text_protocol(socket_i* sp_, char* buff, size_t len); 41 | private: 42 | protocol_e m_protocol; 43 | msg_handler_ptr_t m_msg_handler; 44 | bool m_head_end_flag; 45 | size_t m_body_size; 46 | string m_head; 47 | message_t m_message; 48 | }; 49 | 50 | } 51 | #endif 52 | -------------------------------------------------------------------------------- /fflib/net/udp_socket.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/fflib/net/udp_socket.h -------------------------------------------------------------------------------- /fflib/python/ffpython.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/fflib/python/ffpython.h -------------------------------------------------------------------------------- /fflib/rpc/msg_def/ffrpc_msg_constants.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift Compiler (0.9.0) 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #include "ffrpc_msg_constants.h" 8 | 9 | 10 | 11 | const ffrpc_msgConstants g_ffrpc_msg_constants; 12 | 13 | ffrpc_msgConstants::ffrpc_msgConstants() { 14 | } 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /fflib/rpc/msg_def/ffrpc_msg_constants.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Thrift Compiler (0.9.0) 3 | * 4 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | * @generated 6 | */ 7 | #ifndef ffrpc_msg_CONSTANTS_H 8 | #define ffrpc_msg_CONSTANTS_H 9 | 10 | #include "ffrpc_msg_types.h" 11 | 12 | 13 | 14 | class ffrpc_msgConstants { 15 | public: 16 | ffrpc_msgConstants(); 17 | 18 | }; 19 | 20 | extern const ffrpc_msgConstants g_ffrpc_msg_constants; 21 | 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /fflib/server/db_mgr.h: -------------------------------------------------------------------------------- 1 | #ifndef _FF_DB_MGR_H_ 2 | #define _FF_DB_MGR_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | 11 | #include "base/log.h" 12 | #include "base/smart_ptr.h" 13 | #include "db/ffdb.h" 14 | #include "base/lock.h" 15 | #include "base/ffslot.h" 16 | #include "base/fftype.h" 17 | 18 | namespace ff 19 | { 20 | 21 | class db_mgr_t 22 | { 23 | public: 24 | struct db_connection_info_t; 25 | class db_query_result_t; 26 | public: 27 | db_mgr_t(); 28 | ~db_mgr_t(); 29 | int start(); 30 | int stop(); 31 | 32 | long connect_db(const string& host_); 33 | void db_query(long db_id_,const string& sql_, ffslot_t::callback_t* callback_); 34 | int sync_db_query(long db_id_,const string& sql_, vector >& ret_data_); 35 | 36 | void db_query_impl(db_connection_info_t* db_connection_info_, const string& sql_, ffslot_t::callback_t* callback_); 37 | private: 38 | long m_db_index; 39 | vector > m_tq; 40 | mutex_t m_mutex; 41 | map m_db_connection; 42 | thread_t m_thread; 43 | }; 44 | 45 | class db_mgr_t::db_query_result_t: public ffslot_t::callback_arg_t 46 | { 47 | public: 48 | db_query_result_t(): 49 | ok(false) 50 | {} 51 | virtual int type() 52 | { 53 | return TYPEID(db_query_result_t); 54 | } 55 | void clear() 56 | { 57 | ok = false; 58 | result_data.clear(); 59 | col_names.clear(); 60 | } 61 | bool ok; 62 | vector > result_data; 63 | vector col_names; 64 | }; 65 | 66 | struct db_mgr_t::db_connection_info_t 67 | { 68 | db_connection_info_t() 69 | { 70 | } 71 | db_connection_info_t(const db_connection_info_t& src_): 72 | tq(src_.tq), 73 | db(src_.db) 74 | { 75 | } 76 | shared_ptr_t tq; 77 | shared_ptr_t db; 78 | db_query_result_t ret; 79 | }; 80 | 81 | } 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /fflib/server/ffcurl.cpp: -------------------------------------------------------------------------------- 1 | 2 | #ifdef FF_ENABLE_CURL 3 | 4 | #include "server/ffcurl.h" 5 | #include 6 | //! 中文 7 | 8 | using namespace ff; 9 | 10 | static size_t write_data_func(void *ptr, size_t size, size_t nmemb, void *stream) 11 | { 12 | ffcurl_t::result_t* ret = (ffcurl_t::result_t*)stream; 13 | int written = size * nmemb; 14 | if (ret) 15 | { 16 | ret->data.append((const char*)ptr, written); 17 | } 18 | 19 | return written; 20 | } 21 | 22 | void ffcurl_t::post(const map& param_) 23 | { 24 | CURL* curl = NULL; 25 | CURLcode res; 26 | curl = curl_easy_init(); 27 | result_t result; 28 | if(curl) 29 | { 30 | for (map::const_iterator it = param_.begin(); it != param_.end(); ++it) 31 | { 32 | if (it->second.arg_flag == 0) 33 | { 34 | curl_easy_setopt(curl, (CURLoption)it->first, it->second.larg); 35 | } 36 | else 37 | { 38 | curl_easy_setopt(curl, (CURLoption)it->first, it->second.sarg.c_str()); 39 | } 40 | } 41 | 42 | curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data_func); 43 | curl_easy_setopt(curl, CURLOPT_WRITEHEADER, &result); 44 | res = curl_easy_perform(curl); 45 | /* Check for errors */ 46 | if(res != CURLE_OK) 47 | { 48 | result.err = curl_easy_strerror(res); 49 | } 50 | curl_easy_cleanup(curl); 51 | } 52 | } 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /fflib/server/ffcurl.h: -------------------------------------------------------------------------------- 1 | #ifndef _FF_CURL_IMPL_H_ 2 | #define _FF_CURL_IMPL_H_ 3 | 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | namespace ff 9 | { 10 | 11 | class ffcurl_t 12 | { 13 | public: 14 | struct param_t 15 | { 16 | param_t(): 17 | arg_flag(0), 18 | larg(0) 19 | {} 20 | int arg_flag; 21 | long larg; 22 | string sarg; 23 | }; 24 | struct result_t 25 | { 26 | string err; 27 | string data; 28 | }; 29 | public: 30 | ffcurl_t(); 31 | ~ffcurl_t(); 32 | 33 | void post(const map& param_); 34 | 35 | }; 36 | } 37 | #endif 38 | 39 | -------------------------------------------------------------------------------- /fflib/server/fflua_json_traits.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/fflib/server/fflua_json_traits.h -------------------------------------------------------------------------------- /fflib/xml/ffxml.h: -------------------------------------------------------------------------------- 1 | #ifndef _FF_XML_H_ 2 | #define _FF_XML_H_ 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | using namespace std; 9 | 10 | #include 11 | 12 | namespace ff 13 | { 14 | 15 | class ffxml_t 16 | { 17 | public: 18 | ffxml_t(); 19 | ~ffxml_t(); 20 | int load(const string& file_); 21 | //! root.a 22 | //! root.{b} 23 | //! root.@1.{b} root.@2.c 24 | const char* get(const string& node_name_); 25 | size_t size(const string& node_name_); 26 | 27 | protected: 28 | pair get_node(const string& node_name_); 29 | private: 30 | TiXmlDocument m_xml_doc; 31 | }; 32 | } 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /fflib/xml/tinyxmlerror.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | www.sourceforge.net/projects/tinyxml 3 | Original code (2.0 and earlier )copyright (c) 2000-2006 Lee Thomason (www.grinninglizard.com) 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any 7 | damages arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any 10 | purpose, including commercial applications, and to alter it and 11 | redistribute it freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must 14 | not claim that you wrote the original software. If you use this 15 | software in a product, an acknowledgment in the product documentation 16 | would be appreciated but is not required. 17 | 18 | 2. Altered source versions must be plainly marked as such, and 19 | must not be misrepresented as being the original software. 20 | 21 | 3. This notice may not be removed or altered from any source 22 | distribution. 23 | */ 24 | 25 | #include "xml/tinyxml.h" 26 | 27 | // The goal of the seperate error file is to make the first 28 | // step towards localization. tinyxml (currently) only supports 29 | // english error messages, but the could now be translated. 30 | // 31 | // It also cleans up the code a bit. 32 | // 33 | 34 | const char* TiXmlBase::errorString[ TiXmlBase::TIXML_ERROR_STRING_COUNT ] = 35 | { 36 | "No error", 37 | "Error", 38 | "Failed to open file", 39 | "Error parsing Element.", 40 | "Failed to read Element name", 41 | "Error reading Element value.", 42 | "Error reading Attributes.", 43 | "Error: empty tag.", 44 | "Error reading end tag.", 45 | "Error parsing Unknown.", 46 | "Error parsing Comment.", 47 | "Error parsing Declaration.", 48 | "Error document empty.", 49 | "Error null (0) or unexpected EOF found in input stream.", 50 | "Error parsing CDATA.", 51 | "Error when TiXmlDocument added to document, because TiXmlDocument can only be at the root.", 52 | }; 53 | -------------------------------------------------------------------------------- /lib3party/rapidjson/filestream.h: -------------------------------------------------------------------------------- 1 | #ifndef RAPIDJSON_FILESTREAM_H_ 2 | #define RAPIDJSON_FILESTREAM_H_ 3 | 4 | #include 5 | 6 | namespace rapidjson { 7 | 8 | //! Wrapper of C file stream for input or output. 9 | /*! 10 | This simple wrapper does not check the validity of the stream. 11 | \implements Stream 12 | */ 13 | class FileStream { 14 | public: 15 | typedef char Ch; //!< Character type. Only support char. 16 | 17 | FileStream(FILE* fp) : fp_(fp), count_(0) { Read(); } 18 | char Peek() const { return current_; } 19 | char Take() { char c = current_; Read(); return c; } 20 | size_t Tell() const { return count_; } 21 | void Put(char c) { fputc(c, fp_); } 22 | 23 | // Not implemented 24 | char* PutBegin() { return 0; } 25 | size_t PutEnd(char*) { return 0; } 26 | 27 | private: 28 | void Read() { 29 | RAPIDJSON_ASSERT(fp_ != 0); 30 | int c = fgetc(fp_); 31 | if (c != EOF) { 32 | current_ = (char)c; 33 | count_++; 34 | } 35 | else 36 | current_ = '\0'; 37 | } 38 | 39 | FILE* fp_; 40 | char current_; 41 | size_t count_; 42 | }; 43 | 44 | } // namespace rapidjson 45 | 46 | #endif // RAPIDJSON_FILESTREAM_H_ 47 | -------------------------------------------------------------------------------- /lib3party/rapidjson/internal/stack.h: -------------------------------------------------------------------------------- 1 | #ifndef RAPIDJSON_INTERNAL_STACK_H_ 2 | #define RAPIDJSON_INTERNAL_STACK_H_ 3 | 4 | namespace rapidjson { 5 | namespace internal { 6 | 7 | /////////////////////////////////////////////////////////////////////////////// 8 | // Stack 9 | 10 | //! A type-unsafe stack for storing different types of data. 11 | /*! \tparam Allocator Allocator for allocating stack memory. 12 | */ 13 | template 14 | class Stack { 15 | public: 16 | Stack(Allocator* allocator, size_t stack_capacity) : allocator_(allocator), own_allocator_(0), stack_(0), stack_top_(0), stack_end_(0), stack_capacity_(stack_capacity) { 17 | RAPIDJSON_ASSERT(stack_capacity_ > 0); 18 | if (!allocator_) 19 | own_allocator_ = allocator_ = new Allocator(); 20 | stack_top_ = stack_ = (char*)allocator_->Malloc(stack_capacity_); 21 | stack_end_ = stack_ + stack_capacity_; 22 | } 23 | 24 | ~Stack() { 25 | Allocator::Free(stack_); 26 | delete own_allocator_; // Only delete if it is owned by the stack 27 | } 28 | 29 | void Clear() { /*stack_top_ = 0;*/ stack_top_ = stack_; } 30 | 31 | template 32 | T* Push(size_t count = 1) { 33 | // Expand the stack if needed 34 | if (stack_top_ + sizeof(T) * count >= stack_end_) { 35 | size_t new_capacity = stack_capacity_ * 2; 36 | size_t size = GetSize(); 37 | size_t new_size = GetSize() + sizeof(T) * count; 38 | if (new_capacity < new_size) 39 | new_capacity = new_size; 40 | stack_ = (char*)allocator_->Realloc(stack_, stack_capacity_, new_capacity); 41 | stack_capacity_ = new_capacity; 42 | stack_top_ = stack_ + size; 43 | stack_end_ = stack_ + stack_capacity_; 44 | } 45 | T* ret = (T*)stack_top_; 46 | stack_top_ += sizeof(T) * count; 47 | return ret; 48 | } 49 | 50 | template 51 | T* Pop(size_t count) { 52 | RAPIDJSON_ASSERT(GetSize() >= count * sizeof(T)); 53 | stack_top_ -= count * sizeof(T); 54 | return (T*)stack_top_; 55 | } 56 | 57 | template 58 | T* Top() { 59 | RAPIDJSON_ASSERT(GetSize() >= sizeof(T)); 60 | return (T*)(stack_top_ - sizeof(T)); 61 | } 62 | 63 | template 64 | T* Bottom() { return (T*)stack_; } 65 | 66 | Allocator& GetAllocator() { return *allocator_; } 67 | size_t GetSize() const { return stack_top_ - stack_; } 68 | size_t GetCapacity() const { return stack_capacity_; } 69 | 70 | private: 71 | Allocator* allocator_; 72 | Allocator* own_allocator_; 73 | char *stack_; 74 | char *stack_top_; 75 | char *stack_end_; 76 | size_t stack_capacity_; 77 | }; 78 | 79 | } // namespace internal 80 | } // namespace rapidjson 81 | 82 | #endif // RAPIDJSON_STACK_H_ 83 | -------------------------------------------------------------------------------- /lib3party/rapidjson/internal/strfunc.h: -------------------------------------------------------------------------------- 1 | #ifndef RAPIDJSON_INTERNAL_STRFUNC_H_ 2 | #define RAPIDJSON_INTERNAL_STRFUNC_H_ 3 | 4 | namespace rapidjson { 5 | namespace internal { 6 | 7 | //! Custom strlen() which works on different character types. 8 | /*! \tparam Ch Character type (e.g. char, wchar_t, short) 9 | \param s Null-terminated input string. 10 | \return Number of characters in the string. 11 | \note This has the same semantics as strlen(), the return value is not number of Unicode codepoints. 12 | */ 13 | template 14 | inline SizeType StrLen(const Ch* s) { 15 | const Ch* p = s; 16 | while (*p != '\0') 17 | ++p; 18 | return SizeType(p - s); 19 | } 20 | 21 | } // namespace internal 22 | } // namespace rapidjson 23 | 24 | #endif // RAPIDJSON_INTERNAL_STRFUNC_H_ 25 | -------------------------------------------------------------------------------- /lib3party/rapidjson/stringbuffer.h: -------------------------------------------------------------------------------- 1 | #ifndef RAPIDJSON_STRINGBUFFER_H_ 2 | #define RAPIDJSON_STRINGBUFFER_H_ 3 | 4 | #include "rapidjson.h" 5 | #include "internal/stack.h" 6 | 7 | namespace rapidjson { 8 | 9 | //! Represents an in-memory output stream. 10 | /*! 11 | \tparam Encoding Encoding of the stream. 12 | \tparam Allocator type for allocating memory buffer. 13 | \implements Stream 14 | */ 15 | template 16 | struct GenericStringBuffer { 17 | typedef typename Encoding::Ch Ch; 18 | 19 | GenericStringBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity) : stack_(allocator, capacity) {} 20 | 21 | void Put(Ch c) { *stack_.template Push() = c; } 22 | 23 | void Clear() { stack_.Clear(); } 24 | 25 | const char* GetString() const { 26 | // Push and pop a null terminator. This is safe. 27 | *stack_.template Push() = '\0'; 28 | stack_.template Pop(1); 29 | 30 | return stack_.template Bottom(); 31 | } 32 | 33 | size_t Size() const { return stack_.GetSize(); } 34 | 35 | static const size_t kDefaultCapacity = 256; 36 | mutable internal::Stack stack_; 37 | }; 38 | 39 | typedef GenericStringBuffer > StringBuffer; 40 | 41 | //! Implement specialized version of PutN() with memset() for better performance. 42 | template<> 43 | inline void PutN(GenericStringBuffer >& stream, char c, size_t n) { 44 | memset(stream.stack_.Push(n), c, n * sizeof(c)); 45 | } 46 | 47 | } // namespace rapidjson 48 | 49 | #endif // RAPIDJSON_STRINGBUFFER_H_ 50 | -------------------------------------------------------------------------------- /lib3party/thrift/FFThrift.h: -------------------------------------------------------------------------------- 1 | #ifndef _THRIFT_FFTHRIFT_H_ 2 | #define _THRIFT_FFTHRIFT_H_ 1 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #ifdef TYPE_NAME 12 | #define GET_TYPE_NAME_FFTHRIFT(X) TYPE_NAME(X) 13 | #else 14 | #define GET_TYPE_NAME_FFTHRIFT(X) "ff" 15 | #endif 16 | 17 | //#include 18 | 19 | struct ffthrift_t 20 | { 21 | template 22 | static bool EncodeToString(T& msg_, std::string& data_) 23 | { 24 | using apache::thrift::transport::FFTMemoryBuffer; 25 | using apache::thrift::protocol::TBinaryProtocol; 26 | FFTMemoryBuffer ffmem(&data_); 27 | TBinaryProtocol proto(&ffmem); 28 | proto.writeMessageBegin(GET_TYPE_NAME_FFTHRIFT(T), (apache::thrift::protocol::TMessageType)0, (int32_t)0); 29 | msg_.write(&proto); 30 | proto.writeMessageEnd(); 31 | return true; 32 | } 33 | template 34 | static std::string EncodeAsString(T& msg_) 35 | { 36 | std::string ret; 37 | ffthrift_t::EncodeToString(msg_, ret); 38 | return ret; 39 | } 40 | template 41 | static bool DecodeFromString(T& msg_, const std::string& data_) 42 | { 43 | using apache::thrift::transport::FFTMemoryBuffer; 44 | using apache::thrift::protocol::TBinaryProtocol; 45 | FFTMemoryBuffer ffmem(data_); 46 | TBinaryProtocol proto(&ffmem); 47 | string msg_name; 48 | apache::thrift::protocol::TMessageType nType = (apache::thrift::protocol::TMessageType)0; 49 | int32_t nFlag = 0; 50 | proto.readMessageBegin(msg_name, nType, nFlag); 51 | msg_.read(&proto); 52 | proto.readMessageEnd(); 53 | //printf("msg=%s\n", msg_name.c_str()); 54 | return true; 55 | } 56 | }; 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /lib3party/thrift/TApplicationException.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/lib3party/thrift/TApplicationException.h -------------------------------------------------------------------------------- /lib3party/thrift/Thrift.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _THRIFT_THRIFT_H_ 3 | #define _THRIFT_THRIFT_H_ 1 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace apache { namespace thrift { 13 | 14 | class TOutput { 15 | public: 16 | TOutput() : f_(&errorTimeWrapper) {} 17 | 18 | inline void setOutputFunction(void (*function)(const char *)){ 19 | f_ = function; 20 | } 21 | 22 | inline void operator()(const char *message){ 23 | f_(message); 24 | } 25 | 26 | // It is important to have a const char* overload here instead of 27 | // just the string version, otherwise errno could be corrupted 28 | // if there is some problem allocating memory when constructing 29 | // the string. 30 | void perror(const char *message, int errno_copy); 31 | inline void perror(const std::string &message, int errno_copy) { 32 | perror(message.c_str(), errno_copy); 33 | } 34 | 35 | void printf(const char *message, ...); 36 | 37 | inline static void errorTimeWrapper(const char* msg) { 38 | time_t now; 39 | char dbgtime[26]; 40 | time(&now); 41 | //ctime_r(&now, dbgtime); 42 | #ifdef __linux__ 43 | char* p = ctime(&now); 44 | ::strcpy(dbgtime, p); 45 | #else 46 | ctime_s(dbgtime, sizeof(dbgtime), &now); 47 | #endif 48 | dbgtime[24] = 0; 49 | fprintf(stderr, "Thrift: %s %s\n", dbgtime, msg); 50 | } 51 | 52 | /** Just like strerror_r but returns a C++ string object. */ 53 | static std::string strerror_s(int errno_copy); 54 | 55 | private: 56 | void (*f_)(const char *); 57 | }; 58 | 59 | 60 | class TException : public std::exception { 61 | public: 62 | TException(): 63 | message_() {} 64 | 65 | TException(const std::string& message) : 66 | message_(message) {} 67 | 68 | virtual ~TException() throw() {} 69 | 70 | virtual const char* what() const throw() { 71 | if (message_.empty()) { 72 | return "Default TException."; 73 | } else { 74 | return message_.c_str(); 75 | } 76 | } 77 | 78 | protected: 79 | std::string message_; 80 | 81 | }; 82 | 83 | }} 84 | #endif 85 | -------------------------------------------------------------------------------- /lib3party/thrift/ThriftConfig.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _THRIFT_THRIFT_CONFIG_H_ 3 | #define _THRIFT_THRIFT_CONFIG_H_ 1 4 | 5 | #include 6 | 7 | #define T_VIRTUAL_CALL() 8 | #define BOOST_STATIC_ASSERT(X) assert(X) 9 | #define TDB_LIKELY(val) (val) 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #ifdef _WIN32 21 | #include 22 | #pragma comment(lib, "Ws2_32.lib") 23 | 24 | typedef __int64 int64_t; 25 | typedef unsigned __int64 uint64_t; 26 | typedef int int32_t; 27 | typedef DWORD uint32_t; 28 | typedef short int16_t; 29 | typedef unsigned short uint16_t; 30 | typedef char int8_t; 31 | typedef BYTE uint8_t; 32 | 33 | #else 34 | #include 35 | #endif 36 | 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /lib3party/thrift/cxxfunctional.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /lib3party/thrift/transport/FFTransport.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coolxiaox/ffengine/74eea47fa0b527f3079b3586712963b4b685592f/lib3party/thrift/transport/FFTransport.h --------------------------------------------------------------------------------