Exemple #1
0
void Detection::HandleReceiveFrom(int packet_type, int tracker_index, boost::asio::deadline_timer& timer,
                                  const boost::system::error_code& error, size_t bytes_recvd)
{
    std::ofstream fout("text.txt", std::ofstream::ate|std::ofstream::app);
    if (!error || error == boost::asio::error::message_size)
    {
        if (packet_type == 0)  // bs
        {
            int tracker_count = data_[14] * 256 + data_[13];
            fout << "向bs查询到" << tracker_count << "个tracker" << std::endl;
            fout.close();
            has_tracker_list = true;
            timer.cancel();
        }
        else if (packet_type == 1)  // tracker
        {
            int peer_count = data_[28] * 256 + data_[27];
            //mu.lock();
            std::string result = "";
            result.append("向tracker(");
            result.append(m_tracker_infos[tracker_index].ip);
            result.append(":");
            boost::uint16_t port = m_tracker_infos[tracker_index].port;
            char tmp[10];
            itoa(m_tracker_infos[tracker_index].port, tmp, 10);
            result.append(tmp);
            result.append( ")查询到");
            itoa(peer_count, tmp, 10);
            result.append(tmp);
            result.append("个peer");
//             result += "向tracker(" + m_tracker_infos[tracker_index].ip + ":" + m_tracker_infos[tracker_index].port
//                 + ")查询到" + peer_count + "个peer";
            result_trackers.push_back(result);
//             fout << "向tracker(" << m_tracker_infos[tracker_index].ip << ":" << m_tracker_infos[tracker_index].port
//                 << ")查询到" << peer_count << "个peer" << std::endl;
//             fout.close();
//             mu.unlock();
            timer.cancel();
            has_peer_list = true;
        }
    }
    else if (error != boost::asio::error::operation_aborted)
    {
        if (packet_type == 0)
        {
            fout << error.message() << std::endl;
            fout.close();
        }
        else if (packet_type == 1)
        {
            result_trackers.push_back(error.message());
        }
        
    }
}
Exemple #2
0
	/// Set / reset the timeout timer
	void setTimeout( unsigned timeout )
	{
		if ( timeout == 0 )	{
			LOG_TRACE << "Timeout for connection to " << identifier() << " reset";
			m_timer.cancel();
		}
		else	{
			m_timer.cancel();
			m_timer.expires_from_now( boost::posix_time::seconds( timeout ));
			m_timer.async_wait( m_strand.wrap( boost::bind( &ConnectionBase::handleTimeout,
									this->shared_from_this(),
									boost::asio::placeholders::error )));
			LOG_TRACE << "Timeout for connection to " << identifier() << " set to " << timeout << "s";
		}
	}
Exemple #3
0
    /// Receive an event from the underlying comms connection.
    /// @param event the type of event.
    /// @param weak_ptr a weak ponter to the underlying comms connection.
    void event_handler(int event,
                       typename connection_type::weak_pointer weak_ptr)
    {
      // Use the raw pointer of the connection as the map key.
      void* pointer(weak_ptr.lock().get());
      if (!pointer)
        return;

      switch(event)
      {
      case via::comms::CONNECTED:
        timer_.cancel();
        rx_buffer_.clear();
        rx_.clear();
        if (connected_handler_)
          connected_handler_();
        break;
      case via::comms::RECEIVED:
        receive_handler();
        break;
      case via::comms::SENT:
        if (message_sent_handler_)
          message_sent_handler_();
        break;
      case via::comms::DISCONNECTED:
        disconnected_handler();
        break;
      default:
        break;
      }
    }
Exemple #4
0
	void handle_send(const boost::system::error_code& ec, size_t size){
		timer.cancel();
		if(!ec) // ok
			;
		else if(ec == boost::asio::error::message_size) // mtu handle
			;
	}
Exemple #5
0
void read_callback(bool& dataAvailable, boost::asio::deadline_timer &timeout, const boost::system::error_code& error, std::size_t bytes_transferred) {
    if (error || !bytes_transferred) {
        dataAvailable = false;
        return;
    }
    timeout.cancel();
    dataAvailable = true;
    printw("data is available");
}
 void stop(bool wait)
 {
     _timer.cancel();
     if(_in_callback)
     {
         // If we're called re-entrantly, or a callback is in progress on another thread,
         // abandon the timer and let it delete itself at the end of the callback
         _orphan = true;
     }
     else
     {
         if (wait || !_repeat)
         {
             _completed.wait();
         }
         delete this;
     }
 }
Exemple #7
0
 void updateProperty(const Property::ConstPtr &theProperty)
 {
     ViewerApp::updateProperty(theProperty);
     
     // one of our porperties was changed
     if(theProperty == m_texturePath)
     {
         try
         {
             m_textures[0] = gl::createTextureFromFile(*m_texturePath);
             
             if(m_textures[0])
             {
                 // ->CL_INVALID_GL_OBJECT: internal format must be pow2 (RG, RGBA)
                 m_cl_image = cl::ImageGL(m_context, CL_MEM_READ_WRITE, GL_TEXTURE_2D, 0,
                                          m_textures[0].getId());
             }
         }
         catch(cl::Error &error){LOG_ERROR << error.what() << "(" << oclErrorString(error.err()) << ")";}
         catch (FileNotFoundException &e){LOG_WARNING << e.what();}
     }
     else if(theProperty == m_videoPath)
     {
         
     }
     else if(theProperty == m_num_particles)
     {
         scene().removeObject(m_mesh);
         initParticles(*m_num_particles);
     }
     else if(theProperty == m_point_size)
     {
         m_pointMaterial->setPointSize(*m_point_size);
         
         m_timer.cancel();
         m_timer.expires_from_now(boost::posix_time::seconds(2.f));
         m_timer.async_wait(boost::bind(&OpenCLTest::tick, this, _1));
     }
     else if(theProperty == m_point_color)
     {
         m_mesh->material()->setDiffuse(*m_point_color);
     }
 }
inline wamp_dealer_invocation::~wamp_dealer_invocation()
{
    m_timeout_timer.cancel();
}
Exemple #9
0
 void cancel() {
     mMessageId = -1;
     mTimer.cancel();
 }
Exemple #10
0
void SenderImpl::cancel()
{
    m_timer.cancel();
}
Exemple #11
0
 /// Stop executing random behaviors.
 void cancel() {
     timer_.cancel();
     started_.clear();
 }
Exemple #12
0
	void stop()
	{
		echo_timer_.cancel();
	}