WriteFile does not work with ERROR_UNEXP_NET_ERR when writing to one file from multiple processes

I have multiple computers connected to the same network.

When I try to write a file with the WriteFile function over the network from multiple processes running on different computers, I get ERROR_UNEXP_NET_ERR.

More details: On several PCs they have calculations and obtaining a part of the overall result, which should be written to one file. One randomly selected process calculates the total file size and determines the write offsets for each process. This process creates a file and resizes it to the calculated size.

After that, I start writing the file in all processes at the same time.

I open a file for 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 a loop 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 approach works with a file size of around 7MB, but fails when trying to write to 186.5GB.

I tried to do this in a couple of different ways and tried to write the local part of the file on each PC. Local recording works fine, but all network attempts fail.

I want to know why I am getting errors when I try to write over the network. I will be grateful for your suggestions on how to do it better than better.

+3
c ++ winapi networking


source to share


No one has answered this question yet

Check out similar questions:

505
How to determine CPU and memory consumption from within a process?
484
When should you write the 'inline' keyword for a function / method?
3
Alternative to ReplaceFile when the application keeps the file locked
2
WriteFile error depending on the length of the data to write?
1
Write Unicode CString string to file using WriteFile API
1
WriteFile hook does not capture writing to file
1
Writing RegQueryValueEx values ​​to file with WriteFile error
1
using matching I / O conflicts with c ++ D'tor
0
Crash when calling ReadFile after LockFileEx
0
WriteFile on a file via a network share



All Articles
Loading...
X
Show
Funny
Dev
Pics