Example #1
0
void *HTTPClient::requestLoop(void *data)
{

    HTTPClient * httpCli = (HTTPClient*)data;
    while(1)
    {
        //Wait untill a new request is ready to be processed
        httpCli->m_pRequestMutex->WaitForCond(COND_NEW_REQUEST);
        if(true == httpCli->m_bShutdownRequestThread)
        {
            httpCli->m_pRequestMutex->Release();
            break;
        }

        httpCli->SendRequest();

        if(NULL != httpCli->extCallbackFunc)
        {
            httpCli->extCallbackFunc(httpCli->extDataPtr);
        }
        httpCli->m_pRequestMutex->Release();
        httpCli->m_bRequestCompleted = true;
    }
    return NULL;

}
Example #2
0
void ControlTopology(sp_string topology_id, sp_int32 port, bool activate) {
  EventLoopImpl ss;
  AsyncDNS dns(&ss);
  HTTPClient* client = new HTTPClient(&ss, &dns);
  HTTPKeyValuePairs kvs;
  kvs.push_back(make_pair("topologyid", topology_id));
  sp_string requesturl = activate ? "/activate" : "/deactivate";
  OutgoingHTTPRequest* request =
      new OutgoingHTTPRequest(LOCALHOST, port, requesturl, BaseHTTPRequest::GET, kvs);
  auto cb = [client](IncomingHTTPResponse* response) { ControlTopologyDone(client, response); };

  if (client->SendRequest(request, std::move(cb)) != SP_OK) {
    FAIL() << "Unable to send the request\n";
  }
  ss.loop();
}