NuLL3rr0r

Untitled

Dec 19th, 2012
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. void Client::Start()
  2. {
  3.     m_workerMutex.lock();
  4.  
  5.     assert(boost::algorithm::trim_copy(m_id) != "");
  6.     assert(m_port != 0);
  7.  
  8.     if (m_running) {
  9.         m_workerMutex.unlock();
  10.         return;
  11.     }
  12.  
  13.     //std::string tcpURL((boost::format("tcp://localhost:%1%") % boost::lexical_cast<std::string>(m_port)).str());
  14.  
  15.     m_context = zmq_ctx_new();
  16.     assert(m_context != NULL);
  17.  
  18.     m_socket = zmq_socket(m_context, ZMQ_REQ);
  19.     assert(m_socket != NULL);
  20.  
  21.     int linger = 0;
  22.     zmq_setsockopt(m_socket, ZMQ_LINGER, &linger, sizeof(linger));
  23.  
  24.     //zmq_connect(m_socket, tcpURL.c_str());
  25.  
  26.     m_running = true;
  27.  
  28.     m_workerThread = new boost::thread(&Client::SendRequests, this);
  29.     m_workerThread->detach();
  30.  
  31.     m_workerMutex.unlock();
  32. }
  33.  
  34. void Client::Stop()
  35. {
  36.     m_workerMutex.lock();
  37.  
  38.     if (!m_running) {
  39.         m_workerMutex.unlock();
  40.         return;
  41.     }
  42.  
  43.     m_workerThread->interrupt();
  44.  
  45.     //std::string tcpURL((boost::format("tcp://localhost:%1%") % boost::lexical_cast<std::string>(m_port)).str());
  46.  
  47.     delete m_workerThread;
  48.     m_workerThread = NULL;
  49.  
  50.     //int rc = zmq_disconnect(m_socket, tcpURL.c_str());
  51.     //assert(rc == 0);
  52.     int rc = zmq_close(m_socket);
  53.     assert(rc == 0);
  54.     rc = zmq_ctx_destroy(m_context); // ** FOREVER STOCKS HERE !!
  55.     assert(rc == 0);
  56.  
  57.     m_running = false;
  58.  
  59.     m_workerMutex.unlock();
  60. }
Advertisement
Add Comment
Please, Sign In to add comment