내가 소스 코드를 기반으로 모니터링 파일 프로그램을 쓰고 있어요 실패비동기 읽기는
생성자 :
void init(){
int fd = inotify_init1(IN_NONBLOCK);
int wd = inotify_add_watch(fd_, "./test.txt", IN_ALL_EVENTS);
stream_.reset(new boost::asio::posix::stream_descriptor(io_service_, fd_)));
}
을 inotify를 설명 http://linux.die.net/man/7/inotify
내 코드는 다음과 같습니다 비동기 읽기 :
template<typename Monitor_Handler>
void async_monitor(Monitor_Handler handler) {
stream_->async_read_some(boost::asio::buffer(buffer_),
boost::bind(&monitor::handle_monitor<Monitor_Handler>,
shared_from_this(), boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred, handler));
}
핸들러 :
template<typename Monitor_Handler>
void handle_monitor(const boost::system::error_code &ec,
std::size_t bytes_transferred, Monitor_Handler handler) {
//process buffer
async_monitor(handler);
}
오류가 처음 handle_monitor에서의 첫 번째 변화를 여러 번 (예 : MODIFY, ACCESS, OPEN 여러 이벤트를 ...) 호출이다 감시하는 파일 그런 다음 async_read_some 메서드가 다시 호출되었지만 더 이상 신호가 없습니다 (handle_monitor가 더 이상 호출되지 않음)
그러나 설명을 재설정하고 모니터링 할 파일을 다시 읽으려고하면 ==> 작동했습니다. handle_monitor는 모니터링되는 파일의 새로운 변경 사항에 대해 호출됩니다.
코드 수정 :
template<typename Monitor_Handler>
void handle_monitor(const boost::system::error_code &ec,
std::size_t bytes_transferred, Monitor_Handler handler) {
//process buffer
async_monitor(handler);
init();//for resetting the inotify desciptor
}
너희들은 내가이 문제를 설명 할 수 있을까요 ???? 나는
덕분에 다음과 같이 aync_read_some을 활용하는 더 나은 것 대신
를 사용하는 말을, 나는 FD 변수를 다시 작성합니다. 그러나 그것은 문제가 아닙니다. 나는이 문제에서 내 문제의 범위를 좁힌 다. http://stackoverflow.com/questions/16397293/the-read-method-on-the-inotify-descriptor-does-not-return 설명해 주시겠습니까? 당신의 대답을 보길 바랍니다 – khanhhh89