boost asio async_read_some does not capture inotify events
I am using inotify in conjunction with boost asio aync_read_some. I am
adding a folder to be monitored and then I delete it. I would expect
IN_DELETE_SELF to be raised by inotify and be read from my
async_read_some. But I do not see IN_DELETE_SELF raised. Please help me
find what is being missed here? Ofcourse during inotify_add_watch I am
registering for IN_DELETE_SELF. Note, I have tried both READ_BUFFER_SIZE
to be of 1024 bytes as well as (1024*(EVENT_SIZE + 16)), but in either
case IN_DELETE_SELF is not captured by my code.
#define EVENT_SIZE (sizeof (struct inotify_event))
#define READ_BUFFER_SIZE (1024*(EVENT_SIZE + 16))
//I even tried #define READ_BUFFER_SIZE 1024
void IHandler::init()
{
inotifyFd_ = inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
if(inotifyFd_ < 0)
//Error
else
{
inotifyStream_ = inotifyStreamPointer(new
boost::asio::posix::stream_descriptor(CORE::Utils::Thread::SingletonIOService::Instance(),
inotifyFd_));
doRead();
}
}
void IHandler::doRead()
{
inotifyStream_->async_read_some(
boost::asio::buffer(readBuffer_, READ_BUFFER_SIZE),
std::bind(&IHandler::readInotifyEvent,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
}
void IHandler::readInotifyEvent(boost::system::error_code ec, size_t
bytes_recvd)
{
if(!ec)
{
if(bytes_recvd)
{
char *ptr = NULL;
ptr = readBuffer_;
while (ptr < readBuffer_ + bytes_recvd)
{
struct inotify_event* event = (struct inotify_event *) ptr;
ptr += sizeof (struct inotify_event) +event->len;
processInotifyEvent(event); //Events would be handled here
}
}
inotifyStream_->async_read_some(
boost::asio::buffer(readBuffer_, READ_BUFFER_SIZE),
std::bind(&IHandler::readInotifyEvent,
shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
}
else
//Error
}
Thanks, Sandeep
No comments:
Post a Comment