default disable new state on move

This commit is contained in:
Alex Fabijanic
2022-05-27 13:32:24 -05:00
parent 3e6e259c2a
commit 216d5ae3a4
7 changed files with 114 additions and 60 deletions

View File

@@ -147,13 +147,12 @@
// #define POCO_NET_NO_UNIX_SOCKET // #define POCO_NET_NO_UNIX_SOCKET
// Define to nonzero to enable move // Define to nonzero to enable move semantics
// semantics on classes where it // on classes where it introduces a new state.
// introduces a new state. // For explanation, see:
// For explanation, see
// https://github.com/pocoproject/poco/wiki/Move-Semantics-in-POCO // https://github.com/pocoproject/poco/wiki/Move-Semantics-in-POCO
#ifndef POCO_NEW_STATE_ON_MOVE #ifndef POCO_NEW_STATE_ON_MOVE
#define POCO_NEW_STATE_ON_MOVE 1 // #define POCO_NEW_STATE_ON_MOVE 1
#endif #endif

View File

@@ -22,6 +22,11 @@
#include "Poco/Net/SocketImpl.h" #include "Poco/Net/SocketImpl.h"
#include <vector> #include <vector>
#ifdef POCO_NEW_STATE_ON_MOVE
#define POCO_CHECK_NEW_STATE_ON_MOVE poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl);
#else
#define POCO_CHECK_NEW_STATE_ON_MOVE
#endif
namespace Poco { namespace Poco {
namespace Net { namespace Net {
@@ -485,7 +490,7 @@ inline void Socket::close()
inline bool Socket::poll(const Poco::Timespan& timeout, int mode) const inline bool Socket::poll(const Poco::Timespan& timeout, int mode) const
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
return _pImpl->poll(timeout, mode); return _pImpl->poll(timeout, mode);
} }
@@ -493,7 +498,7 @@ inline bool Socket::poll(const Poco::Timespan& timeout, int mode) const
inline int Socket::available() const inline int Socket::available() const
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
return _pImpl->available(); return _pImpl->available();
} }
@@ -501,7 +506,7 @@ inline int Socket::available() const
inline int Socket::getError() const inline int Socket::getError() const
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
return _pImpl->getError(); return _pImpl->getError();
} }
@@ -509,7 +514,7 @@ inline int Socket::getError() const
inline void Socket::setSendBufferSize(int size) inline void Socket::setSendBufferSize(int size)
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
_pImpl->setSendBufferSize(size); _pImpl->setSendBufferSize(size);
} }
@@ -517,7 +522,7 @@ inline void Socket::setSendBufferSize(int size)
inline int Socket::getSendBufferSize() const inline int Socket::getSendBufferSize() const
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
return _pImpl->getSendBufferSize(); return _pImpl->getSendBufferSize();
} }
@@ -525,7 +530,7 @@ inline int Socket::getSendBufferSize() const
inline void Socket::setReceiveBufferSize(int size) inline void Socket::setReceiveBufferSize(int size)
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
_pImpl->setReceiveBufferSize(size); _pImpl->setReceiveBufferSize(size);
} }
@@ -533,7 +538,7 @@ inline void Socket::setReceiveBufferSize(int size)
inline int Socket::getReceiveBufferSize() const inline int Socket::getReceiveBufferSize() const
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
return _pImpl->getReceiveBufferSize(); return _pImpl->getReceiveBufferSize();
} }
@@ -541,7 +546,7 @@ inline int Socket::getReceiveBufferSize() const
inline void Socket::setSendTimeout(const Poco::Timespan& timeout) inline void Socket::setSendTimeout(const Poco::Timespan& timeout)
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
_pImpl->setSendTimeout(timeout); _pImpl->setSendTimeout(timeout);
} }
@@ -549,7 +554,7 @@ inline void Socket::setSendTimeout(const Poco::Timespan& timeout)
inline Poco::Timespan Socket::getSendTimeout() const inline Poco::Timespan Socket::getSendTimeout() const
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
return _pImpl->getSendTimeout(); return _pImpl->getSendTimeout();
} }
@@ -557,7 +562,7 @@ inline Poco::Timespan Socket::getSendTimeout() const
inline void Socket::setReceiveTimeout(const Poco::Timespan& timeout) inline void Socket::setReceiveTimeout(const Poco::Timespan& timeout)
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
_pImpl->setReceiveTimeout(timeout); _pImpl->setReceiveTimeout(timeout);
} }
@@ -565,7 +570,7 @@ inline void Socket::setReceiveTimeout(const Poco::Timespan& timeout)
inline Poco::Timespan Socket::getReceiveTimeout() const inline Poco::Timespan Socket::getReceiveTimeout() const
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
return _pImpl->getReceiveTimeout(); return _pImpl->getReceiveTimeout();
} }
@@ -573,7 +578,7 @@ inline Poco::Timespan Socket::getReceiveTimeout() const
inline void Socket::setOption(int level, int option, int value) inline void Socket::setOption(int level, int option, int value)
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
_pImpl->setOption(level, option, value); _pImpl->setOption(level, option, value);
} }
@@ -581,7 +586,7 @@ inline void Socket::setOption(int level, int option, int value)
inline void Socket::setOption(int level, int option, unsigned value) inline void Socket::setOption(int level, int option, unsigned value)
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
_pImpl->setOption(level, option, value); _pImpl->setOption(level, option, value);
} }
@@ -589,7 +594,7 @@ inline void Socket::setOption(int level, int option, unsigned value)
inline void Socket::setOption(int level, int option, unsigned char value) inline void Socket::setOption(int level, int option, unsigned char value)
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
_pImpl->setOption(level, option, value); _pImpl->setOption(level, option, value);
} }
@@ -597,7 +602,7 @@ inline void Socket::setOption(int level, int option, unsigned char value)
inline void Socket::setOption(int level, int option, const Poco::Timespan& value) inline void Socket::setOption(int level, int option, const Poco::Timespan& value)
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
_pImpl->setOption(level, option, value); _pImpl->setOption(level, option, value);
} }
@@ -605,7 +610,7 @@ inline void Socket::setOption(int level, int option, const Poco::Timespan& value
inline void Socket::setOption(int level, int option, const IPAddress& value) inline void Socket::setOption(int level, int option, const IPAddress& value)
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
_pImpl->setOption(level, option, value); _pImpl->setOption(level, option, value);
} }
@@ -613,7 +618,7 @@ inline void Socket::setOption(int level, int option, const IPAddress& value)
inline void Socket::getOption(int level, int option, int& value) const inline void Socket::getOption(int level, int option, int& value) const
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
_pImpl->getOption(level, option, value); _pImpl->getOption(level, option, value);
} }
@@ -621,7 +626,7 @@ inline void Socket::getOption(int level, int option, int& value) const
inline void Socket::getOption(int level, int option, unsigned& value) const inline void Socket::getOption(int level, int option, unsigned& value) const
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
_pImpl->getOption(level, option, value); _pImpl->getOption(level, option, value);
} }
@@ -629,7 +634,7 @@ inline void Socket::getOption(int level, int option, unsigned& value) const
inline void Socket::getOption(int level, int option, unsigned char& value) const inline void Socket::getOption(int level, int option, unsigned char& value) const
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
_pImpl->getOption(level, option, value); _pImpl->getOption(level, option, value);
} }
@@ -637,7 +642,7 @@ inline void Socket::getOption(int level, int option, unsigned char& value) const
inline void Socket::getOption(int level, int option, Poco::Timespan& value) const inline void Socket::getOption(int level, int option, Poco::Timespan& value) const
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
_pImpl->getOption(level, option, value); _pImpl->getOption(level, option, value);
} }
@@ -645,7 +650,7 @@ inline void Socket::getOption(int level, int option, Poco::Timespan& value) cons
inline void Socket::getOption(int level, int option, IPAddress& value) const inline void Socket::getOption(int level, int option, IPAddress& value) const
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
_pImpl->getOption(level, option, value); _pImpl->getOption(level, option, value);
} }
@@ -653,7 +658,7 @@ inline void Socket::getOption(int level, int option, IPAddress& value) const
inline void Socket::setLinger(bool on, int seconds) inline void Socket::setLinger(bool on, int seconds)
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
_pImpl->setLinger(on, seconds); _pImpl->setLinger(on, seconds);
} }
@@ -661,7 +666,7 @@ inline void Socket::setLinger(bool on, int seconds)
inline void Socket::getLinger(bool& on, int& seconds) const inline void Socket::getLinger(bool& on, int& seconds) const
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
_pImpl->getLinger(on, seconds); _pImpl->getLinger(on, seconds);
} }
@@ -669,7 +674,7 @@ inline void Socket::getLinger(bool& on, int& seconds) const
inline void Socket::setNoDelay(bool flag) inline void Socket::setNoDelay(bool flag)
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
_pImpl->setNoDelay(flag); _pImpl->setNoDelay(flag);
} }
@@ -677,7 +682,7 @@ inline void Socket::setNoDelay(bool flag)
inline bool Socket::getNoDelay() const inline bool Socket::getNoDelay() const
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
return _pImpl->getNoDelay(); return _pImpl->getNoDelay();
} }
@@ -685,7 +690,7 @@ inline bool Socket::getNoDelay() const
inline void Socket::setKeepAlive(bool flag) inline void Socket::setKeepAlive(bool flag)
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
_pImpl->setKeepAlive(flag); _pImpl->setKeepAlive(flag);
} }
@@ -693,7 +698,7 @@ inline void Socket::setKeepAlive(bool flag)
inline bool Socket::getKeepAlive() const inline bool Socket::getKeepAlive() const
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
return _pImpl->getKeepAlive(); return _pImpl->getKeepAlive();
} }
@@ -701,7 +706,7 @@ inline bool Socket::getKeepAlive() const
inline void Socket::setReuseAddress(bool flag) inline void Socket::setReuseAddress(bool flag)
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
_pImpl->setReuseAddress(flag); _pImpl->setReuseAddress(flag);
} }
@@ -709,7 +714,7 @@ inline void Socket::setReuseAddress(bool flag)
inline bool Socket::getReuseAddress() const inline bool Socket::getReuseAddress() const
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
return _pImpl->getReuseAddress(); return _pImpl->getReuseAddress();
} }
@@ -717,7 +722,7 @@ inline bool Socket::getReuseAddress() const
inline void Socket::setReusePort(bool flag) inline void Socket::setReusePort(bool flag)
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
_pImpl->setReusePort(flag); _pImpl->setReusePort(flag);
} }
@@ -725,7 +730,7 @@ inline void Socket::setReusePort(bool flag)
inline bool Socket::getReusePort() const inline bool Socket::getReusePort() const
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
return _pImpl->getReusePort(); return _pImpl->getReusePort();
} }
@@ -733,7 +738,7 @@ inline bool Socket::getReusePort() const
inline void Socket::setOOBInline(bool flag) inline void Socket::setOOBInline(bool flag)
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
_pImpl->setOOBInline(flag); _pImpl->setOOBInline(flag);
} }
@@ -741,7 +746,7 @@ inline void Socket::setOOBInline(bool flag)
inline bool Socket::getOOBInline() const inline bool Socket::getOOBInline() const
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
return _pImpl->getOOBInline(); return _pImpl->getOOBInline();
} }
@@ -749,7 +754,7 @@ inline bool Socket::getOOBInline() const
inline void Socket::setBlocking(bool flag) inline void Socket::setBlocking(bool flag)
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
_pImpl->setBlocking(flag); _pImpl->setBlocking(flag);
} }
@@ -757,7 +762,7 @@ inline void Socket::setBlocking(bool flag)
inline bool Socket::getBlocking() const inline bool Socket::getBlocking() const
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
return _pImpl->getBlocking(); return _pImpl->getBlocking();
} }
@@ -771,7 +776,7 @@ inline SocketImpl* Socket::impl() const
inline poco_socket_t Socket::sockfd() const inline poco_socket_t Socket::sockfd() const
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
return _pImpl->sockfd(); return _pImpl->sockfd();
} }
@@ -779,7 +784,7 @@ inline poco_socket_t Socket::sockfd() const
inline SocketAddress Socket::address() const inline SocketAddress Socket::address() const
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
return _pImpl->address(); return _pImpl->address();
} }
@@ -787,7 +792,7 @@ inline SocketAddress Socket::address() const
inline SocketAddress Socket::peerAddress() const inline SocketAddress Socket::peerAddress() const
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
return _pImpl->peerAddress(); return _pImpl->peerAddress();
} }
@@ -795,7 +800,7 @@ inline SocketAddress Socket::peerAddress() const
inline bool Socket::secure() const inline bool Socket::secure() const
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
return _pImpl->secure(); return _pImpl->secure();
} }
@@ -819,7 +824,7 @@ inline bool Socket::supportsIPv6()
inline void Socket::init(int af) inline void Socket::init(int af)
{ {
poco_assert_dbg(POCO_NEW_STATE_ON_MOVE && _pImpl); POCO_CHECK_NEW_STATE_ON_MOVE;
_pImpl->init(af); _pImpl->init(af);
} }

