Boost logo

Boost Users :

From: Pooyan McSporran (duckfreezone_at_[hidden])
Date: 2008-01-13 20:36:18


I'm trying to use a combination of the iostreams library and the
serialization library in order to be able to serialise objects and
send them over a socket.

I've written a class called "SocketDevice" which implements a
bidirectional iostreams instance, and I'm trying to use this with
serialization, in particular the binary_oarchive and binary_iarchive
archive models.

The problem is that when I do this, the code ends up calling a copy
constructor (which doesn't exist) on my SocketDevice class. However I
don't want to implement a copy constructor for this class as it
doesn't make sense (as it manages a socket and a buffer for that
socket, etc).

The interface of my SocketDevice class looks like this:

class SocketDevice : public
boost::iostreams::device<boost::iostreams::bidirectional>
{
public:
  typedef char char_type;
  SocketDevice (int sock);
  ~SocketDevice ();
  std::streamsize read (char *s, std::streamsize n);
  std::streamsize write (const char *s, std::streamsize n);
private:
  const int sock;
  char *buffer;
  size_t bufferSize;
};

and I'm trying to do the object sending/receiving via template methods, eg:

template<class C>
void sendObject (const C& data, int sock)
{
  boost::iostreams::stream_buffer<SocketDevice> buf (sock);
  std::ostream s (&buf);
  boost::archive::binary_oarchive oa (s);
  oa << data;
}

The copy constructor appears to be synthesised when the 'buf' object
is instantiated in the above template method.

My guess is that I'm doing something wrong, but I can't see what.
I've also tried splitting my SocketDevice class from a bidirectional
one to a pair of input & output ones, but with the same result. I've
also tried making sendObject() a normal (non-template) method, this
makes no difference.

I realise that there are issues with trying to combine socket
communications with object serialisation, but I'm still curious as to
why I have this copy constructor issue.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net