简体   繁体   中英

open read file with file descriptor

I use a driver that have many files, each file I have an ID to it, when I open theses files I store the files descriptors in strcut array that contain the ID with the file descriptor, each opened file can be blocking or not.

I want to read the file from another program or from an other function in the program, when I try to read a blocking file with its file descriptor, it don't still blocking until I write on it, it return no data in the buffer, but when I use it in the same function It still blocking.

Where is the problem ?

if (vg_bufObj[indice].protocolType == _NO_BLOC) 
vg_bufObj[indice].dev_fd = open(d_path, O_RDONLY | O_NONBLOCK);
else
vg_bufObj[indice].dev_fd = open(d_path, O_RDONLY);

vg_bufObj is struct and declared extern

in other function I read the file with

read_size = read(vg_bufObj[indice].dev_fd, data, 8);

When the protocolType is specified _BLOC the file is open blocking, but when I read it from the another function it return empty data and the read size return the max value of the variable.

if (vg_bufObj[indice].protocolType == _NO_BLOC) 
vg_bufObj[indice].dev_fd = open(d_path, O_RDONLY | O_NONBLOCK);
else
vg_bufObj[indice].dev_fd = open(d_path, O_RDONLY);

vg_bufObj is struct and declared extern

in other function I read the file with

read_size = read(vg_bufObj[indice].dev_fd, data, 8);

When the protocolType is specified _BLOC the file is open blocking, but when I read it from the another function it return empty data and the read size return the max value of the variable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM