diff --git a/IDL-Example/client/kiss-testInterface.d b/IDL-Example/client/kiss-testInterface.d new file mode 100644 index 0000000..147a0f0 --- /dev/null +++ b/IDL-Example/client/kiss-testInterface.d @@ -0,0 +1,64 @@ +module KissRpc.IDL.kiss-testInterface; + +import KissRpc.IDL.kiss-testMessage; +import KissRpc.IDL.kiss-testService; + +import KissRpc.RpcRequest; +import KissRpc.RpcClientImpl; +import KissRpc.RpcClient; +import KissRpc.RpcResponse; +import KissRpc.Unit; + +abstract class RpcAddressBookInterface{ + + this(RpcClient rpClient){ + rpImpl = new RpcClientImpl!(RpcAddressBookService)(rpClient); + } + + contacts getContactListInterface(string accountName, const RPC_PACKAGE_COMPRESS_TYPE compressType, const int secondsTimeOut, string bindFunc = __FUNCTION__){ + + auto req = new RpcRequest(compressType, secondsTimeOut); + + req.push(accountName); + + RpcResponse resp = rpImpl.syncCall(req, bindFunc); + + if(resp.getStatus == RESPONSE_STATUS.RS_OK){ + contacts ret_contacts; + + resp.pop(ret_contacts); + + return ret_contacts; + }else{ + throw new Exception("rpc sync call error, function:" ~ bindFunc); + } + } + + + alias RpcgetContactListCallback = void delegate(contacts); + + void getContactListInterface(string accountName, RpcgetContactListCallback rpcCallback, const RPC_PACKAGE_COMPRESS_TYPE compressType, const int secondsTimeOut, string bindFunc = __FUNCTION__){ + + auto req = new RpcRequest(compressType, secondsTimeOut); + + req.push(accountName); + + rpImpl.asyncCall(req, delegate(RpcResponse resp){ + + if(resp.getStatus == RESPONSE_STATUS.RS_OK){ + + contacts ret_contacts; + + resp.pop(ret_contacts); + + rpcCallback(ret_contacts); + }else{ + throw new Exception("rpc sync call error, function:" ~ bindFunc); + }}, bindFunc); + } + + + RpcClientImpl!(RpcAddressBookService) rpImpl; +} + + diff --git a/IDL-Example/client/kiss-testMessage.d b/IDL-Example/client/kiss-testMessage.d new file mode 100644 index 0000000..aba9876 --- /dev/null +++ b/IDL-Example/client/kiss-testMessage.d @@ -0,0 +1,57 @@ +module KissRpc.IDL.kiss-testMessage; +import std.typetuple; + + +struct UserInfo{ + + string[] addressList; + double wiget; + string phone; + int age; + string userName; + + TypeTuple!(string[], double, string, int, string, ) memberList; + + void createTypeTulple(){ + + memberList[0] = addressList; + memberList[1] = wiget; + memberList[2] = phone; + memberList[3] = age; + memberList[4] = userName; + } + + void restoreTypeTunlp(){ + + addressList = memberList[0]; + wiget = memberList[1]; + phone = memberList[2]; + age = memberList[3]; + userName = memberList[4]; + } + +} + + +struct contacts{ + + UserInfo[] userInfoList; + int number; + + TypeTuple!(UserInfo[], int, ) memberList; + + void createTypeTulple(){ + + memberList[0] = userInfoList; + memberList[1] = number; + } + + void restoreTypeTunlp(){ + + userInfoList = memberList[0]; + number = memberList[1]; + } + +} + + diff --git a/IDL-Example/client/kiss-testService.d b/IDL-Example/client/kiss-testService.d new file mode 100644 index 0000000..7cc640a --- /dev/null +++ b/IDL-Example/client/kiss-testService.d @@ -0,0 +1,32 @@ +module KissRpc.IDL.kiss-testService; + + +import KissRpc.IDL.kiss-testInterface; +import KissRpc.IDL.kiss-testMessage; + +import KissRpc.RpcClient; +import KissRpc.Unit; + +class RpcAddressBookService: RpcAddressBookInterface{ + + this(RpcClient rpClient){ + super(rpClient); + } + + contacts getContactList(string accountName, const RPC_PACKAGE_COMPRESS_TYPE compressType = RPC_PACKAGE_COMPRESS_TYPE.RPCT_NO, const int secondsTimeOut = RPC_REQUEST_TIMEOUT_SECONDS){ + + contacts ret = super.getContactListInterface(accountName, compressType, secondsTimeOut); + return ret; + } + + + void getContactList(string accountName, RpcgetContactListCallback rpcCallback, const RPC_PACKAGE_COMPRESS_TYPE compressType = RPC_PACKAGE_COMPRESS_TYPE.RPCT_NO, const int secondsTimeOut = RPC_REQUEST_TIMEOUT_SECONDS){ + + super.getContactListInterface(accountName, rpcCallback, compressType, secondsTimeOut); + } + + +} + + + diff --git a/README.md b/README.md index 82558ad..ddd5f2e 100755 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ 6. Support pipeline data compression, dynamic data compression, request data compression, flexible use of a wide range of scenarios. -###### 开发环境 +###### development environment * environment: Linux, UNIX, windows, macOS * transport protocol: capnproto(Install dependency Libraries:https://github.com/capnproto/capnproto) @@ -91,8 +91,8 @@ # IDL usage 1. [idl file path] [output file name] [output file path,default current dir] E."/root/home/kiss-rpc.idl" kiss-rpc "/root/home/rpc/" - - 2. At the same time output client and server file code, only need to copy to the corresponding client and server directory. + 2. module name output, module path is ".": E."/root/home/kiss-rpc.idl" module.test.kiss-rpc "/root/home/rpc/" + 3. At the same time output client and server file code, only need to copy to the corresponding client and server directory. # IDL Supported type diff --git a/dub.userprefs b/dub.userprefs index 33842b4..c590a69 100644 --- a/dub.userprefs +++ b/dub.userprefs @@ -1,15 +1,15 @@  - + - + - + @@ -17,6 +17,8 @@ + + diff --git a/kiss-rpc-idl/KissRpcIdl b/kiss-rpc-idl/KissRpcIdl index 7bff11b..3e87f9a 100755 Binary files a/kiss-rpc-idl/KissRpcIdl and b/kiss-rpc-idl/KissRpcIdl differ diff --git a/kiss-rpc-idl/README.md b/kiss-rpc-idl/README.md index 3ed20ba..8a486cc 100755 --- a/kiss-rpc-idl/README.md +++ b/kiss-rpc-idl/README.md @@ -1,8 +1,8 @@ # IDL usage 1. [idl file path] [output file name] [output file path,default current dir] E."/root/home/kiss-rpc.idl" kiss-rpc "/root/home/rpc/" - - 2. At the same time output client and server file code, only need to copy to the corresponding client and server directory. + 2. module name output, module path is ".": E."/root/home/kiss-rpc.idl" module.test.kiss-rpc "/root/home/rpc/" + 3. At the same time output client and server file code, only need to copy to the corresponding client and server directory. # IDL Supported type diff --git a/kiss-rpc-idl/dub.userprefs b/kiss-rpc-idl/dub.userprefs index 26e248c..160bf86 100644 --- a/kiss-rpc-idl/dub.userprefs +++ b/kiss-rpc-idl/dub.userprefs @@ -3,14 +3,15 @@ - - - + + + - - + + + diff --git a/kiss-rpc-idl/source/IDL/IdlParse.d b/kiss-rpc-idl/source/IDL/IdlParse.d index 7e96060..f086d6f 100644 --- a/kiss-rpc-idl/source/IDL/IdlParse.d +++ b/kiss-rpc-idl/source/IDL/IdlParse.d @@ -196,6 +196,21 @@ class idl_parse structCode ~= v.createCodeForLanguage(CODE_LANGUAGE.CL_DLANG); } + auto modulePath = split(fileName, "."); + + if(modulePath.length > 1) + { + for(int i = 0; i < modulePath.length-1; ++i) + { + outFilePath ~= ("/" ~ modulePath[i]); + if(!exists(outFilePath)) + mkdir(outFilePath); + } + + fileName = modulePath[modulePath.length-1]; + } + + if(!exists(outFilePath ~ "/server/")) mkdir(outFilePath ~ "/server/"); diff --git a/kiss-rpc-idl/source/IDL/IdlStructCreateCode.d b/kiss-rpc-idl/source/IDL/IdlStructCreateCode.d index e1d2b92..c31bb78 100644 --- a/kiss-rpc-idl/source/IDL/IdlStructCreateCode.d +++ b/kiss-rpc-idl/source/IDL/IdlStructCreateCode.d @@ -5,6 +5,9 @@ import IDL.IdlUnit; import std.array : appender; import std.format; +import std.algorithm.iteration : map; +import std.numeric : entropy; +import std.algorithm.sorting; class IdlStructDlangCode { @@ -13,15 +16,18 @@ class IdlStructDlangCode auto strings = appender!string(); formattedWrite(strings, "struct %s{\n\n", idlStructInterface.structName); - foreach(k, v; idlStructInterface.memberAttrInfo) + + for(int i =1; i <= idlStructInterface.memberAttrInfo.length; ++i) { + auto v = idlStructInterface.memberAttrInfo[i]; formattedWrite(strings, "\t%s %s;\n", v.typeName, v.memberName); } auto memberList_str = appender!string(); - foreach(k,v; idlStructInterface.memberAttrInfo) + for(int i =1; i <= idlStructInterface.memberAttrInfo.length; ++i) { + auto v = idlStructInterface.memberAttrInfo[i]; formattedWrite(memberList_str, "%s, ", v.typeName); } @@ -31,8 +37,9 @@ class IdlStructDlangCode int index = 0; - foreach(k, v; idlStructInterface.memberAttrInfo) + for(int i =1; i <= idlStructInterface.memberAttrInfo.length; ++i) { + auto v = idlStructInterface.memberAttrInfo[i]; formattedWrite(strings, "\t\tmemberList[%s] = %s;\n", index++, v.memberName); } @@ -41,8 +48,9 @@ class IdlStructDlangCode formattedWrite(strings, "\tvoid restoreTypeTunlp(){\n\n"); index = 0; - foreach(k, v; idlStructInterface.memberAttrInfo) + for(int i =1; i <= idlStructInterface.memberAttrInfo.length; ++i) { + auto v = idlStructInterface.memberAttrInfo[i]; formattedWrite(strings, "\t\t%s = memberList[%s];\n", v.memberName, index++); } diff --git a/test/client/KissRpcClient b/test/client/KissRpcClient index b3a3ef2..80743c4 100755 Binary files a/test/client/KissRpcClient and b/test/client/KissRpcClient differ diff --git a/test/client/source/app.d b/test/client/source/app.d index 347cf0c..70adc6d 100644 --- a/test/client/source/app.d +++ b/test/client/source/app.d @@ -15,7 +15,7 @@ import KissRpc.Unit; import std.conv; static int testNum = 500000; - +static int atestNum = 100000; class ClientSocket : ClientSocketEventInterface { @@ -44,7 +44,7 @@ class ClientSocket : ClientSocketEventInterface for(int i= 1; i <= testNum; ++i) { UserInfo user; - user.name = "jasonsalex1111111111111111111111111111111111111111111111111111111111111111111112222222222222222222222222222222222222222222222222222222223333333333333333333333333333333333333333333344444444444444444444444444444444444444444444444444444445555555555555555555555555555555555555555555555555555555555555555555566666666666666666666666666666666666666666666666666666666666666666666666666777777777777777777777777777777777777777777777777777fdsafadsfadsfadsfadsvcvcbgdfghfgdasfaewtraewtregafgdfagafdasfkljdhasgkjhafkjhadfdkjashfdkjashfhawjuyfaueiwfhdsfkjldhasfkjdhasfkjdhasfkljdasfkljvnc"; + user.name = "jasonsalex"; user.i = i; try{ @@ -73,10 +73,10 @@ class ClientSocket : ClientSocketEventInterface writefln("start async test......................."); - for(int i= 1; i <= testNum; ++i) + for(int i= 1; i <= atestNum; ++i) { UserInfo user; - user.name = "jasonsalex1111111111111111111111111111111111111111111111111111111111111111111112222222222222222222222222222222222222222222222222222222223333333333333333333333333333333333333333333344444444444444444444444444444444444444444444444444444445555555555555555555555555555555555555555555555555555555555555555555566666666666666666666666666666666666666666666666666666666666666666666666666777777777777777777777777777777777777777777777777777fdsafadsfadsfadsfadsvcvcbgdfghfgdasfaewtraewtregafgdfagafdasfkljdhasgkjhafkjhadfdkjashfdkjashfhawjuyfaueiwfhdsfkjldhasfkjdhasfkjdhasfkljdasfkljvnc,nkvbncmzkvndkjashfdasklfhaewokgfjriuewrt34eofjdsfkldasjfkldsa"; + user.name = "jasonaslex"; user.i = i; try{ @@ -87,10 +87,10 @@ class ClientSocket : ClientSocketEventInterface writefln("ret:%s, request:%s, time:%s", s, s.i, Clock.currStdTime().stdTimeToUnixTime!(long)() - startTime); } - if(s.i == testNum) + if(s.i == atestNum) { time = Clock.currStdTime().stdTimeToUnixTime!(long)() - startTime; - writefln("async test, total request:%s, time:%s, QPS:%s", s.i, time, testNum/time); + writefln("async test, total request:%s, time:%s, QPS:%s", s.i, time, atestNum/time); } }); diff --git a/test/client_mutil_connects/KissRpcMutilClient b/test/client_mutil_connects/KissRpcMutilClient index a2d1877..7a59746 100755 Binary files a/test/client_mutil_connects/KissRpcMutilClient and b/test/client_mutil_connects/KissRpcMutilClient differ diff --git a/test/client_mutil_connects/source/app.d b/test/client_mutil_connects/source/app.d index f234411..994ebf5 100644 --- a/test/client_mutil_connects/source/app.d +++ b/test/client_mutil_connects/source/app.d @@ -16,7 +16,7 @@ import kiss.event.GroupPoll; import std.conv; -shared static int testNum = 1000; +shared static int testNum = 500; shared static int clientNum = 1000; shared static long startAllTime; diff --git a/test/server/KissRpcServer b/test/server/KissRpcServer index 77d5a22..0ef841e 100755 Binary files a/test/server/KissRpcServer and b/test/server/KissRpcServer differ