Symbian: clear buffer of RSocket object
I need to go back to Symbian sockets again. The code for setting up a connection to a remote server looks like this:
TInetAddr serverAddr;
TUint iPort=111;
TRequestStatus iStatus;
TSockXfrLength len;
TInt res = iSocketSrv.Connect();
res = iSocket.Open(iSocketSrv,KAfInet,KSockStream, KProtocolInetTcp);
res = iSocket.SetOpt(KSoTcpSendWinSize, KSolInetTcp, 0x10000);
serverAddr.SetPort(iPort);
serverAddr.SetAddress(INET_ADDR(11,11,179,154));
iSocket.Connect(serverAddr,iStatus);
User::WaitForRequest(iStatus);
In iSocket, I get variable size packets. In a very few cases, it happens that such a package is damaged. What I would like to do is clear all data that is currently in the iSocket buffer and be ready to read. I have not seen any RSocket method that allows me to flush the contents of a buffer. Does anyone know how to do this? If possible, I would like to avoid using RecvOneOrMore () or a similar recv function to clear the buffer
thank
You don't have to do what you ask. Receiving corrupted data is a sign that the application on the other end is malfunctioning, so this is an application-level problem, not a transport-level problem. You should, in your application protocol, which you built on top of TCP, include an explicit error message that you can use in this situation to communicate the other end of the situation (if you are trying to find some form of reliability). Since you apparently have certain message boundaries in your application protocol, there is no need to close the connection, just discard the corrupted message by reading the bytes to the next message boundary and continue processing normally from that point on.
Also, flushing the receive buffer would be the wrong thing to do, even if you can. TCP is a byte stream protocol, so it has no concept of message boundaries. At any given moment, the receive buffer will contain a few bytes, which does not guarantee any correspondence to the application's message boundaries, so flushing can get rid of many correct messages and possibly leave only a partial message for the next read. (This is a common mistake made by novice network programmers, by the way, because if your application only communicates very infrequently, it may seem like TCP is being preserved by message boundaries. But it does, and assuming it really bites you.)
source to share