Symbian
Symbian Developer Library

SYMBIAN OS V9.4

Feedback

[Index] [Previous] [Next]


CEchoRead class

CEchoRead wraps an asynchronous read socket call (RSocket::Recv()) in an active object. The request is made by IssueRead():

void CEchoRead::IssueRead()
// Read data from a stream socket
    {
    if (!IsActive())
        {
        iEchoSocket->Recv(iBuffer, 0, iStatus);
        SetActive();
        };
    };

We only want to read characters one at a time, so the data buffer iBuffer in which the read call returns the data is defined in CEchoRead as:

TBuf<1> iBuffer;

As CEchoRead is an active object, we implement a request complete handler in RunL():

void CEchoRead::RunL()
    {
    if (iStatus == KErrNone)
        {
        _LIT(KDot,".");
        iConsole->PrintNotify(KDot);
        iConsole->PrintNotify(iBuffer);
        IssueRead();
        }
    else
        {
        //Pass error up
        _LIT(KCEchoReadError,"\nCEchoRead Error: ");
        iConsole->ErrorNotify(KCEchoReadError, iStatus.Int());
        }    
    };

If no error occurs, we simply ask the user interface to print the character separated by a dot, and then renew the read request to get the next character. In the case of an error, as before, we inform the user interface of this.