Boost logo

Boost :

From: rodolfo_at_[hidden]
Date: 2006-03-23 22:41:38


Hi,
I use boost::serialization a lot to marshall c++ structures to be sent
to a socket, like this:

void send_update(ostream &out, const data_t &data)
{
    {
        text_oarchive oa(out);
        oa << data;
    }
    out << "220 OK" << endl;
}

The problem is that text_oarchive doesn't append a blank character to
denote the end of its data. If the last member sent to the oarchive is
an unsigned 123 number, in this example the data sent would be

... (begining of data)... 123220 OK<CR>

When processing this with text_iarchive, the last member gets the value
123220, instead of 123.

By appending an space (or \n) to the end, in ~text_oarchive, this problem
is solved. Another worst problem is if the receiver uses blocking socket
connection (and no 220 OK is sent). After reading the last digit (3),
it would wait for the next one, which wouldn't arrive, blocking the
connection. By having an space after the last digit, it would know that
the data stream has ended and it wouldn't block anymore.

I've wasted the whole day figuring why my application was blocking :(

Thanks,
Rodolfo Lima

                
_______________________________________________________
Yahoo! Acesso Grátis - Internet rápida e grátis. Instale o discador agora!
http://br.acesso.yahoo.com


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk