Can't use Poco TCPServer and TCPServerConnectionFactory

I am using TCPServer inside an activity. To simplify my design, I am doing my ihnerit job from TCPServerConnectionFactory. With this, my activity implements the CreateConnection () method.

To create my TCPServer I do:

Poco::Net::TCPServer(this, serverSocket);

      

Unfortunately, when my TCPServer is destroyed, it also destroys (this) which I gave in the parameter. So it calls the dtor of my activity, which is really annoying.

Looking deep into Poco's code I can see that TCPServer creates Poco :: shared_Ptr (this) and when this Shared_Ptr is destroyed it deletes the contents of the shared_ptr.

How can I transfer (this) to TCPServer without being destroyed at the end of TCPServer life?

0


source to share


1 answer


You have to pass the factory connection heap allocated to TCPServer. For example see TimeServer example:



class TimeServerConnection: public TCPServerConnection
{
  //...
};

// ...

class TimeServerConnectionFactory: public TCPServerConnectionFactory
{
  // ...
  TCPServerConnection* createConnection(const StreamSocket& socket)
  {
    return new TimeServerConnection(socket, _format);
  }
  // ...
};

// set-up a server socket
ServerSocket svs(port);
// retain the handle to shared ptr for later use
TCPServerConnectionFactory::Ptr pTSCF = new TimeServerConnectionFactory(format);
// set-up a TCPServer instance
TCPServer srv(pTSCF, svs);

      

0


source







All Articles