diff --git a/dub.json b/dub.json index 53bd8bb..2ab0f41 100644 --- a/dub.json +++ b/dub.json @@ -9,8 +9,9 @@ "dependencies": { "dlang-snappy": "~>0.0.1", "flatbuffers": "~>0.1.1", - "kiss" : "~>0.0.7", + "kiss" : "~>0.0.8", }, - "license": "Apache-2.0" + "license": "Apache-2.0" + } diff --git a/kiss-rpc-idl/kissrpc/generated/client/TestRpcInterface.d b/kiss-rpc-idl/kissrpc/generated/client/TestRpcInterface.d deleted file mode 100644 index e4aca1a..0000000 --- a/kiss-rpc-idl/kissrpc/generated/client/TestRpcInterface.d +++ /dev/null @@ -1,111 +0,0 @@ -module kissrpc.generated.TestRpcInterface; - -import kissrpc.generated.TestRpcMessage; -import kissrpc.generated.TestRpcService; - -import kissrpc.RpcRequest; -import kissrpc.RpcClientImpl; -import kissrpc.RpcClient; -import kissrpc.RpcResponse; -import kissrpc.Unit; -import flatbuffers; -import kissrpc.generated.message.TestRpc; - -abstract class RpcTestInterface{ - - this(RpcClient rpClient){ - rpImpl = new RpcClientImpl!(RpcTestService)(rpClient); - } - - UserInfo getNameInterface(const UserInfo userInfo, const RPC_PACKAGE_COMPRESS_TYPE compressType, const int secondsTimeOut, const size_t funcId = 2791659981){ - - auto builder = new FlatBufferBuilder(512); - - //input flatbuffer code for UserInfoFB class - - - - - auto userInfoPos = UserInfoFB.createUserInfoFB(builder, userInfo.i, builder.createString(userInfo.name), ); - - - builder.finish(userInfoPos); - - auto req = new RpcRequest(compressType, secondsTimeOut); - - req.push(builder.sizedByteArray); - - RpcResponse resp = rpImpl.syncCall(req, RPC_PACKAGE_PROTOCOL.TPP_FLAT_BUF, funcId); - - if(resp.getStatus == RESPONSE_STATUS.RS_OK){ - - ubyte[] flatBufBytes; - resp.pop(flatBufBytes); - - auto ret_UserInfoFB = UserInfoFB.getRootAsUserInfoFB(new ByteBuffer(flatBufBytes)); - UserInfo ret_UserInfo; - - //input flatbuffer code for UserInfoFB class - - - - - ret_UserInfo.i = ret_UserInfoFB.i; - ret_UserInfo.name = ret_UserInfoFB.name; - - - return ret_UserInfo; - }else{ - throw new Exception("rpc sync call error, function:" ~ RpcBindFunctionMap[funcId]); - } - } - - - alias RpcgetNameCallback = void delegate(UserInfo); - - void getNameInterface(const UserInfo userInfo, RpcgetNameCallback rpcCallback, const RPC_PACKAGE_COMPRESS_TYPE compressType, const int secondsTimeOut, const size_t funcId = 2791659981){ - - auto builder = new FlatBufferBuilder(512); - //input flatbuffer code for UserInfoFB class - - - - - auto userInfoPos = UserInfoFB.createUserInfoFB(builder, userInfo.i, builder.createString(userInfo.name), ); - - - builder.finish(userInfoPos); - auto req = new RpcRequest(compressType, secondsTimeOut); - - req.push(builder.sizedByteArray); - - rpImpl.asyncCall(req, delegate(RpcResponse resp){ - - if(resp.getStatus == RESPONSE_STATUS.RS_OK){ - - ubyte[] flatBufBytes; - UserInfo ret_UserInfo; - - resp.pop(flatBufBytes); - - auto ret_UserInfoFB = UserInfoFB.getRootAsUserInfoFB(new ByteBuffer(flatBufBytes)); - //input flatbuffer code for UserInfoFB class - - - - - ret_UserInfo.i = ret_UserInfoFB.i; - ret_UserInfo.name = ret_UserInfoFB.name; - - - rpcCallback(ret_UserInfo); - }else{ - throw new Exception("rpc sync call error, function:" ~ RpcBindFunctionMap[funcId]); - }}, RPC_PACKAGE_PROTOCOL.TPP_FLAT_BUF, funcId); - } - - - RpcClientImpl!(RpcTestService) rpImpl; -} - - diff --git a/kiss-rpc-idl/kissrpc/generated/client/TestRpcService.d b/kiss-rpc-idl/kissrpc/generated/client/TestRpcService.d deleted file mode 100644 index 268a957..0000000 --- a/kiss-rpc-idl/kissrpc/generated/client/TestRpcService.d +++ /dev/null @@ -1,34 +0,0 @@ -module kissrpc.generated.TestRpcService; - - -import kissrpc.generated.TestRpcInterface; -import kissrpc.generated.TestRpcMessage; - -import kissrpc.RpcClient; -import kissrpc.Unit; - - -class RpcTestService: RpcTestInterface{ - - this(RpcClient rpClient){ - RpcBindFunctionMap[2791659981] = typeid(&RpcTestService.getName).toString(); - super(rpClient); - } - - UserInfo getName(UserInfo userInfo, const RPC_PACKAGE_COMPRESS_TYPE compressType = RPC_PACKAGE_COMPRESS_TYPE.RPCT_NO, const int secondsTimeOut = RPC_REQUEST_TIMEOUT_SECONDS){ - - UserInfo ret = super.getNameInterface(userInfo, compressType, secondsTimeOut); - return ret; - } - - - void getName(UserInfo userInfo, RpcgetNameCallback rpcCallback, const RPC_PACKAGE_COMPRESS_TYPE compressType = RPC_PACKAGE_COMPRESS_TYPE.RPCT_NO, const int secondsTimeOut = RPC_REQUEST_TIMEOUT_SECONDS){ - - super.getNameInterface(userInfo, rpcCallback, compressType, secondsTimeOut); - } - - -} - - - diff --git a/kiss-rpc-idl/kissrpc/generated/message/TestRpc.d b/kiss-rpc-idl/kissrpc/generated/message/TestRpc.d deleted file mode 100644 index 1e83f3a..0000000 --- a/kiss-rpc-idl/kissrpc/generated/message/TestRpc.d +++ /dev/null @@ -1,28 +0,0 @@ -// automatically generated by the FlatBuffers compiler, do not modifymodule kissrpc.generated.message.TestRpc; - -import std.typecons; -import flatbuffers; - -struct UserInfoFB { - mixin Table!UserInfoFB; - - static UserInfoFB getRootAsUserInfoFB(ByteBuffer _bb) { return UserInfoFB.init_(_bb.get!int(_bb.position()) + _bb.position(), _bb); } - @property int i() { uint o = __offset(4); return o != 0 ? _buffer.get!int(o + _pos) : 0; } - @property Nullable!string name() { uint o = __offset(6); return o != 0 ? Nullable!string(__string(o + _pos)) : Nullable!string.init; } - - static uint createUserInfoFB(FlatBufferBuilder builder,int i,uint name) { - builder.startObject(2); - UserInfoFB.addName(builder, name); - UserInfoFB.addI(builder, i); - return UserInfoFB.endUserInfoFB(builder); - } - - static void startUserInfoFB(FlatBufferBuilder builder) { builder.startObject(2); } - static void addI(FlatBufferBuilder builder, int i) { builder.add!int(0, i, 0); } - static void addName(FlatBufferBuilder builder, uint nameOffset) { builder.addOffset(1, nameOffset, 0); } - static uint endUserInfoFB(FlatBufferBuilder builder) { - uint o = builder.endObject(); - return o; - } -} - diff --git a/kiss-rpc-idl/kissrpc/generated/message/TestRpc.fbs b/kiss-rpc-idl/kissrpc/generated/message/TestRpc.fbs deleted file mode 100644 index 74c8900..0000000 --- a/kiss-rpc-idl/kissrpc/generated/message/TestRpc.fbs +++ /dev/null @@ -1,8 +0,0 @@ -namespace kissrpc.generated.message; - -table UserInfoFB{ - i:int; - name:string; -} - - diff --git a/kiss-rpc-idl/kissrpc/generated/message/TestRpcMessage.d b/kiss-rpc-idl/kissrpc/generated/message/TestRpcMessage.d deleted file mode 100644 index 8d17a68..0000000 --- a/kiss-rpc-idl/kissrpc/generated/message/TestRpcMessage.d +++ /dev/null @@ -1,11 +0,0 @@ -module kissrpc.generated.TestRpcMessage; -import std.typetuple; - - -struct UserInfo{ - - int i; - string name; -} - - diff --git a/kiss-rpc-idl/kissrpc/generated/server/TestRpcInterface.d b/kiss-rpc-idl/kissrpc/generated/server/TestRpcInterface.d deleted file mode 100644 index 794f11a..0000000 --- a/kiss-rpc-idl/kissrpc/generated/server/TestRpcInterface.d +++ /dev/null @@ -1,59 +0,0 @@ -module kissrpc.generated.TestRpcInterface; - -import kissrpc.generated.TestRpcMessage; -import kissrpc.generated.TestRpcService; - -import kissrpc.RpcServer; -import kissrpc.RpcServerImpl; -import kissrpc.RpcResponse; -import kissrpc.RpcRequest; -import flatbuffers; -import kissrpc.generated.message.TestRpc; - -abstract class RpcTestInterface{ - - this(RpcServer rpServer){ - rpImpl = new RpcServerImpl!(RpcTestService)(rpServer); - rpImpl.bindRequestCallback(2791659981, &this.getNameInterface); - - } - - void getNameInterface(RpcRequest req){ - - ubyte[] flatBufBytes; - - auto resp = new RpcResponse(req); - req.pop(flatBufBytes); - - auto userInfoFB = UserInfoFB.getRootAsUserInfoFB(new ByteBuffer(flatBufBytes)); - UserInfo userInfo; - - //input flatbuffer code for UserInfoFB class - - - - userInfo.i = userInfoFB.i; - userInfo.name = userInfoFB.name; - - - auto ret_UserInfo = (cast(RpcTestService)this).getName(userInfo); - - auto builder = new FlatBufferBuilder(512); - //input flatbuffer code for UserInfoFB class - - auto ret_UserInfoPos = UserInfoFB.createUserInfoFB(builder, ret_UserInfo.i, builder.createString(ret_UserInfo.name), ); - - - builder.finish(ret_UserInfoPos); - - resp.push(builder.sizedByteArray); - - rpImpl.response(resp); - } - - - - RpcServerImpl!(RpcTestService) rpImpl; -} - - diff --git a/kiss-rpc-idl/kissrpc/generated/server/TestRpcService.d b/kiss-rpc-idl/kissrpc/generated/server/TestRpcService.d deleted file mode 100644 index 205cdb6..0000000 --- a/kiss-rpc-idl/kissrpc/generated/server/TestRpcService.d +++ /dev/null @@ -1,32 +0,0 @@ -module kissrpc.generated.TestRpcService; - -import kissrpc.generated.TestRpcInterface; -import kissrpc.generated.TestRpcMessage; - -import kissrpc.RpcServer; -import kissrpc.Unit; - - -class RpcTestService: RpcTestInterface{ - - this(RpcServer rpServer){ - RpcBindFunctionMap[2791659981] = typeid(&RpcTestService.getName).toString(); - super(rpServer); - } - - UserInfo getName(UserInfo userInfo){ - - UserInfo userInfoRet; - //input service code for UserInfo class - - - - return userInfoRet; - } - - - -} - - - diff --git a/kiss-rpc-idl/source/IDL/IdlInerfaceCreateCode.d b/kiss-rpc-idl/source/IDL/IdlInerfaceCreateCode.d index 84016d6..dc5dda6 100644 --- a/kiss-rpc-idl/source/IDL/IdlInerfaceCreateCode.d +++ b/kiss-rpc-idl/source/IDL/IdlInerfaceCreateCode.d @@ -77,7 +77,7 @@ class IdlFunctionAttrCode formattedWrite(strings, "\t\t%s\n\n", IdlParseStruct.createDeserializeCodeForFlatbuffer(idlStructList[FunctionAttrInterface.funcArgMap.getTypeName], FunctionAttrInterface.funcArgMap.getVarName, FunctionAttrInterface.funcArgMap.getVarName~"FB")); - formattedWrite(strings, "\t\tauto %s = (cast(Rpc%sService)this).%s(%s);\n\n", FunctionAttrInterface.retValue.getVarName, inerfaceName, FunctionAttrInterface.getFuncName, FunctionAttrInterface.funcArgMap.getVarName); + formattedWrite(strings, "\t\tauto %s = (cast(%sService)this).%s(%s);\n\n", FunctionAttrInterface.retValue.getVarName, inerfaceName, FunctionAttrInterface.getFuncName, FunctionAttrInterface.funcArgMap.getVarName); formattedWrite(strings, "\t\tauto builder = new FlatBufferBuilder(512);\n"); @@ -226,9 +226,9 @@ class idl_inerface_dlang_code { auto strings = appender!string(); - formattedWrite(strings, "abstract class Rpc%sInterface{ \n\n", idlInterface.interfaceName); + formattedWrite(strings, "abstract class %sInterface{ \n\n", idlInterface.interfaceName); formattedWrite(strings, "\tthis(RpcServer rpServer){ \n"); - formattedWrite(strings, "\t\trpImpl = new RpcServerImpl!(Rpc%sService)(rpServer); \n", idlInterface.interfaceName); + formattedWrite(strings, "\t\trpImpl = new RpcServerImpl!(%sService)(rpServer); \n", idlInterface.interfaceName); foreach(k,v; idlInterface.functionList) { @@ -242,7 +242,7 @@ class idl_inerface_dlang_code formattedWrite(strings, IdlFunctionAttrCode.createServerInterfaceCode(v, idlInterface.interfaceName)); } - formattedWrite(strings, "\tRpcServerImpl!(Rpc%sService) rpImpl;\n}\n\n\n", idlInterface.interfaceName); + formattedWrite(strings, "\tRpcServerImpl!(%sService) rpImpl;\n}\n\n\n", idlInterface.interfaceName); return strings.data; } @@ -253,12 +253,12 @@ class idl_inerface_dlang_code auto strings = appender!string(); - formattedWrite(strings, "\nclass Rpc%sService: Rpc%sInterface{\n\n", idlInterface.interfaceName, idlInterface.interfaceName); + formattedWrite(strings, "\nclass %sService: %sInterface{\n\n", idlInterface.interfaceName, idlInterface.interfaceName); formattedWrite(strings, "\tthis(RpcServer rpServer){\n"); foreach(k,v; idlInterface.functionList) { - formattedWrite(strings, "\t\tRpcBindFunctionMap[%s] = typeid(&Rpc%sService.%s).toString();\n", v.funcHash, idlInterface.interfaceName, v.funcName); + formattedWrite(strings, "\t\tRpcBindFunctionMap[%s] = typeid(&%sService.%s).toString();\n", v.funcHash, idlInterface.interfaceName, v.funcName); } formattedWrite(strings, "\t\tsuper(rpServer);\n"); @@ -279,9 +279,9 @@ class idl_inerface_dlang_code { auto strings = appender!string(); - formattedWrite(strings, "abstract class Rpc%sInterface{ \n\n", idlInterface.interfaceName); + formattedWrite(strings, "abstract class %sInterface{ \n\n", idlInterface.interfaceName); formattedWrite(strings, "\tthis(RpcClient rpClient){ \n"); - formattedWrite(strings, "\t\trpImpl = new RpcClientImpl!(Rpc%sService)(rpClient); \n", idlInterface.interfaceName); + formattedWrite(strings, "\t\trpImpl = new RpcClientImpl!(%sService)(rpClient); \n", idlInterface.interfaceName); formattedWrite(strings, "\t}\n\n"); @@ -290,7 +290,7 @@ class idl_inerface_dlang_code formattedWrite(strings, IdlFunctionAttrCode.createClientInterfaceCode(v, idlInterface.interfaceName)); } - formattedWrite(strings, "\tRpcClientImpl!(Rpc%sService) rpImpl;\n}\n\n\n", idlInterface.interfaceName); + formattedWrite(strings, "\tRpcClientImpl!(%sService) rpImpl;\n}\n\n\n", idlInterface.interfaceName); return strings.data; } @@ -300,12 +300,12 @@ class idl_inerface_dlang_code { auto strings = appender!string(); - formattedWrite(strings, "\nclass Rpc%sService: Rpc%sInterface{\n\n", idlInterface.interfaceName, idlInterface.interfaceName); + formattedWrite(strings, "\nclass %sService: %sInterface{\n\n", idlInterface.interfaceName, idlInterface.interfaceName); formattedWrite(strings, "\tthis(RpcClient rpClient){\n"); foreach(k,v; idlInterface.functionList) { - formattedWrite(strings, "\t\tRpcBindFunctionMap[%s] = typeid(&Rpc%sService.%s).toString();\n", v.funcHash, idlInterface.interfaceName, v.funcName); + formattedWrite(strings, "\t\tRpcBindFunctionMap[%s] = typeid(&%sService.%s).toString();\n", v.funcHash, idlInterface.interfaceName, v.funcName); } diff --git a/source/KissRpc/RpcClient.d b/source/KissRpc/RpcClient.d index bca2f14..16242c4 100755 --- a/source/KissRpc/RpcClient.d +++ b/source/KissRpc/RpcClient.d @@ -177,7 +177,6 @@ class RpcClient:RpcEventInterface{ break; case SOCKET_STATUS.SE_WRITE_FAILED: - // writeln("heressss"); auto t = task(&clientSocketEvent.writeFailed, socket); taskPool.put(t); break; @@ -194,6 +193,11 @@ class RpcClient:RpcEventInterface{ clientSocket = new RpcClientSocket(ip, port, sel, this); } + void reConnect() + { + clientSocket.reConnect(); + } + ulong getWaitResponseNum() { return sendPackManage.getWaitResponseNum; diff --git a/source/KissRpc/RpcClientListener.d b/source/KissRpc/RpcClientListener.d index dd75b7e..c21952e 100644 --- a/source/KissRpc/RpcClientListener.d +++ b/source/KissRpc/RpcClientListener.d @@ -23,6 +23,11 @@ class RpcClientListener : ClientSocketEventInterface { } + + void reConnect() + { + _rpClient.reConnect(); + } void disconnectd(RpcSocketBaseInterface socket) { diff --git a/source/KissRpc/RpcClientSocket.d b/source/KissRpc/RpcClientSocket.d index 74d94e8..bd1f228 100755 --- a/source/KissRpc/RpcClientSocket.d +++ b/source/KissRpc/RpcClientSocket.d @@ -40,13 +40,13 @@ public: _socketEventDelegate.socketEvent(this, SOCKET_STATUS.SE_CONNECTD, "connect to server is ok!"); } override void onConnectFailed(void* attachment) { - writeln("onConnectFailed"); + //writeln("onConnectFailed"); } override void onWriteCompleted(void* attachment, size_t count , ByteBuffer buffer) { // writeln("write success index ",index); } override void onWriteFailed(void* attachment) { - writeln("onWriteFailed"); + //writeln("onWriteFailed"); _socketEventDelegate.socketEvent(this, SOCKET_STATUS.SE_WRITE_FAILED, "write data to server is failed"); } override void onReadCompleted(void* attachment, size_t count , ByteBuffer buffer) { @@ -55,11 +55,16 @@ public: _readBuffer.clear(); } override void onReadFailed(void* attachment) { - writeln("onReadFailed"); + //writeln("onReadFailed"); } override void onClose() { _socketEventDelegate.socketEvent(this, SOCKET_STATUS.SE_DISCONNECTD, "disconnect from server!"); } + override void reConnect() { + //writeln("RpcClientSocket reConnect"); + super.reConnect(); + } + void disconnect() { close();