Ejemplo n.º 1
0
 void receive_1p( FUNC func_ )
 {
     if( connection_1p )
     {
         try
         {
             while( true )
             {
                 std::memset( buffer_.data(), '\0', buffer_.size() );
                 auto state_ = connection_1p->receive( buffer_.data(), buffer_.size(), 0 );
                 if( state_ != bluetooth::connection::socket_state::success )
                 {
                     break;
                 }
                 func_( this, buffer_ );
             }
         }
         catch( bluetooth_disconnect_exception const& )
         {
             connection_1p.reset();
             if( !listener_ )
             {
                 listener_ = std::make_shared<bluetooth::listener>();
             }
             subject_1p.notify( connection_state::disconnect );
         }
     }
 }
Ejemplo n.º 2
0
std::string to_string(buffer_type buf){
    std::size_t length = 0; 
    while(length < buf.size())
    {
        if(buf[length] == '\0') break;
        length++;
    }
    return std::string(buf.data(), buf.data() + length);
}
Ejemplo n.º 3
0
void instance::write(execution_unit* ctx, buffer_type& buf,
                     header& hdr, payload_writer* pw) {
  CAF_LOG_TRACE(CAF_ARG(hdr));
  try {
    if (pw) {
      auto pos = buf.size();
      // write payload first (skip first 72 bytes and write header later)
      char placeholder[basp::header_size];
      buf.insert(buf.end(), std::begin(placeholder), std::end(placeholder));
      binary_serializer bs{ctx, buf};
      (*pw)(bs);
      auto plen = buf.size() - pos - basp::header_size;
      CAF_ASSERT(plen <= std::numeric_limits<uint32_t>::max());
      hdr.payload_len = static_cast<uint32_t>(plen);
      stream_serializer<charbuf> out{ctx, buf.data() + pos, basp::header_size};
      out << hdr;
    } else {
      binary_serializer bs{ctx, buf};
      bs << hdr;
    }
  }
  catch (std::exception& e) {
    CAF_LOG_ERROR(CAF_ARG(e.what()));
  }
}
Ejemplo n.º 4
0
 void write()
 {
     m_socket.async_write_some(
             m_write_buf.data(),
             bind(&this_type::handle_write, shared_from_this(),
                 boost::asio::placeholders::error,
                 boost::asio::placeholders::bytes_transferred)
             );
 }
Ejemplo n.º 5
0
std::string Base64Helper::Encode(const buffer_type& data) {
    auto encodedSize = data.size() * 4;
    encodedSize = (encodedSize + 3) / 3;
    encodedSize += 4 - (encodedSize % 4);   
    
    std::string text;
    text.resize(encodedSize);
    
    base64Encode(&text[0], data.data(), data.size());    
    
    return text;
}