0

the following code works perfectly well for smaller files (1-10MB), but when I try to send bigger files (I tested with a 7GB file) then TransmitFile returns false, and WSAGetLastError() returns 87. I don't really know what to do with that error code (Wrong Parameters) since nothing about the parameters changes. Does somebody know under what circumstances TransmitFile complains about wrrong parameters when the file size changes?

void send_file(int socket, std::string& src_file) {
    const auto file_size = std::filesystem::file_size(src_file);
    if(!(send_uint64(socket, file_size) == sizeof(static_cast<uint64_t>(file_size))))
        throw WSA_socket_exception(WSAGetLastError(), socket);


    const auto file = reinterpret_cast<HANDLE>(_get_osfhandle(_fileno(fopen(src_file.c_str(), "r"))));

    if (!TransmitFile(socket, file, 0, static_cast<DWORD>(MAX_BUFFER_FILE), nullptr, nullptr, 0)) {
        throw WSA_socket_exception(WSAGetLastError(), socket);
    }

}
Max Luchterhand
  • 448
  • 3
  • 10
  • 3
    What is the maximum value a `DWORD` can have? Probably the value wrapped around to the negative side of the integer, thus TransmitFile sees it as an invalid parameter. [Possible duplicate](https://stackoverflow.com/questions/18240501/how-would-one-transfer-files-larger-than-2-147-483-646-bytes-2-gib-with-win32) – PaulMcKenzie Mar 16 '20 at 15:02
  • @PaulMcKenzie - yes, this duplicate. only instead `SetFilePointerEx` (bad solution) need set direct offset in `OVERLAPPED` – RbMm Mar 16 '20 at 15:28

0 Answers0