OsclAcceptMethod::~OsclAcceptMethod()
{
    if (AcceptRequest())
    {
        AcceptRequest()->~OsclAcceptRequest();
        Alloc().deallocate(AcceptRequest());
    }
    DiscardAcceptedSocket();
}
示例#2
0
void CStdPoolOfThreads::KillAllThreads(TKillFlags flags)
{
    TACValue n, old_max;
    bool queuing_was_forbidden;
    {{
        CMutexGuard guard(m_Mutex);
        old_max = m_MaxThreads;
        queuing_was_forbidden = m_QueuingForbidden;
        m_MaxThreads = 0;  // Forbid spawning new threads
        m_QueuingForbidden = false; // Always queue normally here.
        n = m_ThreadCount.Get(); // Capture for use without mutex
    }}

    {{
        TACValue n2 = TACValue(m_Threads.size());
        if (n != n2) {
            ERR_POST(Warning << "Registered " << n2 << " threads but expected "
                     << n);
            if (n < n2) {
                n = n2;
            }
        }
    }}

    CRef<CStdRequest> poison(new CFatalRequest);

    for (TACValue i = 0;  i < n;  ) {
        try {
            WaitForRoom();
            AcceptRequest(poison);
            ++i;
        } catch (CBlockingQueueException&) { // guard against races
            continue;
        }
    }
    NON_CONST_ITERATE(TThreads, it, m_Threads) {
        if ((flags & fKill_Wait) != 0) {
            (*it)->Join();
        } else {
            (*it)->Detach();
        }
    }
    m_Threads.clear();
    CMutexGuard guard(m_Mutex);
    m_QueuingForbidden = queuing_was_forbidden;
    if ((flags & fKill_Reopen) != 0) {
        m_MaxThreads = old_max;
    }
}
示例#3
0
void
CPoolOfThreads_ForServer::KillAllThreads(bool wait)
{
    m_KilledAll = true;

    CRef<CStdRequest> poison(new CFatalRequest_ForServer);

    for (TACValue i = 0;  i < m_MaxThreads; ++i) {
        AcceptRequest(poison);
    }
    NON_CONST_ITERATE(TThreads, it, m_Threads) {
        if (wait) {
            (*it)->Join();
        } else {
            (*it)->Detach();
        }
    }
    m_Threads.clear();
}
TPVSocketEvent OsclAcceptMethod::Accept(int32 aTimeout)
{
    //in case previous accepted socket was never
    //retrieved...
    DiscardAcceptedSocket();

    iAcceptedSocket = OsclSocketI::NewL(Alloc());

    if (iAcceptedSocket->Open(*SocketServ()) != OsclErrNone)
    {
        DiscardAcceptedSocket();
        return EPVSocketFailure;
    }

    if (!StartMethod(aTimeout))
    {
        DiscardAcceptedSocket();
        return EPVSocketFailure;
    }

    AcceptRequest()->Accept(*iAcceptedSocket);
    return EPVSocketPending;
}