natebizu wrote:
> I have a windows application that needs to open a file that is on a
> network share, but sometimes the user is not connected to the network.
> The problem is fopen takes a REALLY long time to timeout. How do I
> reduce the time it takes for fopen to timeout?
>
> FILE *in = fopen("\\\\share\\drive\\file.txt", "r");
> bool fileFound;
> if(in)
> fileFound=true;
> else
> fileFound=false;
You can't. fopen(), on Windows, calls CreateFile() behind the scenes -
and I've never seen the call do anything other than synchronous file
I/O. I'm pretty sure you are looking for either Overlapped or
Asynchronous File I/O. Which means you get to dig around in the ugly
file APIs of Windows to do what you want. I recommend reading Safe C++
Design Principles before you start dumping CreateFile() calls at the
application layer of your app. (Safe C++ is a free e-book for c-prog
members available in the Files section of this group's website).
--
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197
*NEW* VerifyMyPC 2.2
Change tracking and management tool.
Reduce tech. support times from 2 hours to 5 minutes.
Free for personal use, $10 otherwise.
http://www.CubicleSoft.com/VerifyMyPC/