4
我在我的C程序中打開一個文件:打開文件O_NONBLOCKING丟失內核模塊
pcm->dfd = open(fname, O_RDONLY|O_NONBLOCK);
,過一會兒給它select()
和read()
。
但我的問題是,該O_NONBLOCK
被somewere丟失:
ssize_t my_read(struct file *filp, char __user *user_buffer, size_t bytes_requested, loff_t *capture_ptr) {
if (filp->f_flags & O_NONBLOCK){
LOGI("mode: O_NONBLOCK");
}
else{
LOGI("mode: BLOCKING"); // <-- this is printed
}
..
}
我也試過
pcm->dfd=open(fname, O_RDONLY|O_NONBLOCK);
// O_NONBLOCK does not work :/
int flags = fcntl(pcm->dfd, F_GETFL, 0);
fcntl(pcm->dfd, F_SETFL, flags | O_NONBLOCK);
這不是一個測井問題,司機也表現爲阻斷模式。
任何想法?
編輯:
從打開的文件中讀取的代碼是絕對簡單:
size=read(pcm->dfd,inBuffer,inBufferBytes);
我還檢查程序,如果有一個fcntl()
somewere人,但沒有..
編輯2:
有可能的是,O_NONBLOCK
在我的用戶程序(的Android NDK)的其他值不是內核?我在內核頭文件中搜索了O_NONBLOCK
,並且已經有2個不同的定義。
我還檢查open
- 實施我的內核模塊,並且已經有filp->f_flags
是不O_NONBLOCK
。
顯示我們執行'read'的代碼。 – cnicutar
增加了'read'-line。與UB'O_NONBLOCK'結果(也稱爲_unspecified behaviour_),按照[規格] –
打開文件(http://pubs.opengroup.org/onlinepubs/000095399/functions/open.html)。 –