View File

@@ -54,11 +54,13 @@ RawSocket::RawSocket(const RawSocket& socket): Socket(socket)
{ {
} }
#ifdef POCO_NEW_STATE_ON_MOVE
RawSocket::RawSocket(RawSocket&& socket): Socket(std::move(socket)) RawSocket::RawSocket(RawSocket&& socket): Socket(std::move(socket))
{ {
} }
#endif // POCO_NEW_STATE_ON_MOVE
RawSocket::RawSocket(SocketImpl* pImpl): Socket(pImpl) RawSocket::RawSocket(SocketImpl* pImpl): Socket(pImpl)
{ {
@@ -82,6 +84,8 @@ RawSocket& RawSocket::operator = (const Socket& socket)
} }
#ifdef POCO_NEW_STATE_ON_MOVE
RawSocket& RawSocket::operator = (Socket&& socket) RawSocket& RawSocket::operator = (Socket&& socket)
{ {
if (dynamic_cast<RawSocketImpl*>(socket.impl())) if (dynamic_cast<RawSocketImpl*>(socket.impl()))
@@ -91,6 +95,7 @@ RawSocket& RawSocket::operator = (Socket&& socket)
return *this; return *this;
} }
#endif // POCO_NEW_STATE_ON_MOVE
RawSocket& RawSocket::operator = (const RawSocket& socket) RawSocket& RawSocket::operator = (const RawSocket& socket)
{ {
@@ -99,12 +104,15 @@ RawSocket& RawSocket::operator = (const RawSocket& socket)
} }
#ifdef POCO_NEW_STATE_ON_MOVE
RawSocket& RawSocket::operator = (RawSocket&& socket) RawSocket& RawSocket::operator = (RawSocket&& socket)
{ {
Socket::operator = (std::move(socket)); Socket::operator = (std::move(socket));
return *this; return *this;
} }
#endif // POCO_NEW_STATE_ON_MOVE
void RawSocket::connect(const SocketAddress& address) void RawSocket::connect(const SocketAddress& address)
{ {

View File

@@ -65,6 +65,8 @@ WebSocket::WebSocket(const Socket& socket):
} }
#ifdef POCO_NEW_STATE_ON_MOVE
WebSocket::WebSocket(Socket&& socket): WebSocket::WebSocket(Socket&& socket):
StreamSocket(std::move(socket)) StreamSocket(std::move(socket))
{ {
@@ -73,14 +75,16 @@ WebSocket::WebSocket(Socket&& socket):
} }
WebSocket::WebSocket(const WebSocket& socket): WebSocket::WebSocket(WebSocket&& socket):
StreamSocket(socket) StreamSocket(std::move(socket))
{ {
} }
#endif // POCO_NEW_STATE_ON_MOVE
WebSocket::WebSocket(WebSocket&& socket):
StreamSocket(std::move(socket)) WebSocket::WebSocket(const WebSocket& socket):
StreamSocket(socket)
{ {
} }
@@ -100,6 +104,8 @@ WebSocket& WebSocket::operator = (const Socket& socket)
} }
#ifdef POCO_NEW_STATE_ON_MOVE
WebSocket& WebSocket::operator = (Socket&& socket) WebSocket& WebSocket::operator = (Socket&& socket)
{ {
if (dynamic_cast<WebSocketImpl*>(socket.impl())) if (dynamic_cast<WebSocketImpl*>(socket.impl()))
@@ -110,19 +116,21 @@ WebSocket& WebSocket::operator = (Socket&& socket)
} }
WebSocket& WebSocket::operator = (const WebSocket& socket)
{
Socket::operator = (socket);
return *this;
}
WebSocket& WebSocket::operator = (WebSocket&& socket) WebSocket& WebSocket::operator = (WebSocket&& socket)
{ {
Socket::operator = (std::move(socket)); Socket::operator = (std::move(socket));
return *this; return *this;
} }
#endif // POCO_NEW_STATE_ON_MOVE
WebSocket& WebSocket::operator = (const WebSocket& socket)
{
Socket::operator = (socket);
return *this;
}
void WebSocket::shutdown() void WebSocket::shutdown()
{ {

View File

@@ -91,7 +91,10 @@ void RawSocketTest::testEchoIPv4Move()
rs0.connect(sa); rs0.connect(sa);
RawSocket rs(std::move(rs0)); RawSocket rs(std::move(rs0));
#ifdef POCO_NEW_STATE_ON_MOVE
assertTrue (rs0.impl() == nullptr); assertTrue (rs0.impl() == nullptr);
#endif // POCO_NEW_STATE_ON_MOVE
int n = rs.sendBytes("hello", 5); int n = rs.sendBytes("hello", 5);
assertTrue (5 == n); assertTrue (5 == n);

View File

@@ -65,7 +65,14 @@ void SocketProactorTest::testTCPSocketProactor()
received = true; received = true;
}; };
proactor.addReceive(s, buf, onRecvCompletion); proactor.addReceive(s, buf, onRecvCompletion);
while (!received) proactor.poll(); Stopwatch sw;
sw.start();
while (!received)
{
if (sw.elapsedSeconds() > 1)
fail("SocketProactor receive completion timed out.", __LINE__, __FILE__);
proactor.poll();
}
assertTrue (sent); assertTrue (sent);
assertTrue (sendPassed); assertTrue (sendPassed);
@@ -84,8 +91,11 @@ void SocketProactorTest::testTCPSocketProactor()
proactor.addSend(s, SocketProactor::Buffer(hello.begin(), hello.end()), nullptr); proactor.addSend(s, SocketProactor::Buffer(hello.begin(), hello.end()), nullptr);
proactor.addReceive(s, buf, nullptr); proactor.addReceive(s, buf, nullptr);
int handled = 0, handledTot = 0; int handled = 0, handledTot = 0;
sw.restart();
do do
{ {
if (sw.elapsedSeconds() > 1)
fail("SocketProactor receive completion timed out.", __LINE__, __FILE__);
proactor.poll(&handled); proactor.poll(&handled);
handledTot += handled; handledTot += handled;
} }
@@ -109,7 +119,13 @@ void SocketProactorTest::testTCPSocketProactor()
errSock.connectNB(SocketAddress("127.0.0.1", 0xFFEE)); errSock.connectNB(SocketAddress("127.0.0.1", 0xFFEE));
proactor.addSend(errSock, SocketProactor::Buffer(hello.begin(), hello.end()), onError); proactor.addSend(errSock, SocketProactor::Buffer(hello.begin(), hello.end()), onError);
Thread::sleep(100); Thread::sleep(100);
while (!error) proactor.poll(); sw.restart();
while (!error)
{
if (sw.elapsedSeconds() > 1)
fail("SocketProactor send completion timed out.", __LINE__, __FILE__);
proactor.poll();
}
assertTrue (error); assertTrue (error);
assertTrue(errorPassed); assertTrue(errorPassed);
} }
@@ -227,7 +243,14 @@ void SocketProactorTest::testSocketProactorStartStop()
}; };
proactor.addReceiveFrom(s, buf, sa, onRecvCompletion); proactor.addReceiveFrom(s, buf, sa, onRecvCompletion);
while (!received) proactor.poll(); Stopwatch sw;
sw.start();
while (!received)
{
if (sw.elapsedSeconds() > 1)
fail("SocketProactor receiveFrom timed out.", __LINE__, __FILE__);
proactor.poll();
}
assertTrue (sent); assertTrue (sent);
assertTrue (sendPassed); assertTrue (sendPassed);
@@ -253,7 +276,13 @@ void SocketProactorTest::testSocketProactorStartStop()
SocketAddress("127.0.0.1", echoServer.port()), SocketAddress("127.0.0.1", echoServer.port()),
onSendCompletion); onSendCompletion);
proactor.addReceiveFrom(s, buf, sa, onRecvCompletion); proactor.addReceiveFrom(s, buf, sa, onRecvCompletion);
while (!received) proactor.poll(); sw.restart();
while (!received)
{
if (sw.elapsedSeconds() > 1)
fail("SocketProactor receiveFrom timed out.", __LINE__, __FILE__);
proactor.poll();
}
assertTrue(std::string(buf.begin(), buf.end()) == hello); assertTrue(std::string(buf.begin(), buf.end()) == hello);
assertTrue (sent); assertTrue (sent);

View File

@@ -123,7 +123,9 @@ void WebSocketTest::testWebSocket()
HTTPResponse response; HTTPResponse response;
WebSocket ws0 = WebSocket(cs, request, response); WebSocket ws0 = WebSocket(cs, request, response);
WebSocket ws(std::move(ws0)); WebSocket ws(std::move(ws0));
#ifdef POCO_NEW_STATE_ON_MOVE
assertTrue(ws0.impl() == nullptr); assertTrue(ws0.impl() == nullptr);
#endif
std::string payload("x"); std::string payload("x");
ws.sendFrame(payload.data(), (int) payload.size()); ws.sendFrame(payload.data(), (int) payload.size());