diff --git a/Net/src/SocketImpl.cpp b/Net/src/SocketImpl.cpp index a3f9aa198d..536d0ed77d 100644 --- a/Net/src/SocketImpl.cpp +++ b/Net/src/SocketImpl.cpp @@ -56,7 +56,7 @@ using sighandler_t = sig_t; #endif -#if POCO_OS == POCO_OS_LINUX +#if POCO_OS == POCO_OS_LINUX && !defined(POCO_EMSCRIPTEN) #include #endif @@ -1422,6 +1422,8 @@ Poco::Int64 _sendfile(poco_socket_t sd, FileIOS::NativeHandle fd, Poco::UInt64 o { sent = sentSize; } +#else + throw Poco::NotImplementedException("sendfile not implemented for this platform"); #endif #endif if (errno == EAGAIN || errno == EWOULDBLOCK) @@ -1438,7 +1440,8 @@ Poco::Int64 SocketImpl::sendFile(FileInputStream &fileInputStream, Poco::UInt64 std::streamoff sentSize = fileSize - offset; Poco::Int64 sent = 0; sighandler_t sigPrev = signal(SIGPIPE, SIG_IGN); - while (sent == 0) { + while (sent == 0) + { errno = 0; sent = _sendfile(_sockfd, fd, offset, sentSize); } diff --git a/Net/testsuite/src/SocketStreamTest.cpp b/Net/testsuite/src/SocketStreamTest.cpp index 1901dc384e..d4b6e6ca9a 100644 --- a/Net/testsuite/src/SocketStreamTest.cpp +++ b/Net/testsuite/src/SocketStreamTest.cpp @@ -21,6 +21,7 @@ #include "Poco/Stopwatch.h" #include "Poco/FileStream.h" #include "Poco/File.h" +#include "Poco/Path.h" using Poco::Net::Socket; @@ -127,7 +128,8 @@ void SocketStreamTest::testSendFile() { const int fileSize = 64000; std::string payload(fileSize, 'x'); - const std::string fileName = "test.sendfile.txt"; + Poco::Path testFilePath = Poco::Path::temp().append("test.sendfile.txt"); + const std::string fileName = testFilePath.toString(); { File f(fileName); if (f.exists()) @@ -147,7 +149,15 @@ void SocketStreamTest::testSendFile() Poco::UInt64 offset = 0; Poco::Int64 sent = 0; + try + { sent = ss.sendFile(fin); + } + catch (Poco::NotImplementedException &) + { + std::cout << "[NOT IMPLEMENTED]\n"; + return; + } assertTrue(sent >= 0); while (sent < fileSize) {