Boost's official site socket::close() function, see the description
"This function causes all outstanding asynchronous connect, send and receive operations to finish immediately, and the handlers for cancelled operations will be passed the boost::asio::error::operation_aborted error."
But strangely, when i call chat_session::close(), socket::close() passing ERROR_CONNECTION_ABORTED (1236) error instead of boost::asio::error::operation_aborted (995).
Why is this happens? here is my chat_session class.
class chat_session
: public boost::enable_shared_from_this<chat_session>
{
public:
chat_session(boost::asio::io_service& io, chat_server* room)
: m_sock(io), m_room(room)
{
}
~chat_session()
{
}
void start()
{
m_room.join(shared_from_this());
m_sock.async_read_some(
boost::asio::buffer(m_recv_data),
boost::bind(&chat_session::handle_read, shared_from_this(),
boost::asio::placeholders::error));
}
void close()
{
// closing socket. chat_session::handle_read will receive
// boost::asio::error::operation_aborted error.
m_sock.close();
}
boost::asio::ip::tcp::socket& socket()
{
return m_sock;
}
private:
void handle_read(const boost::system::error_code& error)
{
if (!error)
{
printf("RECV -> %s.\n", m_recv_data);
m_sock.async_read_some(
boost::asio::buffer(m_recv_data),
boost::bind(&chat_session::handle_read, shared_from_this(),
boost::asio::placeholders::error));
}
else
{
// when i call chat_session::close(),
// ERROR_CONNECTION_ABORTED (1236) error occurred
// instead of boost::asio::error::operation_aborted error over here
...
m_room.leave(shared_from_this());
}
}
boost::asio::ip::tcp::socket m_sock;
chat_room& m_room;
char m_recv_data[50];
};