X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/f782b90bcef4c93ddbb5d916709ac40aeb76210a..75af832bc1a2b6ed23412f84dfbac872beb668af:/src/smpi/internals/smpi_global.cpp diff --git a/src/smpi/internals/smpi_global.cpp b/src/smpi/internals/smpi_global.cpp index f63b4d9095..19eb74736f 100644 --- a/src/smpi/internals/smpi_global.cpp +++ b/src/smpi/internals/smpi_global.cpp @@ -492,31 +492,35 @@ static void smpi_copy_file(std::string src, std::string target, off_t fdin_size) xbt_assert(fdout >= 0, "Cannot write into %s", target.c_str()); XBT_DEBUG("Copy %" PRIdMAX " bytes into %s", static_cast(fdin_size), target.c_str()); + bool slow_copy = true; #if HAVE_SENDFILE ssize_t sent_size = sendfile(fdout, fdin, NULL, fdin_size); - xbt_assert(sent_size == fdin_size, - "Error while copying %s: only %zd bytes copied instead of %" PRIdMAX " (errno: %d -- %s)", target.c_str(), - sent_size, static_cast(fdin_size), errno, strerror(errno)); -#else - const int bufsize = 1024 * 1024 * 4; - char buf[bufsize]; - while (int got = read(fdin, buf, bufsize)) { - if (got == -1) { - xbt_assert(errno == EINTR, "Cannot read from %s", src.c_str()); - } else { - char* p = buf; - int todo = got; - while (int done = write(fdout, p, todo)) { - if (done == -1) { - xbt_assert(errno == EINTR, "Cannot write into %s", target.c_str()); - } else { - p += done; - todo -= done; + if (sent_size == fdin_size) + slow_copy = false; + else if (sent_size != -1 || errno != ENOSYS) + xbt_die("Error while copying %s: only %zd bytes copied instead of %" PRIdMAX " (errno: %d -- %s)", target.c_str(), + sent_size, static_cast(fdin_size), errno, strerror(errno)); +#endif + if (slow_copy) { + const int bufsize = 1024 * 1024 * 4; + char buf[bufsize]; + while (int got = read(fdin, buf, bufsize)) { + if (got == -1) { + xbt_assert(errno == EINTR, "Cannot read from %s", src.c_str()); + } else { + char* p = buf; + int todo = got; + while (int done = write(fdout, p, todo)) { + if (done == -1) { + xbt_assert(errno == EINTR, "Cannot write into %s", target.c_str()); + } else { + p += done; + todo -= done; + } } } } } -#endif close(fdin); close(fdout); }