Wednesday, February 3, 2016

Survival issue heap and stack (C / S mode communications)





I wrote based on client - server (C / S) mode of application (not the network communication). Its main features are: a server running in the background (EXE), client run in the foreground (APP). Client requests to the server, then the server transmits the processed data to the client. You can normally run on the simulator, no problem, it is possible to achieve the desired effect. However, one put the phone on the big issues: First, the client can send a message to the server, the server response can also receive messages, but once the time for data communication, which uses RMessage writeback data when it quits unexpectedly .
Client - server communication part of the code:
// AStateMsg structure and imsg are customizable (TStateMsg) type, inside a 4 TINT type data.
// CLIENT
iStateBuffer.Set (reinterpret_cast & lt; TUint8 * & gt; (& amp; aStateMsg), sizeof (aStateMsg),
sizeof (aStateMsg));
messageParameters [0] = static_cast & lt; TAny * & gt; (& amp; iStateBuffer);
SendReceive (ERequstState, & amp; messageParameters [0], aStatus);

// SERVER
TPtr8 ptr (reinterpret_cast & lt; TUint8 * & gt; (& amp; imsg), sizeof (imsg),
sizeof (imsg));


TRAPD (err, iMessage.WriteL (iMessage.Ptr0 (), ptr));
if (err)
{

PanicClient (EBadDescriptor);

}
iMessage.Complete (ERequestComplete);
After the term "efficiency program," it says, is passed to the asynchronous request client data it must not be based on the stack, so I will repair
client code
Changed as follows:

HBufC8 * hbuf = HBufC8 :: NewLC (sizeof (aStateMsg));
TPtr8 ptr = hbuf- & gt; Des ();
messageParameters [0] = static_cast & lt; TAny * & gt; (& amp; ptr);
This time in the simulator can not run (compiled by), but also to the time to write back data to quit unexpectedly. I do not know heap-based data transfer is not my wording above? Please Supreme pointing.
Also, I finally just put the asynchronous mode to synchronous mode, and in the simulator is operating normally, put it on the phone is also abnormal exit.
I really Meizhe erupted, synchronous, asynchronous not work, is it this way IPC unavailable on the phone? Anybody know?
Reply:
Why did you first messageParameters [0] which put the iStateBuffer address, the second time to become a ptr address?
You messageParameters [0] in the end what to put inside?
Reply:
Give a code to study it? btsy2000@hotmail.com
Reply:
You used to get a bigger stack variables, I suspect that much of a reason to return data
Reply:

HBufC8 * hbuf = HBufC8 :: NewLC (sizeof (aStateMsg));

TPtr8 ptr = hbuf- & gt; Des ();
messageParameters [0] = static_cast & lt; TAny * & gt; (& amp; ptr); // this you pass the stack variables



You either pass HBufC8 * in, or transfer raw data buffer + size inside. But how to explain it all depends on the server into the data transfer.



HBufC8 * hbuf = HBufC8 :: NewLC (sizeof (aStateMsg));
messageParameters [0] = static_cast & lt; TAny * & gt; (hbuf- & gt; Des () Ptr ().);

messageParameters [1] = sizeof (aStateMsg);

Or

messageParameters [0] = static_cast & lt; TAny * & gt; (hbuf)

Reply:
Check the rest of the code is not necessarily a problem to find a place.

No comments:

Post a Comment