исключение выдается при отмене при использовании Ctrl + C - PullRequest
0 голосов
/ 04 июня 2018
pplx::task<void> RestInterface::Getsxxxx()

{
utility::stringstream_t ss;
pplx::cancellation_token_source cts;
pplx::cancellation_token ct = cts.get_token();

ss<<"http://"<<URL<<":"<<PORT<<PATH<<ZALL;

http_client client(U(ss.str()));

///here were using the jSON function for URI to request the REST API
///else the name of the API can be passed to stream also.
http_request requestJson(methods::GET);

requestJson.headers().set_content_type(U("application/json"));

    ///you must perform the request
    ///against a server that provides JSON data.

    return client.request(requestJson, ct).then([=](http_response response) -> pplx::task<web::json::value>
    {
        ///If the status is OK extract the body of the response into a JSON value
        if(!getCancelledSate())
        {
            if (response.status_code() == status_codes::OK)
            {
                return response.extract_json();
            }
            else
            {
                // return an empty JSON value
                isConnected = false;
                return pplx::task_from_result(web::json::value());
            }
        }
        else
        {
            //try{
                cts.cancel();
            //}
            //catch(http_exception const & e)
            //{
            //    std::cout<<__FILE__<<"["<<__LINE__<<"]"<<"Exception:"<< e.what() << std::endl;
            //}
        }

    }, ct).then([=](pplx::task<web::json::value> previousTask)
    {
        try{
            std::cout <<" before previousTask.wait()"<< std::endl;
            ///Get the JSON value from the task and call the traversal method

            if(previousTask.wait() == pplx::task_status::canceled){
                //Do nothing
                std::cout <<" after previousTask.wait()"<< std::endl;
            }else{
                web::json::value const & dataValue = previousTask.get();
                m_dataJson = dataValue;

                ///clear string streambuffer
                m_Buffer.str("");
                m_Buffer.clear();
                m_Buffer << m_dataJson.serialize();

                utility::string_t streamJson = m_Buffer.str();

                if((strxxxxcmp(streamJson, APP_ACTIVE) < 0)){
                    isConnected = false;
                    //......So work
                }else{
                    //......So work
                }
            }
        }
        catch(http_exception const & e)
        {
            isConnected = false;
            std::cout<<__FILE__<<"["<<__LINE__<<"]"<<"Exception:"<< e.what() << std::endl;
        }
        });
}

void RestInterface::xxxxz()
{
    try
    {
        isConnected = true;
        Getsxxxx().wait();
    }
    catch(const std::exception &e)
    {
        std::cout<<__FILE__<<"["<<__LINE__<<"]"<<"Exception:"<< e.what() << std::endl;
        //printf("Error exception:%s\n", e.what());
    }
}

Теперь у меня проблема.у нас есть сценарий, в котором мы должны отменить задачу, когда генерируется сигнал, например, например, когда генерируется SIGINT ... когда пользователь дает SIGINT, используя Ctrl + C. Иногда я вижу следующее сообщение.

**/build/casablanca-FHxOgj/casablanca-2.8.0/Release/include/pplx/pplxtasks.h:1835: pplx::task_status pplx::details::_Task_impl_base::_Wait(): Assertion `_IsCompleted()' failed.
Aborted**

Я думаю, что какое-то задание выдает исключение, которое не обрабатывается, но я не совсем уверен, какое именно и о причине.Кто-нибудь может поделиться некоторыми мыслями по этому поводу.

любая помощь будет отличной

...