Click here to Skip to main content
15,889,369 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

At the moment I have a little design issue. I created proxy server for my application, but I'm having trouble to delete sessions. (using boost::asio)

I obviously have two sockets. One connected from proxy to client and one connected from proxy to server. I use async operations to recv/send data on those sockets. However when error occurs and the socket is closed, I want to delete that session. However if I delete the session, the handler of the other socket is called too and the delete is called twice (which leads to crash of-course).

Any ideas how to fix that are welcome.

Ex.:
C++
//m_socket1 handler:
void CSomeSession::Handler_SendToClient( const boost::system::error_code& error)
{
	if( error)
	{
		std::cout << error.message() << std::endl;		
		delete this;
	}
}

//m_socket2 handler:
void CSomeSession::Handler_SendToServer( const boost::system::error_code& error)
{
	if( error)
	{
		std::cout << error.message() << std::endl;		
		delete this;
	}
}

Same goes for recv.

Thank you for your help.

[Edit]Code block added[/Edit]
Posted
Updated 5-Dec-12 7:55am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900