boost::asio write_some - error

Discussion in 'C++' started by Przemek Biernat, Jul 1, 2013.

  1. I have some problem with send data by boost::asio. My code:

    void Connection::SendCommand(std::shared_ptr<ICommand> command)
    {
    int dataSize = command->GetSize();

    vector<char> dataBuffer = vector<char>(dataSize);

    stringstream ss;
    binary_oarchive oa(ss);
    command->Serialize(oa);

    if(_side == Server)
    command->Execute();

    binary_iarchive ia(ss);

    ia.load_binary(&dataBuffer[0], dataSize);

    int* header = new int[3];

    header[0] = (int)(command->Type());
    header[1] = (int)FromClientToServer;
    header[2] = dataSize;

    size_t s = _socket->write_some(buffer(header, 3*sizeof(int)));
    size_t s1 = _socket->write_some(buffer(dataBuffer, dataSize*sizeof(char)));

    delete[] header;
    }

    I get exception on the second call write_some:

    boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::system::system_error> > at memory location 0x0021F520.

    Does anybody know what is wrong?
     
    Przemek Biernat, Jul 1, 2013
    #1
    1. Advertising

  2. Przemek Biernat

    Cholo Lennon Guest

    On 07/01/2013 01:33 PM, Przemek Biernat wrote:
    > I have some problem with send data by boost::asio. My code:
    >
    > void Connection::SendCommand(std::shared_ptr<ICommand> command)
    > {
    > int dataSize = command->GetSize();
    >
    > vector<char> dataBuffer = vector<char>(dataSize);
    >
    > stringstream ss;
    > binary_oarchive oa(ss);
    > command->Serialize(oa);
    >
    > if(_side == Server)
    > command->Execute();
    >
    > binary_iarchive ia(ss);
    >
    > ia.load_binary(&dataBuffer[0], dataSize);
    >
    > int* header = new int[3];
    >
    > header[0] = (int)(command->Type());
    > header[1] = (int)FromClientToServer;
    > header[2] = dataSize;
    >
    > size_t s = _socket->write_some(buffer(header, 3*sizeof(int)));
    > size_t s1 = _socket->write_some(buffer(dataBuffer, dataSize*sizeof(char)));
    >
    > delete[] header;
    > }
    >
    > I get exception on the second call write_some:
    >
    > boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::system::system_error> > at memory location 0x0021F520.
    >
    > Does anybody know what is wrong?
    >


    The best place to ask about boost libraries is:
    gmane.comp.lib.boost.user (point your news reader to news.gmane.org)

    Regards


    --
    Cholo Lennon
    Bs.As.
    ARG
     
    Cholo Lennon, Jul 1, 2013
    #2
    1. Advertising

  3. On 7/1/2013 11:33 AM, Przemek Biernat wrote:
    > I have some problem with send data by boost::asio. My code:
    >
    > void Connection::SendCommand(std::shared_ptr<ICommand> command)
    > {
    > int dataSize = command->GetSize();
    >
    > vector<char> dataBuffer = vector<char>(dataSize);
    >
    > stringstream ss;
    > binary_oarchive oa(ss);
    > command->Serialize(oa);
    >
    > if(_side == Server)
    > command->Execute();
    >
    > binary_iarchive ia(ss);
    >
    > ia.load_binary(&dataBuffer[0], dataSize);
    >
    > int* header = new int[3];
    >
    > header[0] = (int)(command->Type());
    > header[1] = (int)FromClientToServer;
    > header[2] = dataSize;
    >
    > size_t s = _socket->write_some(buffer(header, 3*sizeof(int)));
    > size_t s1 = _socket->write_some(buffer(dataBuffer, dataSize*sizeof(char)));
    >
    > delete[] header;
    > }
    >
    > I get exception on the second call write_some:
    >
    > boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::system::system_error> > at memory location 0x0021F520.
    >
    > Does anybody know what is wrong?



    Funny, I had the what I think might be the same error today when I
    upgraded to boost 1.53 and Visual Studio 2012. Did you debug through it
    and see where it was being thrown from in the boost source?
     
    Christopher Pisz, Jul 2, 2013
    #3

  4. >
    > Funny, I had the what I think might be the same error today when I
    >
    > upgraded to boost 1.53 and Visual Studio 2012. Did you debug through it
    >
    > and see where it was being thrown from in the boost source?


    Now I get this error on read in function in file read.hpp.
    When I call io_service.run() on the client then the server try to read data, but I'm not sending at this moment and I get error in function read.

    inline std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers)
    {
    boost::system::error_code ec;
    std::size_t bytes_transferred = read(s, buffers, transfer_all(), ec);
    boost::asio::detail::throw_error(ec, "read");
    return bytes_transferred;
    }
     
    Przemek Biernat, Jul 2, 2013
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?utf-8?B?5byg5rKI6bmP?=

    How to compile the HelloWorld of boost.asio?

    =?utf-8?B?5byg5rKI6bmP?=, Aug 10, 2006, in forum: C++
    Replies:
    1
    Views:
    3,490
    Victor Bazarov
    Aug 10, 2006
  2. Replies:
    1
    Views:
    1,200
    Martin York
    Apr 20, 2008
  3. Torsten Mueller

    boost::asio for HTTP -> data truncated

    Torsten Mueller, Aug 12, 2010, in forum: C++
    Replies:
    3
    Views:
    2,026
    Francesco S. Carta
    Aug 13, 2010
  4. Christopher
    Replies:
    0
    Views:
    1,387
    Christopher
    Jun 8, 2011
  5. boost::asio write_some

    , Jun 29, 2013, in forum: C Programming
    Replies:
    4
    Views:
    352
Loading...

Share This Page