Search Results

Search found 2 results on 1 pages for 'nixman'.

Page 1/1 | 1 

  • boost.serialization and lazy initialization

    - by niXman
    i need to serialize directory tree. i have no trouble with this type: std::map< std::string, // string(path name) std::vector<std::string> // string array(file names in the path) > tree; but for the serialization the directory tree with the content i need other type: std::map< std::string, // string(path name) std::vector< // files array std::pair< std::string, // file name std::vector< // array of file pieces std::pair< // <<<<<<<<<<<<<<<<<<<<<< for this i need lazy initialization std::string, // piece buf boost::uint32_t // crc32 summ on piece > > > > > tree; how can i serialize the object of type "std::pair" in the moment of its serialization?

    Read the article

  • boost.asio error on read from socket.

    - by niXman
    The following code of the client: typedef boost::array<char, 10> header_packet; header_packet header; boost::system::error_code error; ... /** send header */ boost::asio::write( _socket, boost::asio::buffer(header, header.size()), boost::asio::transfer_all(), error ); /** send body */ boost::asio::write( _socket, boost::asio::buffer(buffer, buffer.length()), boost::asio::transfer_all(), error ); of the server: struct header { boost::uint32_t header_length; boost::uint32_t id; boost::uint32_t body_length; }; static header unpack_header(const header_packet& data) { header hdr; sscanf(data.data(), "%02d%04d%04d", &hdr.header_length, &hdr.id, &hdr.body_length); return hdr; } void connection::start() { boost::asio::async_read( _socket, boost::asio::buffer(_header, _header.size()), boost::bind( &connection::read_header_handler, shared_from_this(), boost::asio::placeholders::error ) ); } /***************************************************************************/ void connection::read_header_handler(const boost::system::error_code& e) { if ( !e ) { std::cout << "readed header: " << _header.c_array() << std::endl; std::cout << constants::unpack_header(_header); boost::asio::async_read( _socket, boost::asio::buffer(_body, constants::unpack_header(_header).body_length), boost::bind( &connection::read_body_handler, shared_from_this(), boost::asio::placeholders::error ) ); } else { /** report error */ std::cout << "read header finished with error: " << e.message() << std::endl; } } /***************************************************************************/ void connection::read_body_handler(const boost::system::error_code& e) { if ( !e ) { std::cout << "readed body: " << _body.c_array() << std::endl; start(); } else { /** report error */ std::cout << "read body finished with error: " << e.message() << std::endl; } } On the server side the method read_header_handler() is called, but the method read_body_handler() is never called. Though the client has written down the data in a socket. The header is readed and decoded successfully. What's the error?

    Read the article

1