Britto
Britto

Reputation: 501

C++ Network IO, File handling and network failures

I would like to create a new file on a different machine in the network and write to it. I use CreateFile and WriteFile MSDN functions to create and write to the file.

The problem here is writes to the network disk are inconsistent during network failures

During long failures and local caching enabled, the handle becomes invalid and error code ERROR_BAD_NETPATH (53) is returned. So closing existing handle and reopening new handle results in loss of data in the cache.

Disabling local caching through the use of FILE_FLAG_NO_BUFFERING and FILE_FLAG_WRITE_THROUGH flags cannot be used here because it slows down the writes

What is the best way to do network file writes? or is this network failure one off and this has to be a limitation?

Upvotes: 1

Views: 300

Answers (1)

user2587106
user2587106

Reputation: 325

do as Marcelino suggested, ie first write the file locally. Then use system() to run a copy utility program that works for your platform (eg: xcopy, or scp) as an external process. This functionality of reliably copying you should not try to duplicate. Just use it. :)

Upvotes: 1

Related Questions