void OsclSocketRequestAO::Run()
{
    //The server has completed the socket request.

    RequestDone();


    // Check the request completion status
    switch (Status())
    {
        case OSCL_REQUEST_ERR_NONE:
            ADD_STATS(iContainer.iSocketFxn, EOsclSocket_RequestAO_Success);
            Success();
            LOGINFOMED((0, "OsclSocket(0x%x): %s %s ", SocketI(), TPVSocketFxnStr[iContainer.iSocketFxn], TPVSocketEventStr[EPVSocketSuccess]));
            LOG_STATS(iContainer.iSocketFxn);
            CLEAR_STATS(iContainer.iSocketFxn);
            SocketObserver()->HandleSocketEvent(Id(), iContainer.iSocketFxn, EPVSocketSuccess, 0);
            break;

        case OSCL_REQUEST_ERR_CANCEL:
            ADD_STATS(iContainer.iSocketFxn, EOsclSocket_RequestAO_Canceled);
            //Request was cancelled, either due to an API call or due to the
            //socket server shutting down before completing the operation.
            LOGINFOMED((0, "OsclSocket(0x%x): %s %s ", SocketI(), TPVSocketFxnStr[iContainer.iSocketFxn], TPVSocketEventStr[EPVSocketCancel]));
            LOG_STATS(iContainer.iSocketFxn);
            CLEAR_STATS(iContainer.iSocketFxn);
            SocketObserver()->HandleSocketEvent(Id(), iContainer.iSocketFxn, EPVSocketCancel, 0);
            break;

        default:
            ADD_STATS(iContainer.iSocketFxn, EOsclSocket_RequestAO_Error);
            //Some error.
            LOGINFOMED((0, "OsclSocket(0x%x): %s %s %d", SocketI(), TPVSocketFxnStr[iContainer.iSocketFxn], TPVSocketEventStr[EPVSocketFailure], GetSocketError()));
            LOG_STATS(iContainer.iSocketFxn);
            CLEAR_STATS(iContainer.iSocketFxn);
            SocketObserver()->HandleSocketEvent(Id(), iContainer.iSocketFxn, EPVSocketFailure, GetSocketError());
            break;
    }
}
void OsclAcceptRequest::Accept(OsclSocketI &aSocket)
{
    OsclAny *p = NewRequest(sizeof(AcceptParam));
    if (!p)
        PendComplete(OsclErrNoMemory);
    else
    {
        iParam = OSCL_PLACEMENT_NEW(p, AcceptParam(aSocket));
        if (!iParam)
            PendComplete(OsclErrNoMemory);
        else
            SocketI()->Accept(*Param(), *this);
    }
}
void OsclSendToRequest::SendTo(const uint8* &aPtr, uint32 aLen, OsclNetworkAddress &aAddress)
{
    OsclAny *p = NewRequest(sizeof(SendToParam));
    if (!p)
        PendComplete(OsclErrNoMemory);
    else
    {
        iParam = OSCL_PLACEMENT_NEW(p, SendToParam(aPtr, aLen, aAddress, 0));
        if (!iParam)
            PendComplete(OsclErrNoMemory);
        else
            SocketI()->SendTo(*Param(), *this);
    }
}
void OsclConnectRequest::Connect(OsclNetworkAddress &aAddress)
{
    OsclAny *p = NewRequest(sizeof(ConnectParam));
    if (!p)
        PendComplete(OsclErrNoMemory);
    else
    {
        iParam = OSCL_PLACEMENT_NEW(p, ConnectParam(aAddress));
        if (!iParam)
            PendComplete(OsclErrNoMemory);
        else
        {
            SocketI()->Connect(*Param(), *this);
        }
    }
}
OsclAny* OsclSocketRequestAO::NewRequest(const uint32 size)
{
    //Activate the AO.  The socket server will complete the request.
    PendForExec();

    bool reallocate = (!iParam || size != iParamSize);

    //Cleanup any previous parameters.
    CleanupParam(reallocate);

    LOGINFOMED((0, "OsclSocket(0x%x): New Request %s", SocketI(), TPVSocketFxnStr[iContainer.iSocketFxn]));

    //Allocate space for new parameters, or recycle current space.
    if (reallocate)
    {
        iParamSize = size;
        return Alloc().ALLOCATE(size);
    }
    else
        return iParam;
}
void OsclSendToRequest::Success()
{
    SocketI()->SendToSuccess(*Param());
}