Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible that application can lose I/O connection to a file?

Tags:

c++

c

I have a C application. Which creates a connection to file at startup and it continuously runs for many days.

I am only connecting one time . and not reconnecting it in code. Only checking if

if(NULL == file)

Is there can be case that my application lose I/O connection of that file handler ?

if yes. Is there a way , How can I create test case for it ?

like image 265
Vivek Goel Avatar asked May 16 '11 07:05

Vivek Goel


1 Answers

Yes it's possible. For example if the file is on another machine or on a removable storage. Then you can physically disconnect/unplug the device and the subsequent operations on the handle will fail.

As others mentioned in the comments, you can simulate it in a test case by creating a RAM disk and either unmounting it or killing the driver. Alternatively, if all you care is about unidirectional I/O, maybe you could test your code with a pipe, and then close the other end of the pipe.

like image 91
Yakov Galka Avatar answered Sep 23 '22 13:09

Yakov Galka