passing arguments in asyncronous server

Login to reply to this topic.
Wed, 2008-05-21 05:27
Joined: 2007-08-28
Forum posts: 23

my server was synchronous it was working fine. but now i have made it asynchronus by making these changes
1. i have set the message slots to 2 ( a i can make two request pending) while creating the session i.e createsession in client.
2. made one asyncronous function having trequeststatus, i have made the descriptor which i am passing from the client as a member variable of the client.
3. i m handling the asyncronous request in the server side.

but the problem is : the descriptor which i am passing in the asyncronous function from client is not getting passed to the server side( server is handling async request). in server side i m getting junck value in the descriptor.


Wed, 2008-05-21 06:42
Joined: 2007-11-16
Forum posts: 26
Re: passing arguments in asyncronous server

Smiling

EXPORT_C void RCryptoSrv::EncryptL( TInt aVal, TRequestStatus& aStatus )
{
iVal = aVal;
//TPckg<TInt> pkcgVal( iVal );
iTestArgs.Set(0,iVal);
SendReceive( EEncryptFile, iTestArgs, aStatus );
}

Try above code for sending an integer...

I feel as you are using asynchronous communication the TPckg will be destroyed as go out of function and your 0 argument pointer will be pointing to some junk values.

Pramod


"Nobody will believe in you unless you believe in yourself."

Wed, 2008-05-21 07:23
Joined: 2007-08-28
Forum posts: 23
Re: passing arguments in asyncronous server

thanks for the reply.
yes u r saying it correct. when i am packaging the data. it is getting destroyed.
but if i want to pass some strut then i need to package it.
some solution for that.

Wed, 2008-05-21 08:14
Joined: 2007-11-16
Forum posts: 26
Re: passing arguments in asyncronous server

make TPckg var as member varible

TPckg<mystruct> iPkcgVal;

EXPORT_C void RCryptoSrv::EncryptL( mystruct& aMyStruct, TRequestStatus& aStatus )
{
iPkcgVal( aMyStruct);
iTestArgs.Set(0,&iPkcgVal);
SendReceive( EEncryptFile, iTestArgs, aStatus );
}

Try this


"Nobody will believe in you unless you believe in yourself."

Wed, 2008-05-21 13:11
Joined: 2007-08-28
Forum posts: 23
Re: passing arguments in asyncronous server

thanks for the replies ...
but lastly i have found the mistake i was making ...
actually the reason behind this what i found is :
it is not working in case of asyncronous request coz in async the kernel takes the value from the
address space of client and directly reading value causes in some descriptor results in junk value i.e
aMessage.ReadL( 0, des) so take the values in proper pointers rather than using aMessage.ReadL( 0, des )
coz kernel resolve the address values which are passed from client to server.
and passing values from the client use member variable not local variables.
client side:
typedef RArray RFolderList;
EXPORT_C void RClient::Fun( RFolderList& aFolderList, TRequestStatus& aStatus )
{
iFolderList = aFolderList;
iFolderListPckg = new(ELeave) TPckgC(iFolderList);

TInt n = iFolderList.Count();
iArgs.Set( 0, iFolderListPckg );
SendReceive( EEncryptFile, iArgs, aStatus );
}

server side:
void CServerSession::Fun(const RMessage2& aMessage)
{

TPckg des1(iFolderList);
TPckg* des;
des = (TPckg*)aMessage.Ptr0();();//pointer is used in place of ReadL()
des1.Copy(*des);
TInt count;
for( count = 0; count< iFolderList.Count(); count++ )
{
TBuf<50> fileName;
fileName = iFolderList[count];
SomeFun(fileName);
}
}

Thu, 2008-05-22 09:48
Joined: 2004-11-29
Forum posts: 1156
Re: passing arguments in asyncronous server

mearunsingh:
Nope, that is not good code.

You will have a memory leak each time you send a message.

Why don't you just do as the previous poster suggest, and put the TPckgC as a member variable?

Make the iFolderListPckg not being a pointer, and just use an assignment:

iFolderListPckg = TPckgC(iFolderList);

And what is wrong with ReadL?

Also, you can't send over R-objects like that... you won't get the actual array over, so your app will crash as soon as you try to use it.
unless your server is in a thread in the same process as your client, and not in its own process.
Then it just has a risk of crashing when you change the array on the client side...

Thu, 2008-07-03 12:31
Joined: 2007-08-28
Forum posts: 23
Re: passing arguments in asyncronous server

hi
alh

i am passing the rarray from client side to server side by marshalling it. and on the server side i am not able to retrive the data on the server side.i have checkd that the data on the client side marshalled properly.
code snippet is

client side
EXPORT_C void RClient::FolderListL( RFolderList& aFolderList )
{

iData = NULL;
iData = HBufC8::NewL(100);
TRAPD ( err, iData = iCryptoData->MarshalDataL( aFolderList ) )
if( iData )
{
TPtr8 ptr(iData->Des());
// TIpcArgs args(&ptr);
iArgs.Set( 0,&ptr );
SendReceive( ESetFolderList, iArgs, iStatus);
}
}

on the server side :
void CCSession::GetFolder(const RMessage2& aMessage)
{
TInt clientDesMaxLen;
clientDesMaxLen = aMessage.GetDesMaxLength(0) // failing here...as the data is not passed properly
HBufC8* desData = HBufC8::NewLC(clientDesMaxLen);
TPtr8 readPtr(desData->Des());
aMessage.ReadL(0, readPtr);
RFolderList folderList;
iData = CCryptoData::NewL();
iData->UnMardhalDataL(*desData, folderList);
}

Thu, 2008-07-03 15:06
Joined: 2004-11-29
Forum posts: 1156
Re: passing arguments in asyncronous server

Here you do the same mistake again:

{
TPtr8 ptr(iData->Des());
// TIpcArgs args(&ptr);
iArgs.Set( 0,&ptr );
SendReceive( ESetFolderList, iArgs, iStatus);
}

The ptr object is on the stack, and will go out of scope before the server can access it.

Thu, 2008-07-03 15:16
Joined: 2007-08-28
Forum posts: 23
Re: passing arguments in asyncronous server

thanks for the reply . i have got that.

Thu, 2008-07-03 15:16
Joined: 2007-08-28
Forum posts: 23
Re: passing arguments in asyncronous server

thanks for the reply . i have got that.

Thu, 2008-07-03 15:16
Joined: 2007-08-28
Forum posts: 23
Re: passing arguments in asyncronous server

thanks for the reply . i have got that.

Thu, 2008-07-03 15:16
Joined: 2007-08-28
Forum posts: 23
Re: passing arguments in asyncronous server

thanks for the reply . i have got that.

Fri, 2008-07-04 11:48
Joined: 2007-08-28
Forum posts: 23
Re: passing arguments in asyncronous server

in emulator things are working properly but in device data is not passed from client to server.
i am marshalling the data(RArray list of TFileName) in the client side and un-marshalling the data on the server side.

client side:
aFolderList is RArray
RBuf iData;

Clinet( aFolderList )
{
iData.Create(100);
iFolderCount = aFolderList.Count();
iData.Copy( iCryptoData->MarshalDataL( aFolderList ) );
iArgs.Set( 0,&iData );
iArgs.Set( 1, iFolderCount);

SendReceive( ESetFolderList, iArgs, iStatus );
}

server side:

in session(const RMessage2& aMessage)
{
TInt clientDesMaxLen;
clientDesMaxLen = aMessage.GetDesMaxLength(0);
HBufC8* desData = HBufC8::NewLC(clientDesMaxLen);// in device it fails here means len is not proper
TPtr8 readPtr(desData->Des());
aMessage.ReadL(0, readPtr);
TInt folderCount = aMessage.Int1();
RArray folderList;
iData = CCryptoData::NewL();
iData->UnMardhalDataL(*desData, folderList, folderCount);
}

above code is working fine in emulator but in device in server side it fails.
so can u please tell me how to pass the data(folder list) in different processes (i.e client server)

Fri, 2008-07-04 15:10
Joined: 2004-11-29
Forum posts: 1156
Re: passing arguments in asyncronous server

IPC can be tricky when you want to send lots of data over...

What is the length returned from GetDesMaxLength?

If its a negative value (most commonly -38, KErrBadDescriptor) then the problem is probably in how you send the descriptor

If its positive, maybe you have some OOM-problems on target, if the heap in your server is too small?

I also notice you don't delete your desData afterwards, maybe you have a leak here?

Overall, to me, it looks like your code should work though... It working on emu but not on target makes it feel a bit like OOM.

Only one weirdness, shouldn't the RBuf be a RBuf8?

Two notes though:
- the TIpcArgs itself, can live on stack, it is copied by the kernel when sending the message. Problem is with pointers stored in it.
- You can probably rewrite this to save one rather big copy on this line:

iData.Copy( iCryptoData->MarshalDataL( aFolderList ) );

Easiest way to do that would probably be to simply rewrite your MarshalDataL to take a RBuf reference, and fill it up directly, instead of going through a HBufC.

Fri, 2008-07-04 15:21
Joined: 2007-08-28
Forum posts: 23
Re: passing arguments in asyncronous server

thanks for the reply ...
the code is working properly on the device ....above code is fine ..due to some binary mismatch things were not working in the e50.

  • Login to reply to this topic.