I have several pc connected to one network.
When I trying to write file with WriteFile function across network from several processes running on the different PC-s I getting ERROR_UNEXP_NET_ERR.
Details: Several PC-s does they own calculations and getting part of the common result wich should be writen to one file. One randomly choosen process calculates total file size and determines writing offsets for each process. This process creates the file and resize it up to calculated size.
After this I starting writing file in all processes simultaneously.
I open file on each process like this:
handle_ = ::CreateFile("////SERVERNAME//folder//filename.ext", GENERIC_WRITE | GENERIC_READ, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
And trying to write in the cycle like this:
const size_t BUFFER_SIZE = 30 * 1024;
std::vector<char> buffer(BUFFER_SIZE);
const size_t storage_size = storage_.size();
size_t internal_offset = 0;
while (size_t bytes = storage_.read(buffer.data(), buffer.size(), internal_offset))
{
DWORD done = 0;
LARGE_INTEGER li;
li.QuadPart = offset + internal_offset;
OVERLAPPED overlapped;
overlapped.OffsetHigh = li.HighPart;
overlapped.Offset = li.LowPart;
overlapped.hEvent = 0;
overlapped.Pointer = 0;
overlapped.Internal = 0;
overlapped.InternalHigh = 0;
BOOL success = ::WriteFile(handle_, buffer, (DWORD)bytes, &done, &overlapped);
if (!success || done != bytes)
ThrowError(FFL, "Cannot write file: {1} ({2})", filepath_, GetLastError()); // Returns error code 59 (ERROR_UNEXP_NET_ERR)
internal_offset += bytes;
}
This approch works with file size about 7MB but fails when I trying to write 186.5GB.
I tryed to do this by several differnt ways and tryed to write file part localy on each PC. Local write works fine but all network attempts fails.
I want to know why I getting errors when trying to write across the network. I will be gratefull for adwices how to do this in better maner.