Exemplo n.º 1
0
void SsdpListenerMulticast::Run()
{
    Signal();
    for (;;) {
        iReaderRequest.Flush();

        try {
            LOG(kSsdpMulticast, "SSDP Multicast      Listen\n");
            iReaderRequest.Read(0);
            if (iReaderRequest.Version() == Http::eHttp11) {
                if (iReaderRequest.Uri() == Ssdp::kMethodUri) {
                    const Brx& method = iReaderRequest.Method();
                    if (method == Ssdp::kMethodNotify) {
                        LOG(kSsdpMulticast, "SSDP Multicast      Notify\n");
                        iLock.Wait();
                        EraseDisabled(iNotifyHandlers);
                        VectorNotifyHandler callbacks;
                        TUint count = (TUint)iNotifyHandlers.size();
                        for (TUint i=0; i<count; i++) {
                            callbacks.push_back(iNotifyHandlers[i]);
                        }
                        iLock.Signal();
                        for (TUint i = 0; i<count; i++) {
                            Notify(*(callbacks[i]));
                        }
                    }
                    else if (method == Ssdp::kMethodMsearch) {
                        LOG(kSsdpMulticast, "SSDP Multicast      Msearch\n");
                        iLock.Wait();
                        EraseDisabled(iMsearchHandlers);
                        VectorMsearchHandler callbacks;
                        TUint count = (TUint)iMsearchHandlers.size();
                        for (TUint i=0; i<count; i++) {
                            callbacks.push_back(iMsearchHandlers[i]);
                        }
                        iLock.Signal();
                        for (TUint i = 0; i<count; i++) {
                            Msearch(*(callbacks[i]));
                        }
                    }
                }
            }
        }
        catch (HttpError&) {
            LOG2(kSsdpMulticast, kError, "SSDP Multicast      HttpError\n");
        }
        catch (WriterError&) {
            LOG2(kSsdpMulticast, kError, "SSDP Multicast      WriterError\n");
        }
        catch (ReaderError&) {
            LOG2(kSsdpMulticast, kError, "SSDP Multicast      ReaderError\n");
            if (iExiting) {
                break;
            }
        }
    }
}
Exemplo n.º 2
0
void SsdpListenerMulticast::EraseDisabled(VectorMsearchHandler& aVector)
{
    VectorMsearchHandler::iterator it = aVector.begin();
    while (it != aVector.end()) {
        MsearchHandler* handler = reinterpret_cast<MsearchHandler*>(*it);
        handler->Lock();
        if (handler->IsDisabled()) {
            handler->Unlock();
            delete handler;
            it = aVector.erase(it);
        }
        else {
            handler->Unlock();
            it++;
        }
    }
}
Exemplo n.º 3
0
void SsdpListenerMulticast::Run()
{
    Signal();
    for (;;) {
        iReaderRequest.Flush();

        try {
            LOG(kSsdpMulticast, "SSDP Multicast      Listen\n");
            iReaderRequest.Read(0);
            if (iReaderRequest.Version() == Http::eHttp11) {
                if (iReaderRequest.Uri() == Ssdp::kMethodUri) {
                    const Brx& method = iReaderRequest.Method();
                    if (method == Ssdp::kMethodNotify) {
                        LOG(kSsdpMulticast, "SSDP Multicast      Notify\n");
                        iLock.Wait();
                        EraseDisabled(iNotifyHandlers);
                        VectorNotifyHandler callbacks;
                        TUint count = (TUint)iNotifyHandlers.size();
                        for (TUint i=0; i<count; i++) {
                            callbacks.push_back(iNotifyHandlers[i]);
                        }
                        iLock.Signal();
                        for (TUint i = 0; i<count; i++) {
                            Notify(*(callbacks[i]));
                        }
                    }
                    else if (method == Ssdp::kMethodMsearch) {
                        LOG(kSsdpMulticast, "SSDP Multicast      Msearch\n");
                        iLock.Wait();
                        EraseDisabled(iMsearchHandlers);
                        VectorMsearchHandler callbacks;
                        TUint count = (TUint)iMsearchHandlers.size();
                        for (TUint i=0; i<count; i++) {
                            callbacks.push_back(iMsearchHandlers[i]);
                        }
                        iLock.Signal();
                        for (TUint i = 0; i<count; i++) {
                            Msearch(*(callbacks[i]));
                        }
                    }
                }
            }
        }
        catch (HttpError& ex) {
            Endpoint::EndpointBuf epb;
            iSocket.Sender().AppendEndpoint(epb);
            epb.PtrZ();
            try {
                Brn buf = iReaderUntil.Read(kMaxBufferBytes);
                LOG2(kSsdpMulticast, kError, "SSDP Multicast      HttpError (sender=%s) from %s:%u.  Received: %.*s\n\n",
                                             (const char*)epb.Ptr(), ex.File(), ex.Line(), PBUF(buf));
            }
            catch (ReaderError&) {
            }
        }
        catch (WriterError&) {
            LOG2(kSsdpMulticast, kError, "SSDP Multicast      WriterError\n");
        }
        catch (ReaderError&) {
            LOG2(kSsdpMulticast, kError, "SSDP Multicast      ReaderError\n");
            if (iExiting) {
                break;
            }
        }
        if (iRecreateSocket) {
            try {
                iSocket.Interrupt(false);
                iSocket.ReCreate();
                iRecreateSocket = false;
            }
            catch (NetworkError&) {
                LOG2(kSsdpMulticast, kError, "SSDP Multicast      failed to recreate socket after library Resumed\n");
            }
        }
    }
}