Merge branch 'devel' of https://github.com/pocoproject/poco into devel

This commit is contained in:
Alex Fabijanic 2022-06-29 19:57:03 +02:00
commit 076cddb465
7 changed files with 111 additions and 6 deletions

View File

@ -24,6 +24,7 @@
#elif defined(POCO_HAVE_FD_POLL)
#ifndef _WIN32
#include <poll.h>
#include "Poco/Pipe.h"
#endif
#endif
@ -226,6 +227,17 @@ private:
class PollSetImpl
{
public:
PollSetImpl()
{
pollfd fd{_pipe.readHandle(), POLLIN, 0};
_pollfds.push_back(fd);
}
~PollSetImpl()
{
_pipe.close();
}
void add(const Socket& socket, int mode)
{
Poco::FastMutex::ScopedLock lock(_mutex);
@ -280,7 +292,7 @@ public:
_socketMap.clear();
_addMap.clear();
_removeSet.clear();
_pollfds.clear();
_pollfds.reserve(1);
}
PollSet::SocketModeMap poll(const Poco::Timespan& timeout)
@ -341,11 +353,17 @@ public:
if (rc < 0) SocketImpl::error();
{
if (_pollfds[0].revents & POLLIN)
{
char c;
_pipe.readBytes(&c, 1);
}
Poco::FastMutex::ScopedLock lock(_mutex);
if (!_socketMap.empty())
{
for (auto it = _pollfds.begin(); it != _pollfds.end(); ++it)
for (auto it = _pollfds.begin() + 1; it != _pollfds.end(); ++it)
{
std::map<poco_socket_t, Socket>::const_iterator its = _socketMap.find(it->fd);
if (its != _socketMap.end())
@ -371,7 +389,8 @@ public:
void wakeUp()
{
// TODO
char c = 1;
_pipe.writeBytes(&c, 1);
}
int count() const
@ -396,6 +415,8 @@ private:
std::map<poco_socket_t, int> _addMap;
std::set<poco_socket_t> _removeSet;
std::vector<pollfd> _pollfds;
Poco::Pipe _pipe;
/// Add _pipe to head of _pollfds used to wake up poll blocking
};

View File

@ -138,7 +138,11 @@ void SocketReactor::stop()
void SocketReactor::wakeUp()
{
if (_pThread) _pThread->wakeUp();
if (_pThread && _pThread != Thread::current())
{
_pThread->wakeUp();
_pollSet.wakeUp();
}
}

View File

@ -12,6 +12,7 @@
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Poco/Net/MailMessage.h"
#include "Poco/Net/MailStream.h"
#include "Poco/Net/MailRecipient.h"
#include "Poco/Net/PartHandler.h"
#include "Poco/Net/StringPartSource.h"
@ -24,9 +25,12 @@
#include <sstream>
#include <fstream>
#include <vector>
#include <iostream>
using Poco::Net::MailMessage;
using Poco::Net::MailInputStream;
using Poco::Net::MailOutputStream;
using Poco::Net::MailRecipient;
using Poco::Net::MessageHeader;
using Poco::Net::PartHandler;
@ -364,6 +368,55 @@ void MailMessageTest::testReadDefaultTransferEncoding()
}
void MailMessageTest::testContentDisposition()
{
/*
// see https://github.com/pocoproject/poco/issues/3650
// Note "Content-disposition" casing,
// "Content-type" or "Content-transfer-encoding" do not cause problem
auto rawMessage =
"Date: Wed, 29 Jun 2022 08:25:48 GMT" "\r\n"
"Content-Type: multipart/mixed; boundary=MIME_boundary_5DBC66DE2780DE93" "\r\n"
"From: mySenderName<sender@send.pl>" "\r\n"
"Subject: mySubjct" "\r\n"
"To: <aja@o.pl>" "\r\n"
"Mime-Version: 1.0" "\r\n"
"\r\n"
"--MIME_boundary_5DBC66DE2780DE93" "\r\n"
"Content-Type: text/plain; charset=UTF-8" "\r\n"
"Content-Transfer-Encoding: quoted-printable" "\r\n"
"Content-Disposition: inline" "\r\n"
"\r\n"
"MyRealContent" "\r\n"
"--MIME_boundary_5DBC66DE2780DE93" "\r\n"
"Content-Type: text/plain; name=Plik" "\r\n"
"Content-Transfer-Encoding: base64" "\r\n"
"Content-disposition: attachment; filename=attachment.txt" "\r\n"
"\r\n"
"TXlBdHRhY2htZW50" "\r\n"
"--MIME_boundary_5DBC66DE2780DE93--" "\r\n"
"." "\r\n";
Poco::Net::MailMessage message;
//Convert raw message to message
std::istringstream is(rawMessage);
MailInputStream mis(is);
message.read(mis);
//get raw message again:
std::ostringstream oss;
MailOutputStream mos(oss);
message.write(mos);
mos.close();
auto plainMessage = oss.str();
assertEqual(rawMessage, plainMessage);
//std::cout << plain_message <<std::endl;
*/
}
void MailMessageTest::testRead8Bit()
{
std::istringstream istr(
@ -705,6 +758,7 @@ CppUnit::Test* MailMessageTest::suite()
CppUnit_addTest(pSuite, MailMessageTest, testWriteMultiPart);
CppUnit_addTest(pSuite, MailMessageTest, testReadQP);
CppUnit_addTest(pSuite, MailMessageTest, testReadDefaultTransferEncoding);
CppUnit_addTest(pSuite, MailMessageTest, testContentDisposition);
CppUnit_addTest(pSuite, MailMessageTest, testRead8Bit);
CppUnit_addTest(pSuite, MailMessageTest, testReadMultiPart);
CppUnit_addTest(pSuite, MailMessageTest, testReadMultiPartDefaultTransferEncoding);

View File

@ -32,6 +32,7 @@ public:
void testReadWriteMultiPart();
void testReadWriteMultiPartStore();
void testReadDefaultTransferEncoding();
void testContentDisposition();
void testReadQP();
void testRead8Bit();
void testReadMultiPart();

View File

@ -288,7 +288,7 @@ void PollSetTest::testPollClosedServer()
void PollSetTest::testPollSetWakeUp()
{
#if defined(POCO_HAVE_FD_EPOLL)
#if defined(POCO_HAVE_FD_EPOLL) || defined (POCO_HAVE_FD_POLL)
PollSet ps;
Timespan timeout(100000000); // 100 seconds
Poller poller(ps, timeout);
@ -304,7 +304,7 @@ void PollSetTest::testPollSetWakeUp()
assertTrue(sw.elapsedSeconds() < 1);
#else // TODO: other implementations
std::cout << "not implemented";
#endif // POCO_HAVE_FD_EPOLL
#endif // POCO_HAVE_FD_EPOLL || POCO_HAVE_FD_EPOLL
}

View File

@ -161,6 +161,15 @@ public:
/// underlying TCP connection. No orderly SSL shutdown
/// is performed.
void setBlocking(bool flag);
/// Sets the socket in blocking mode if flag is true,
/// disables blocking mode if flag is false.
bool getBlocking() const;
/// Returns the blocking mode of the socket.
/// This method will only work if the blocking modes of
/// the socket are changed via the setBlocking method!
int sendBytes(const void* buffer, int length, int flags = 0);
/// Sends the contents of the given buffer through
/// the socket. Any specified flags are ignored.

View File

@ -311,6 +311,22 @@ void SecureSocketImpl::close()
}
void SecureSocketImpl::setBlocking(bool flag)
{
poco_check_ptr (_pSocket);
_pSocket->setBlocking(flag);
}
bool SecureSocketImpl::getBlocking() const
{
poco_check_ptr (_pSocket);
return _pSocket->getBlocking();
}
int SecureSocketImpl::sendBytes(const void* buffer, int length, int flags)
{
poco_assert (_pSocket->initialized());