Seweryn Habdank-Wojewódzki wrote:
Hello
I would like to ask for consideration of some new functionality for boost::serialization.
If I have a stream and I do not want to close the stream at the end of serialization
I can't see why this is a problem. Does the following not work? { o?stream os("stream_name"); os << ... ; // your own stuff here { text_oarchive oa(os); oa << .... os.flush(); // actually I think this is invoked by default when archive is destroyed } // archive destructor called here - stream stays open // stream is still open here. os << ... ; // more of your own stuff os.close(); } Robert Ramey I have to make easy, but nasty trick using stringstream
as a buffer between my stream and serialized stream.
More concrete example. I'am using easy library for sockets. Connection is represented as stream and after connection I do not want to close it. So when I try to use serialization though the socket, serialisation is hanging - it is waiting for the end of the stream, but there is no end of stream because it is socket.
It will be useful just to add to library one fuction for manual sending data - "simulation" of the end of stream. To avoid or closing socket either using stringstreams buffers.
Below is example code for this problem - this code is using buffers, but IMHO better will be that inside library will be functionality for such a situation.
Best regards, Seweryn Habdank-Wojewódzki.
Ps. Full code I can send if will be needed.
void do_server() { string message("Hello Socket!\nHelloWorld!");
// create class instance const gps_position g(35, 59, 24.567f);
try { TCPSocketWrapper sockserver;
// listen on some port sockserver.listen(IPportnumber);
cout << "server is ready" << endl;
// accept connection from client TCPSocketWrapper sock(sockserver.accept());
cout << "accepted connection from: " << sock.address() << endl;
// make the stream around the socket wrapper TCPStream stream(sock);
bool oncemore = true; int command; while (oncemore) { // read the command stream >> command;
switch (command) { case 1: { cout << "command 1" <
// ------------------------------------------------
// buffer
// ------------------------------------------------
std::ostringstream s;
{ boost::archive::text_oarchive oa(s);
// write class instance to archive oa << g; } //------------------------------------------------------------------
// buffer
//------------------------------------------------------------------ stream << s.str() << endl; }
break; default: cout << "END command" << endl; oncemore = false; break; } } } catch (const SocketRunTimeException &e) { cout << "socket exception: " << e.what() << endl; } }
void do_client() { string message;
// ... some time later restore the class instance to its orginal state gps_position newg;
try { TCPClientStream stream(IPserveraddress, IPportnumber);
bool oncemore = true; int command; while (oncemore) { cout << "1. request for a serialized object" << endl; cout << "other - end" << endl;
cin >> command; stream << command << endl;
switch (command) { case 1: { // ------------------------------------------------
// buffer
// ------------------------------------------------
std::string line; std::getline(stream, line); istringstream s(line);
// ------------------------------------------------
// buffer will be filled
// ------------------------------------------------
{ boost::archive::text_iarchive ia(s);
ia >> newg; }
cout << "received: " << newg << endl; } break; default: oncemore = false; break; } } } catch (const SocketRunTimeException &e) { cout << "socket exception: " << e.what() << endl; } }
\/\/| Seweryn Habdank-Wojewódzki `\/\/ =