Skip to content

Commit

Permalink
fix bugs for idl
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Jul 17, 2017
1 parent ba26278 commit 966704e
Show file tree
Hide file tree
Showing 15 changed files with 203 additions and 24 deletions.
64 changes: 64 additions & 0 deletions IDL-Example/client/kiss-testInterface.d
Original file line number Diff line number Diff line change
@@ -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;
}


57 changes: 57 additions & 0 deletions IDL-Example/client/kiss-testMessage.d
Original file line number Diff line number Diff line change
@@ -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];
}

}


32 changes: 32 additions & 0 deletions IDL-Example/client/kiss-testService.d
Original file line number Diff line number Diff line change
@@ -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);
}


}



6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions dub.userprefs
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
<Properties StartupItem="dub.json">
<MonoDevelop.Ide.Workspace ActiveConfiguration="Default" PreferredExecutionTarget="cov" />
<MonoDevelop.Ide.Workbench ActiveDocument="source/KissRpc/Unit.d">
<MonoDevelop.Ide.Workbench ActiveDocument="source/KissRpc/RpcSendPackageManage.d">
<Files>
<File FileName="source/KissRpc/RpcSendPackageManage.d" Line="1" Column="1" />
<File FileName="source/KissRpc/RpcSendPackageManage.d" Line="98" Column="55" />
<File FileName="source/KissRpc/RpcRequest.d" Line="1" Column="1" />
<File FileName="source/KissRpc/RpcResponse.d" Line="1" Column="1" />
<File FileName="source/KissRpc/RpcCapnprotoPackage.d" Line="1" Column="1" />
<File FileName="source/KissRpc/RpcCapnprotoPayload.d" Line="1" Column="1" />
<File FileName="source/KissRpc/RpcRecvPackageManage.d" Line="1" Column="1" />
<File FileName="source/util/snappy.d" Line="1" Column="1" />
<File FileName="source/KissRpc/RpcServer.d" Line="1" Column="1" />
<File FileName="source/KissRpc/RpcServer.d" Line="53" Column="29" />
<File FileName="source/KissRpc/Logs.d" Line="1" Column="1" />
<File FileName="source/KissRpc/Unit.d" Line="10" Column="48" />
<File FileName="source/KissRpc/RpcSocketBaseInterface.d" Line="1" Column="1" />
<File FileName="source/KissRpc/RpcServerImpl.d" Line="1" Column="1" />
<File FileName="source/KissRpc/RpcBinaryPackage.d" Line="126" Column="19" NotebookId="1" />
<File FileName="source/KissRpc/RpcClient.d" Line="1" Column="1" NotebookId="1" />
<File FileName="source/KissRpc/Endian.d" Line="1" Column="1" NotebookId="1" />
<File FileName="source/KissRpc/RpcClientImpl.d" Line="1" Column="1" NotebookId="1" />
<File FileName="../../../Projects/grpc/examples/cpp/helloworld/greeter_async_client2.cc" Line="1" Column="1" NotebookId="1" />
</Files>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints>
Expand Down
Binary file modified kiss-rpc-idl/KissRpcIdl
Binary file not shown.
4 changes: 2 additions & 2 deletions kiss-rpc-idl/README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 6 additions & 5 deletions kiss-rpc-idl/dub.userprefs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
<MonoDevelop.Ide.Workbench ActiveDocument="source/IDL/IdlParse.d">
<Files>
<File FileName="source/IDL/IdlBaseInterface.d" Line="1" Column="1" />
<File FileName="source/IDL/IdlInerfaceCreateCode.d" Line="185" Column="96" />
<File FileName="source/IDL/IdlParse.d" Line="176" Column="40" />
<File FileName="source/app.d" Line="1" Column="1" />
<File FileName="source/IDL/IdlInerfaceCreateCode.d" Line="1" Column="1" />
<File FileName="source/IDL/IdlParse.d" Line="207" Column="25" />
<File FileName="source/app.d" Line="19" Column="3" />
<File FileName="source/IDL/IdlUnit.d" Line="1" Column="1" />
<File FileName="source/IDL/IdlSymbol.d" Line="1" Column="1" />
<File FileName="source/IDL/IdlStructCreateCode.d" Line="1" Column="1" />
<File FileName="source/IDL/IdlParseStruct.d" Line="1" Column="1" />
<File FileName="source/IDL/IdlParseStruct.d" Line="107" Column="13" />
<File FileName="source/IDL/IdlParseInterface.d" Line="1" Column="1" />
<File FileName="dub.json" Line="1" Column="1" />
<File FileName="source/IDL/IdlStructCreateCode.d" Line="45" Column="3" NotebookId="1" />
</Files>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints>
Expand Down
15 changes: 15 additions & 0 deletions kiss-rpc-idl/source/IDL/IdlParse.d
Original file line number Diff line number Diff line change
Expand Up @@ -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/");

Expand Down
16 changes: 12 additions & 4 deletions kiss-rpc-idl/source/IDL/IdlStructCreateCode.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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++);
}

Expand Down
Binary file modified test/client/KissRpcClient
Binary file not shown.
12 changes: 6 additions & 6 deletions test/client/source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import KissRpc.Unit;
import std.conv;

static int testNum = 500000;

static int atestNum = 100000;

class ClientSocket : ClientSocketEventInterface
{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand All @@ -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);
}

});
Expand Down
Binary file modified test/client_mutil_connects/KissRpcMutilClient
Binary file not shown.
2 changes: 1 addition & 1 deletion test/client_mutil_connects/source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Binary file modified test/server/KissRpcServer
Binary file not shown.

0 comments on commit 966704e

Please sign in to comment.