For any of those who might encounter the same error, I found what my problem is - thanks to Inge Henriksen.
class ASocket
{
// ...
~ASocket()
{
if(m_handle.bev)
{
bufferevent_free(m_handle.bev);
}
if(m_handle.fd >= 0)
::close(m_handle.fd);
}
// ...
}
Upon deleting an asynchronous socket object (ASocket
), the bufferevent
would be freed if it exists and the socket would be deleted - libevent would continue to operate on a closed socket. Note that bufferevent_free, as stated at http://www.wangafu.net/~nickm/libevent-book/Ref6_bufferevent.html#_freeing_a_bufferevent, but not on the Doxygen documentation page, will not free the bufferevent
upon calling the bufferevent_free
function but rather:
The bufferevent_free() function does, however, try to free the bufferevent as soon as possible.
This was fixed like so:
class ASocket
{
// ...
// If bufferevent exists, it must be created with
// the BEV_OPT_CLOSE_ON_FREE flag.
~ASocket()
{
if(m_handle.bev)
{
bufferevent_free(m_handle.bev);
}
else
{
if(m_handle.fd >= 0)
::close(m_handle.fd);
}
}
// ...
}
If the socket has a bufferevent
, it is freed and libevent will close the socket once it is finished.