mirror of
https://github.com/pocoproject/poco.git
synced 2025-11-23 13:32:11 +01:00
Feature net udp (#2347)
* add PMTU discovery #2329 * add socket gather/scatter capabilities #2330 (win, udp) * enable WSAPoll * add FastMemoryPool * add receiveFrom() with native args * allow copying of StringTokenizer * add AtomicFlag and SpinlockMutex * update .gitignore * UDPServer and client #2343 (windows) * fix warnings * fix warnings * regenerate Net VS solutions * regenerate CppUnit projects/solutions * clang fixes * gcc fixes * try to fix travis * more travis fixes * more travis fixes * handle UDPClient exception * fix makefiles and init order warnings * add UNIX gather/scatter sendto/recvfrom implementations and tests * run travis tests as sudo * try to run tests as sudo, 2nd attempt * fix warning * use mutex in reactor * lock-order-inversion in SocketReactor #2346 * add PMTU discovery #2329 (linux) * ICMPSocket does not check reply address #1921 * remove some ignored tests * add PMTU discovery #2329 (reconcile logic with #1921) * fix native receiveFrome() * reinstate ignoring of proxy errors * add testMTU to ignore list * add include atomic * NTPClient not checking reply address #2348 * some ICMP/MTU fixes * UDPSocketReader cleanup * resolve some socket inheritance warnings * add NTP time sync to ignored tests * SocketNotifier not thread-safe #2345 * prevent x64 samples build attempt for win32 * build TestApp and Library * fix ICMP tests * regen VS projects * regen VS projects and add missing 2012 files * remove debug prints
This commit is contained in:
committed by
GitHub
parent
da15142f69
commit
c4e676d36d
@@ -17,7 +17,9 @@
|
||||
#include "Poco/Net/NetworkInterface.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include "Poco/Timespan.h"
|
||||
#include "Poco/Buffer.h"
|
||||
#include "Poco/Stopwatch.h"
|
||||
#include <cstring>
|
||||
|
||||
|
||||
using Poco::Net::Socket;
|
||||
@@ -28,6 +30,7 @@ using Poco::Net::IPAddress;
|
||||
using Poco::Net::NetworkInterface;
|
||||
#endif
|
||||
using Poco::Timespan;
|
||||
using Poco::Buffer;
|
||||
using Poco::Stopwatch;
|
||||
using Poco::TimeoutException;
|
||||
using Poco::InvalidArgumentException;
|
||||
@@ -59,6 +62,25 @@ void DatagramSocketTest::testEcho()
|
||||
}
|
||||
|
||||
|
||||
void DatagramSocketTest::testEchoBuffer()
|
||||
{
|
||||
UDPEchoServer echoServer;
|
||||
DatagramSocket ss;
|
||||
Buffer<char> buffer(0);
|
||||
ss.connect(SocketAddress("127.0.0.1", echoServer.port()));
|
||||
int n = ss.receiveBytes(buffer);
|
||||
assertTrue (n == 0);
|
||||
assertTrue (buffer.size() == 0);
|
||||
n = ss.sendBytes("hello", 5);
|
||||
assertTrue (n == 5);
|
||||
n = ss.receiveBytes(buffer);
|
||||
assertTrue (n == 5);
|
||||
assertTrue (buffer.size() == 5);
|
||||
assertTrue (std::string(buffer.begin(), n) == "hello");
|
||||
ss.close();
|
||||
}
|
||||
|
||||
|
||||
void DatagramSocketTest::testSendToReceiveFrom()
|
||||
{
|
||||
UDPEchoServer echoServer(SocketAddress("127.0.0.1", 0));
|
||||
@@ -133,6 +155,443 @@ void DatagramSocketTest::testBroadcast()
|
||||
}
|
||||
|
||||
|
||||
void DatagramSocketTest::testGatherScatterFixed()
|
||||
{
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||
testGatherScatterFixedWin();
|
||||
testGatherScatterSTRFFixedWin();
|
||||
#elif defined(POCO_OS_FAMILY_UNIX)
|
||||
testGatherScatterFixedUNIX();
|
||||
testGatherScatterSTRFFixedUNIX();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void DatagramSocketTest::testGatherScatterFixedWin()
|
||||
{
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||
UDPEchoServer echoServer;
|
||||
DatagramSocket ss;
|
||||
Socket::BufVec sbv = Socket::makeBufVec(3, 10);
|
||||
assertTrue (sbv.size() == 3);
|
||||
|
||||
std::memcpy(sbv[0].buf, "1234567890", 10);
|
||||
std::memcpy(sbv[1].buf, "abcdefghij", 10);
|
||||
std::memcpy(sbv[2].buf, "helloworld", 10);
|
||||
|
||||
ss.connect(SocketAddress("127.0.0.1", echoServer.port()));
|
||||
int n = ss.sendBytes(sbv);
|
||||
assertTrue (n == 30);
|
||||
|
||||
std::memset(sbv[0].buf, 0, 10);
|
||||
std::memset(sbv[1].buf, 0, 10);
|
||||
std::memset(sbv[2].buf, 0, 10);
|
||||
|
||||
char empty[10] = {};
|
||||
assertTrue (0 == std::memcmp(sbv[0].buf, empty, 10));
|
||||
assertTrue (0 == std::memcmp(sbv[1].buf, empty, 10));
|
||||
assertTrue (0 == std::memcmp(sbv[2].buf, empty, 10));
|
||||
|
||||
n = ss.receiveBytes(sbv);
|
||||
assertTrue (n == 30);
|
||||
|
||||
assertTrue (0 == std::memcmp(sbv[0].buf, "1234567890", 10));
|
||||
assertTrue (0 == std::memcmp(sbv[1].buf, "abcdefghij", 10));
|
||||
assertTrue (0 == std::memcmp(sbv[2].buf, "helloworld", 10));
|
||||
|
||||
Socket::destroyBufVec(sbv);
|
||||
|
||||
ss.close();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void DatagramSocketTest::testGatherScatterSTRFFixedWin()
|
||||
{
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||
UDPEchoServer echoServer(SocketAddress("127.0.0.1", 0));
|
||||
DatagramSocket ss;
|
||||
Socket::BufVec sbv = Socket::makeBufVec(3, 10);
|
||||
assertTrue (sbv.size() == 3);
|
||||
|
||||
std::memcpy(sbv[0].buf, "1234567890", 10);
|
||||
std::memcpy(sbv[1].buf, "abcdefghij", 10);
|
||||
std::memcpy(sbv[2].buf, "helloworld", 10);
|
||||
|
||||
ss.connect(SocketAddress("127.0.0.1", echoServer.port()));
|
||||
int n = ss.sendTo(sbv, SocketAddress("127.0.0.1", echoServer.port()));
|
||||
assertTrue (n == 30);
|
||||
|
||||
std::memset(sbv[0].buf, 0, 10);
|
||||
std::memset(sbv[1].buf, 0, 10);
|
||||
std::memset(sbv[2].buf, 0, 10);
|
||||
|
||||
char empty[10] = {};
|
||||
assertTrue (0 == std::memcmp(sbv[0].buf, empty, 10));
|
||||
assertTrue (0 == std::memcmp(sbv[1].buf, empty, 10));
|
||||
assertTrue (0 == std::memcmp(sbv[2].buf, empty, 10));
|
||||
|
||||
SocketAddress sa;
|
||||
n = ss.receiveFrom(sbv, sa);
|
||||
assertTrue (sa.host() == echoServer.address().host());
|
||||
assertTrue (sa.port() == echoServer.port());
|
||||
assertTrue (n == 30);
|
||||
|
||||
assertTrue (0 == std::memcmp(sbv[0].buf, "1234567890", 10));
|
||||
assertTrue (0 == std::memcmp(sbv[1].buf, "abcdefghij", 10));
|
||||
assertTrue (0 == std::memcmp(sbv[2].buf, "helloworld", 10));
|
||||
|
||||
Socket::destroyBufVec(sbv);
|
||||
|
||||
ss.close();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void DatagramSocketTest::testGatherScatterFixedUNIX()
|
||||
{
|
||||
#if defined(POCO_OS_FAMILY_UNIX)
|
||||
UDPEchoServer echoServer;
|
||||
DatagramSocket ss;
|
||||
Socket::BufVec sbv = Socket::makeBufVec(3, 10);
|
||||
assertTrue (sbv.size() == 3);
|
||||
|
||||
std::memcpy(sbv[0].iov_base, "1234567890", 10);
|
||||
std::memcpy(sbv[1].iov_base, "abcdefghij", 10);
|
||||
std::memcpy(sbv[2].iov_base, "helloworld", 10);
|
||||
|
||||
ss.connect(SocketAddress("127.0.0.1", echoServer.port()));
|
||||
int n = ss.sendBytes(sbv);
|
||||
assertTrue (n == 30);
|
||||
|
||||
std::memset(sbv[0].iov_base, 0, 10);
|
||||
std::memset(sbv[1].iov_base, 0, 10);
|
||||
std::memset(sbv[2].iov_base, 0, 10);
|
||||
|
||||
char empty[10] = {};
|
||||
assertTrue (0 == std::memcmp(sbv[0].iov_base, empty, 10));
|
||||
assertTrue (0 == std::memcmp(sbv[1].iov_base, empty, 10));
|
||||
assertTrue (0 == std::memcmp(sbv[2].iov_base, empty, 10));
|
||||
|
||||
n = ss.receiveBytes(sbv);
|
||||
assertTrue (n == 30);
|
||||
|
||||
assertTrue (0 == std::memcmp(sbv[0].iov_base, "1234567890", 10));
|
||||
assertTrue (0 == std::memcmp(sbv[1].iov_base, "abcdefghij", 10));
|
||||
assertTrue (0 == std::memcmp(sbv[2].iov_base, "helloworld", 10));
|
||||
|
||||
Socket::destroyBufVec(sbv);
|
||||
|
||||
ss.close();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void DatagramSocketTest::testGatherScatterSTRFFixedUNIX()
|
||||
{
|
||||
#if defined(POCO_OS_FAMILY_UNIX)
|
||||
UDPEchoServer echoServer(SocketAddress("127.0.0.1", 0));
|
||||
DatagramSocket ss;
|
||||
Socket::BufVec sbv = Socket::makeBufVec(3, 10);
|
||||
assertTrue (sbv.size() == 3);
|
||||
|
||||
std::memcpy(sbv[0].iov_base, "1234567890", 10);
|
||||
std::memcpy(sbv[1].iov_base, "abcdefghij", 10);
|
||||
std::memcpy(sbv[2].iov_base, "helloworld", 10);
|
||||
|
||||
int n = ss.sendTo(sbv, SocketAddress("127.0.0.1", echoServer.port()));
|
||||
assertTrue (n == 30);
|
||||
|
||||
std::memset(sbv[0].iov_base, 0, 10);
|
||||
std::memset(sbv[1].iov_base, 0, 10);
|
||||
std::memset(sbv[2].iov_base, 0, 10);
|
||||
|
||||
char empty[10] = {};
|
||||
assertTrue (0 == std::memcmp(sbv[0].iov_base, empty, 10));
|
||||
assertTrue (0 == std::memcmp(sbv[1].iov_base, empty, 10));
|
||||
assertTrue (0 == std::memcmp(sbv[2].iov_base, empty, 10));
|
||||
|
||||
SocketAddress sa;
|
||||
n = ss.receiveFrom(sbv, sa);
|
||||
assertTrue (sa.host() == echoServer.address().host());
|
||||
assertTrue (sa.port() == echoServer.port());
|
||||
assertTrue (n == 30);
|
||||
|
||||
assertTrue (0 == std::memcmp(sbv[0].iov_base, "1234567890", 10));
|
||||
assertTrue (0 == std::memcmp(sbv[1].iov_base, "abcdefghij", 10));
|
||||
assertTrue (0 == std::memcmp(sbv[2].iov_base, "helloworld", 10));
|
||||
|
||||
Socket::destroyBufVec(sbv);
|
||||
|
||||
ss.close();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void DatagramSocketTest::testGatherScatterVariable()
|
||||
{
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||
testGatherScatterVariableWin();
|
||||
testGatherScatterSTRFVariableWin();
|
||||
#elif defined(POCO_OS_FAMILY_UNIX)
|
||||
testGatherScatterVariableUNIX();
|
||||
testGatherScatterSTRFVariableUNIX();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void DatagramSocketTest::testGatherScatterVariableWin()
|
||||
{
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||
UDPEchoServer echoServer(SocketAddress("127.0.0.1", 0));
|
||||
DatagramSocket ss;
|
||||
std::vector<std::string> strOut(3);
|
||||
strOut[0] = "123";
|
||||
strOut[1] = "abcdef";
|
||||
strOut[2] = "helloworld";
|
||||
Socket::BufVec sbvOut = Socket::makeBufVec(strOut);
|
||||
assertTrue (sbvOut.size() == 3);
|
||||
assertTrue (sbvOut[0].len == 3);
|
||||
assertTrue (sbvOut[1].len == 6);
|
||||
assertTrue (sbvOut[2].len == 10);
|
||||
assertTrue (0 == std::memcmp(sbvOut[0].buf, "123", 3));
|
||||
assertTrue (0 == std::memcmp(sbvOut[1].buf, "abcdef", 6));
|
||||
assertTrue (0 == std::memcmp(sbvOut[2].buf, "helloworld", 10));
|
||||
|
||||
ss.connect(SocketAddress("127.0.0.1", echoServer.port()));
|
||||
int n = ss.sendTo(sbvOut, SocketAddress("127.0.0.1", echoServer.port()));
|
||||
assertTrue (n == 19);
|
||||
|
||||
std::vector<char*> strIn(3);
|
||||
strIn[0] = (char*) calloc(4, 1);
|
||||
strIn[1] = (char*) calloc(7, 1);
|
||||
strIn[2] = (char*) calloc(11, 1);
|
||||
std::memcpy(strIn[0], "321", 3);
|
||||
std::memcpy(strIn[1], "fedcba", 6);
|
||||
std::memcpy(strIn[2], "dlrowolleh", 10);
|
||||
Socket::BufVec sbvIn = Socket::makeBufVec(strIn);
|
||||
assertTrue (sbvIn.size() == 3);
|
||||
assertTrue (sbvIn[0].len == 3);
|
||||
assertTrue (sbvIn[1].len == 6);
|
||||
assertTrue (sbvIn[2].len == 10);
|
||||
assertTrue (0 == std::memcmp(sbvIn[0].buf, "321", 3));
|
||||
assertTrue (0 == std::memcmp(sbvIn[1].buf, "fedcba", 6));
|
||||
assertTrue (0 == std::memcmp(sbvIn[2].buf, "dlrowolleh", 10));
|
||||
|
||||
SocketAddress sa;
|
||||
n = ss.receiveFrom(sbvIn, sa);
|
||||
assertTrue (sa.host() == echoServer.address().host());
|
||||
assertTrue (sa.port() == echoServer.port());
|
||||
assertTrue (n == 19);
|
||||
|
||||
assertTrue (0 == std::memcmp(sbvIn[0].buf, "123", 3));
|
||||
assertTrue (0 == std::memcmp(sbvIn[1].buf, "abcdef", 6));
|
||||
assertTrue (0 == std::memcmp(sbvIn[2].buf, "helloworld", 10));
|
||||
|
||||
n = ss.sendBytes(sbvOut);
|
||||
assertTrue (n == 19);
|
||||
|
||||
std::reverse(sbvIn.begin(), sbvIn.end());
|
||||
n = ss.receiveBytes(sbvIn);
|
||||
assertTrue (n == 19);
|
||||
|
||||
assertTrue (0 == std::memcmp(sbvIn[0].buf, "123abcdefh", 10));
|
||||
assertTrue (0 == std::memcmp(sbvIn[1].buf, "ellowo", 6));
|
||||
assertTrue (0 == std::memcmp(sbvIn[2].buf, "rld", 3));
|
||||
|
||||
free(strIn[0]);
|
||||
free(strIn[1]);
|
||||
free(strIn[2]);
|
||||
|
||||
ss.close();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void DatagramSocketTest::testGatherScatterSTRFVariableWin()
|
||||
{
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||
UDPEchoServer echoServer;
|
||||
DatagramSocket ss;
|
||||
std::vector<std::string> strOut(3);
|
||||
strOut[0] = "123";
|
||||
strOut[1] = "abcdef";
|
||||
strOut[2] = "helloworld";
|
||||
Socket::BufVec sbvOut = Socket::makeBufVec(strOut);
|
||||
assertTrue (sbvOut.size() == 3);
|
||||
assertTrue (sbvOut[0].len == 3);
|
||||
assertTrue (sbvOut[1].len == 6);
|
||||
assertTrue (sbvOut[2].len == 10);
|
||||
assertTrue (0 == std::memcmp(sbvOut[0].buf, "123", 3));
|
||||
assertTrue (0 == std::memcmp(sbvOut[1].buf, "abcdef", 6));
|
||||
assertTrue (0 == std::memcmp(sbvOut[2].buf, "helloworld", 10));
|
||||
|
||||
ss.connect(SocketAddress("127.0.0.1", echoServer.port()));
|
||||
int n = ss.sendBytes(sbvOut);
|
||||
assertTrue (n == 19);
|
||||
|
||||
std::vector<char*> strIn(3);
|
||||
strIn[0] = new char[4];
|
||||
strIn[1] = new char[7];
|
||||
strIn[2] = new char[11];
|
||||
std::memcpy(strIn[0], "321", 3); strIn[0][3] = '\0';
|
||||
std::memcpy(strIn[1], "fedcba", 6); strIn[1][6] = '\0';
|
||||
std::memcpy(strIn[2], "dlrowolleh", 10); strIn[2][10] = '\0';
|
||||
Socket::BufVec sbvIn = Socket::makeBufVec(strIn);
|
||||
assertTrue (sbvIn.size() == 3);
|
||||
assertTrue (sbvIn[0].len == 3);
|
||||
assertTrue (sbvIn[1].len == 6);
|
||||
assertTrue (sbvIn[2].len == 10);
|
||||
assertTrue (0 == std::memcmp(sbvIn[0].buf, "321", 3));
|
||||
assertTrue (0 == std::memcmp(sbvIn[1].buf, "fedcba", 6));
|
||||
assertTrue (0 == std::memcmp(sbvIn[2].buf, "dlrowolleh", 10));
|
||||
|
||||
n = ss.receiveBytes(sbvIn);
|
||||
assertTrue (n == 19);
|
||||
|
||||
assertTrue (0 == std::memcmp(sbvIn[0].buf, "123", 3));
|
||||
assertTrue (0 == std::memcmp(sbvIn[1].buf, "abcdef", 6));
|
||||
assertTrue (0 == std::memcmp(sbvIn[2].buf, "helloworld", 10));
|
||||
|
||||
n = ss.sendBytes(sbvOut);
|
||||
assertTrue (n == 19);
|
||||
|
||||
std::reverse(sbvIn.begin(), sbvIn.end());
|
||||
n = ss.receiveBytes(sbvIn);
|
||||
assertTrue (n == 19);
|
||||
|
||||
assertTrue (0 == std::memcmp(sbvIn[0].buf, "123abcdefh", 10));
|
||||
assertTrue (0 == std::memcmp(sbvIn[1].buf, "ellowo", 6));
|
||||
assertTrue (0 == std::memcmp(sbvIn[2].buf, "rld", 3));
|
||||
|
||||
delete [] strIn[0];
|
||||
delete [] strIn[1];
|
||||
delete [] strIn[2];
|
||||
|
||||
ss.close();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void DatagramSocketTest::testGatherScatterSTRFVariableUNIX()
|
||||
{
|
||||
#if defined(POCO_OS_FAMILY_UNIX)
|
||||
UDPEchoServer echoServer;
|
||||
DatagramSocket ss;
|
||||
std::vector<std::string> strOut(3);
|
||||
strOut[0] = "123";
|
||||
strOut[1] = "abcdef";
|
||||
strOut[2] = "helloworld";
|
||||
Socket::BufVec sbvOut = Socket::makeBufVec(strOut);
|
||||
assertTrue (sbvOut.size() == 3);
|
||||
assertTrue (sbvOut[0].iov_len == 3);
|
||||
assertTrue (sbvOut[1].iov_len == 6);
|
||||
assertTrue (sbvOut[2].iov_len == 10);
|
||||
assertTrue (0 == std::memcmp(sbvOut[0].iov_base, "123", 3));
|
||||
assertTrue (0 == std::memcmp(sbvOut[1].iov_base, "abcdef", 6));
|
||||
assertTrue (0 == std::memcmp(sbvOut[2].iov_base, "helloworld", 10));
|
||||
|
||||
ss.connect(SocketAddress("127.0.0.1", echoServer.port()));
|
||||
int n = ss.sendBytes(sbvOut);
|
||||
assertTrue (n == 19);
|
||||
|
||||
std::vector<char*> strIn(3);
|
||||
strIn[0] = new char[4];
|
||||
strIn[1] = new char[7];
|
||||
strIn[2] = new char[11];
|
||||
std::memcpy(strIn[0], "321", 3); strIn[0][3] = '\0';
|
||||
std::memcpy(strIn[1], "fedcba", 6); strIn[1][6] = '\0';
|
||||
std::memcpy(strIn[2], "dlrowolleh", 10); strIn[2][10] = '\0';
|
||||
Socket::BufVec sbvIn = Socket::makeBufVec(strIn);
|
||||
assertTrue (sbvIn.size() == 3);
|
||||
assertTrue (sbvIn[0].iov_len == 3);
|
||||
assertTrue (sbvIn[1].iov_len == 6);
|
||||
assertTrue (sbvIn[2].iov_len == 10);
|
||||
assertTrue (0 == std::memcmp(sbvIn[0].iov_base, "321", 3));
|
||||
assertTrue (0 == std::memcmp(sbvIn[1].iov_base, "fedcba", 6));
|
||||
assertTrue (0 == std::memcmp(sbvIn[2].iov_base, "dlrowolleh", 10));
|
||||
|
||||
n = ss.receiveBytes(sbvIn);
|
||||
assertTrue (n == 19);
|
||||
|
||||
assertTrue (0 == std::memcmp(sbvIn[0].iov_base, "123", 3));
|
||||
assertTrue (0 == std::memcmp(sbvIn[1].iov_base, "abcdef", 6));
|
||||
assertTrue (0 == std::memcmp(sbvIn[2].iov_base, "helloworld", 10));
|
||||
|
||||
n = ss.sendBytes(sbvOut);
|
||||
assertTrue (n == 19);
|
||||
|
||||
std::reverse(sbvIn.begin(), sbvIn.end());
|
||||
n = ss.receiveBytes(sbvIn);
|
||||
assertTrue (n == 19);
|
||||
|
||||
assertTrue (0 == std::memcmp(sbvIn[0].iov_base, "123abcdefh", 10));
|
||||
assertTrue (0 == std::memcmp(sbvIn[1].iov_base, "ellowo", 6));
|
||||
assertTrue (0 == std::memcmp(sbvIn[2].iov_base, "rld", 3));
|
||||
|
||||
delete [] strIn[0];
|
||||
delete [] strIn[1];
|
||||
delete [] strIn[2];
|
||||
|
||||
ss.close();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void DatagramSocketTest::testGatherScatterVariableUNIX()
|
||||
{
|
||||
#if defined(POCO_OS_FAMILY_UNIX)
|
||||
UDPEchoServer echoServer;
|
||||
DatagramSocket ss;
|
||||
std::vector<std::string> strOut(3);
|
||||
strOut[0] = "123";
|
||||
strOut[1] = "abcdef";
|
||||
strOut[2] = "helloworld";
|
||||
Socket::BufVec sbvOut = Socket::makeBufVec(strOut);
|
||||
assertTrue (sbvOut.size() == 3);
|
||||
assertTrue (sbvOut[0].iov_len == 3);
|
||||
assertTrue (sbvOut[1].iov_len == 6);
|
||||
assertTrue (sbvOut[2].iov_len == 10);
|
||||
assertTrue (0 == std::memcmp(sbvOut[0].iov_base, "123", 3));
|
||||
assertTrue (0 == std::memcmp(sbvOut[1].iov_base, "abcdef", 6));
|
||||
assertTrue (0 == std::memcmp(sbvOut[2].iov_base, "helloworld", 10));
|
||||
|
||||
ss.connect(SocketAddress("127.0.0.1", echoServer.port()));
|
||||
int n = ss.sendBytes(sbvOut);
|
||||
assertTrue (n == 19);
|
||||
|
||||
std::vector<char*> strIn(3);
|
||||
strIn[0] = new char[4];
|
||||
strIn[1] = new char[7];
|
||||
strIn[2] = new char[11];
|
||||
std::memcpy(strIn[0], "321", 3); strIn[0][3] = '\0';
|
||||
std::memcpy(strIn[1], "fedcba", 6); strIn[1][6] = '\0';
|
||||
std::memcpy(strIn[2], "dlrowolleh", 10); strIn[2][10] = '\0';
|
||||
Socket::BufVec sbvIn = Socket::makeBufVec(strIn);
|
||||
assertTrue (sbvIn.size() == 3);
|
||||
assertTrue (sbvIn[0].iov_len == 3);
|
||||
assertTrue (sbvIn[1].iov_len == 6);
|
||||
assertTrue (sbvIn[2].iov_len == 10);
|
||||
assertTrue (0 == std::memcmp(sbvIn[0].iov_base, "321", 3));
|
||||
assertTrue (0 == std::memcmp(sbvIn[1].iov_base, "fedcba", 6));
|
||||
assertTrue (0 == std::memcmp(sbvIn[2].iov_base, "dlrowolleh", 10));
|
||||
|
||||
n = ss.receiveBytes(sbvIn);
|
||||
assertTrue (n == 19);
|
||||
|
||||
assertTrue (0 == std::memcmp(sbvIn[0].iov_base, "123", 3));
|
||||
assertTrue (0 == std::memcmp(sbvIn[1].iov_base, "abcdef", 6));
|
||||
assertTrue (0 == std::memcmp(sbvIn[2].iov_base, "helloworld", 10));
|
||||
|
||||
delete [] strIn[0];
|
||||
delete [] strIn[1];
|
||||
delete [] strIn[2];
|
||||
|
||||
ss.close();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void DatagramSocketTest::setUp()
|
||||
{
|
||||
}
|
||||
@@ -148,11 +607,14 @@ CppUnit::Test* DatagramSocketTest::suite()
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("DatagramSocketTest");
|
||||
|
||||
CppUnit_addTest(pSuite, DatagramSocketTest, testEcho);
|
||||
CppUnit_addTest(pSuite, DatagramSocketTest, testEchoBuffer);
|
||||
CppUnit_addTest(pSuite, DatagramSocketTest, testSendToReceiveFrom);
|
||||
CppUnit_addTest(pSuite, DatagramSocketTest, testUnbound);
|
||||
#if (POCO_OS != POCO_OS_FREE_BSD) // works only with local net bcast and very randomly
|
||||
CppUnit_addTest(pSuite, DatagramSocketTest, testBroadcast);
|
||||
#endif
|
||||
CppUnit_addTest(pSuite, DatagramSocketTest, testGatherScatterFixed);
|
||||
CppUnit_addTest(pSuite, DatagramSocketTest, testGatherScatterVariable);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
||||
@@ -25,9 +25,12 @@ public:
|
||||
~DatagramSocketTest();
|
||||
|
||||
void testEcho();
|
||||
void testEchoBuffer();
|
||||
void testSendToReceiveFrom();
|
||||
void testUnbound();
|
||||
void testBroadcast();
|
||||
void testGatherScatterFixed();
|
||||
void testGatherScatterVariable();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
@@ -35,6 +38,16 @@ public:
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
// "STRF" are sendto/recvfrom versions of the same functionality
|
||||
void testGatherScatterFixedWin();
|
||||
void testGatherScatterSTRFFixedWin();
|
||||
void testGatherScatterVariableWin();
|
||||
void testGatherScatterSTRFVariableWin();
|
||||
|
||||
void testGatherScatterFixedUNIX();
|
||||
void testGatherScatterSTRFFixedUNIX();
|
||||
void testGatherScatterVariableUNIX();
|
||||
void testGatherScatterSTRFVariableUNIX();
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -196,8 +196,8 @@ void HTTPResponseTest::testCookies()
|
||||
cookies.clear();
|
||||
response2.getCookies(cookies);
|
||||
assertTrue (cookies.size() == 2);
|
||||
assertTrue (cookies[0].getName() == "name1" && cookies[1].getName() == "name2"
|
||||
|| cookies[0].getName() == "name2" && cookies[1].getName() == "name1");
|
||||
assertTrue (((cookies[0].getName() == "name1") && (cookies[1].getName() == "name2"))
|
||||
|| ((cookies[0].getName() == "name2") && (cookies[1].getName() == "name1")));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -32,6 +32,9 @@ using Poco::Delegate;
|
||||
using Poco::AutoPtr;
|
||||
|
||||
|
||||
Poco::FastMutex ICMPClientTest::_mutex;
|
||||
|
||||
|
||||
ICMPClientTest::ICMPClientTest(const std::string& name):
|
||||
CppUnit::TestCase(name)
|
||||
{
|
||||
@@ -65,6 +68,8 @@ void ICMPClientTest::testPing()
|
||||
#endif
|
||||
|
||||
unregisterDelegates(icmpClient);
|
||||
// wait for delegates to finish printing
|
||||
Poco::FastMutex::ScopedLock l(_mutex);
|
||||
}
|
||||
|
||||
|
||||
@@ -90,6 +95,8 @@ void ICMPClientTest::testBigPing()
|
||||
#endif
|
||||
|
||||
unregisterDelegates(icmpClient);
|
||||
// wait for delegates to finish printing
|
||||
Poco::FastMutex::ScopedLock l(_mutex);
|
||||
}
|
||||
|
||||
|
||||
@@ -123,6 +130,7 @@ void ICMPClientTest::tearDown()
|
||||
|
||||
void ICMPClientTest::onBegin(const void* pSender, ICMPEventArgs& args)
|
||||
{
|
||||
Poco::FastMutex::ScopedLock l(_mutex);
|
||||
std::ostringstream os;
|
||||
os << std::endl << "Pinging " << args.hostName() << " [" << args.hostAddress() << "] with "
|
||||
<< args.dataSize() << " bytes of data:"
|
||||
@@ -133,6 +141,7 @@ void ICMPClientTest::onBegin(const void* pSender, ICMPEventArgs& args)
|
||||
|
||||
void ICMPClientTest::onReply(const void* pSender, ICMPEventArgs& args)
|
||||
{
|
||||
Poco::FastMutex::ScopedLock l(_mutex);
|
||||
std::ostringstream os;
|
||||
os << "Reply from " << args.hostAddress()
|
||||
<< " bytes=" << args.dataSize()
|
||||
@@ -144,6 +153,7 @@ void ICMPClientTest::onReply(const void* pSender, ICMPEventArgs& args)
|
||||
|
||||
void ICMPClientTest::onError(const void* pSender, ICMPEventArgs& args)
|
||||
{
|
||||
Poco::FastMutex::ScopedLock l(_mutex);
|
||||
std::ostringstream os;
|
||||
os << args.error();
|
||||
std::cerr << os.str() << std::endl;
|
||||
@@ -152,6 +162,7 @@ void ICMPClientTest::onError(const void* pSender, ICMPEventArgs& args)
|
||||
|
||||
void ICMPClientTest::onEnd(const void* pSender, ICMPEventArgs& args)
|
||||
{
|
||||
Poco::FastMutex::ScopedLock l(_mutex);
|
||||
std::ostringstream os;
|
||||
int received = args.received();
|
||||
os << std::endl << "--- Ping statistics for " << args.hostAddress() << " ---"
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "CppUnit/TestCase.h"
|
||||
#include "Poco/Net/ICMPClient.h"
|
||||
#include "Poco/Net/ICMPEventArgs.h"
|
||||
#include "Poco/Mutex.h"
|
||||
|
||||
|
||||
class ICMPClientTest: public CppUnit::TestCase
|
||||
@@ -42,6 +43,7 @@ public:
|
||||
private:
|
||||
void registerDelegates(const Poco::Net::ICMPClient& icmpClient);
|
||||
void unregisterDelegates(const Poco::Net::ICMPClient& icmpClient);
|
||||
static Poco::FastMutex _mutex;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
#include "ICMPClientTestSuite.h"
|
||||
#include "ICMPClientTest.h"
|
||||
#include "ICMPSocketTest.h"
|
||||
|
||||
|
||||
CppUnit::Test* ICMPClientTestSuite::suite()
|
||||
@@ -17,6 +18,7 @@ CppUnit::Test* ICMPClientTestSuite::suite()
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ICMPClientTestSuite");
|
||||
|
||||
pSuite->addTest(ICMPClientTest::suite());
|
||||
pSuite->addTest(ICMPSocketTest::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
||||
@@ -13,20 +13,27 @@
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "UDPEchoServer.h"
|
||||
#include "Poco/Net/ICMPSocket.h"
|
||||
#include "Poco/Net/ICMPPacketImpl.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include "Poco/Timespan.h"
|
||||
#include "Poco/Stopwatch.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using Poco::Net::Socket;
|
||||
using Poco::Net::ICMPSocket;
|
||||
using Poco::Net::ICMPPacketImpl;
|
||||
using Poco::Net::SocketAddress;
|
||||
using Poco::Net::IPAddress;
|
||||
using Poco::Net::ICMPException;
|
||||
using Poco::Timespan;
|
||||
using Poco::Stopwatch;
|
||||
using Poco::TimeoutException;
|
||||
using Poco::Net::NetException;
|
||||
using Poco::Net::ICMPException;
|
||||
using Poco::Exception;
|
||||
using Poco::TimeoutException;
|
||||
|
||||
|
||||
ICMPSocketTest::ICMPSocketTest(const std::string& name): CppUnit::TestCase(name)
|
||||
@@ -57,12 +64,9 @@ void ICMPSocketTest::testSendToReceiveFrom()
|
||||
ss.receiveFrom(sa);
|
||||
fail("must throw");
|
||||
}
|
||||
catch(ICMPException&)
|
||||
{
|
||||
}
|
||||
catch(TimeoutException&)
|
||||
{
|
||||
}
|
||||
catch (ICMPException&) { }
|
||||
catch (TimeoutException&) { }
|
||||
catch (Exception&) { }
|
||||
|
||||
ss.sendTo(sa);
|
||||
ss.receiveFrom(sa);
|
||||
@@ -72,6 +76,32 @@ void ICMPSocketTest::testSendToReceiveFrom()
|
||||
}
|
||||
|
||||
|
||||
void ICMPSocketTest::testMTU()
|
||||
{
|
||||
try
|
||||
{
|
||||
Poco::UInt16 sz = ICMPPacketImpl::MAX_PAYLOAD_SIZE + 1;
|
||||
SocketAddress addr("127.0.0.1:0");
|
||||
Poco::UInt16 mtu = ICMPSocket::mtu(addr, sz);
|
||||
std::cout << addr.toString() << " : MTU=" << mtu << std::endl;
|
||||
assertTrue (mtu != 0 && mtu <= ICMPPacketImpl::MAX_PAYLOAD_SIZE);
|
||||
sz = ICMPPacketImpl::MAX_PAYLOAD_SIZE;
|
||||
mtu = ICMPSocket::mtu(addr, sz);
|
||||
std::cout << addr.toString() << " : MTU=" << mtu << std::endl;
|
||||
assertTrue (mtu != 0);
|
||||
sz = 1500;
|
||||
addr = SocketAddress("www.appinf.com:0");
|
||||
mtu = ICMPSocket::mtu(addr, sz);
|
||||
std::cout << addr.toString() << " : MTU=" << mtu << std::endl;
|
||||
assertTrue (mtu != 0 && mtu <= sz);
|
||||
}
|
||||
catch (Poco::NotImplementedException& ex)
|
||||
{
|
||||
std::cerr << ex.displayText() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ICMPSocketTest::setUp()
|
||||
{
|
||||
}
|
||||
@@ -88,6 +118,7 @@ CppUnit::Test* ICMPSocketTest::suite()
|
||||
|
||||
CppUnit_addTest(pSuite, ICMPSocketTest, testSendToReceiveFrom);
|
||||
CppUnit_addTest(pSuite, ICMPSocketTest, testAssign);
|
||||
CppUnit_addTest(pSuite, ICMPSocketTest, testMTU);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ public:
|
||||
|
||||
void testSendToReceiveFrom();
|
||||
void testAssign();
|
||||
void testMTU();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "HTTPTestSuite.h"
|
||||
#include "HTTPClientTestSuite.h"
|
||||
#include "TCPServerTestSuite.h"
|
||||
#include "UDPServerTestSuite.h"
|
||||
#include "HTTPServerTestSuite.h"
|
||||
#include "HTMLTestSuite.h"
|
||||
#include "ReactorTestSuite.h"
|
||||
@@ -37,6 +38,7 @@ CppUnit::Test* NetTestSuite::suite()
|
||||
pSuite->addTest(HTTPTestSuite::suite());
|
||||
pSuite->addTest(HTTPClientTestSuite::suite());
|
||||
pSuite->addTest(TCPServerTestSuite::suite());
|
||||
pSuite->addTest(UDPServerTestSuite::suite());
|
||||
pSuite->addTest(HTTPServerTestSuite::suite());
|
||||
pSuite->addTest(HTMLTestSuite::suite());
|
||||
pSuite->addTest(ReactorTestSuite::suite());
|
||||
|
||||
@@ -52,13 +52,10 @@ namespace
|
||||
_reactor(reactor)
|
||||
{
|
||||
_reactor.addEventHandler(_socket, Observer<EchoServiceHandler, ReadableNotification>(*this, &EchoServiceHandler::onReadable));
|
||||
_reactor.addEventHandler(_socket, Observer<EchoServiceHandler, ShutdownNotification>(*this, &EchoServiceHandler::onShutdown));
|
||||
}
|
||||
|
||||
~EchoServiceHandler()
|
||||
{
|
||||
_reactor.removeEventHandler(_socket, Observer<EchoServiceHandler, ReadableNotification>(*this, &EchoServiceHandler::onReadable));
|
||||
_reactor.removeEventHandler(_socket, Observer<EchoServiceHandler, ShutdownNotification>(*this, &EchoServiceHandler::onShutdown));
|
||||
}
|
||||
|
||||
void onReadable(ReadableNotification* pNf)
|
||||
@@ -70,13 +67,11 @@ namespace
|
||||
{
|
||||
_socket.sendBytes(buffer, n);
|
||||
}
|
||||
else delete this;
|
||||
}
|
||||
|
||||
void onShutdown(ShutdownNotification* pNf)
|
||||
{
|
||||
pNf->release();
|
||||
delete this;
|
||||
else
|
||||
{
|
||||
_reactor.removeEventHandler(_socket, Observer<EchoServiceHandler, ReadableNotification>(*this, &EchoServiceHandler::onReadable));
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -129,8 +124,11 @@ namespace
|
||||
checkReadableObserverCount(1);
|
||||
_reactor.removeEventHandler(_socket, Observer<ClientServiceHandler, ReadableNotification>(*this, &ClientServiceHandler::onReadable));
|
||||
checkReadableObserverCount(0);
|
||||
if (_once || _data.size() == 8192) _reactor.stop();
|
||||
delete this;
|
||||
if (_once || _data.size() == 8192)
|
||||
{
|
||||
_reactor.stop();
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -434,7 +432,6 @@ void SocketReactorTest::testParallelSocketReactor()
|
||||
ClientServiceHandler::setOnce(false);
|
||||
ClientServiceHandler::resetData();
|
||||
reactor.run();
|
||||
//acceptor.run();
|
||||
std::string data(ClientServiceHandler::data());
|
||||
assertTrue (data.size() == 8192);
|
||||
assertTrue (!ClientServiceHandler::readableError());
|
||||
|
||||
199
Net/testsuite/src/UDPServerTest.cpp
Normal file
199
Net/testsuite/src/UDPServerTest.cpp
Normal file
@@ -0,0 +1,199 @@
|
||||
//
|
||||
// UDPServerTest.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "UDPServerTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Net/UDPServer.h"
|
||||
#include "Poco/Net/UDPClient.h"
|
||||
#include "Poco/Net/UDPHandler.h"
|
||||
#include "Poco/Net/DatagramSocket.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include "Poco/Net/NetworkInterface.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include "Poco/Timespan.h"
|
||||
#include "Poco/AtomicCounter.h"
|
||||
#include "Poco/StringTokenizer.h"
|
||||
#include <cstring>
|
||||
|
||||
|
||||
using Poco::Net::DatagramSocket;
|
||||
using Poco::Net::UDPServer;
|
||||
using Poco::Net::UDPClient;
|
||||
using Poco::Net::UDPMultiServer;
|
||||
using Poco::Net::UDPHandler;
|
||||
using Poco::Net::Socket;
|
||||
using Poco::Net::SocketBufVec;
|
||||
using Poco::Net::SocketAddress;
|
||||
using Poco::Timespan;
|
||||
using Poco::Thread;
|
||||
using Poco::TimeoutException;
|
||||
using Poco::InvalidArgumentException;
|
||||
using Poco::AtomicCounter;
|
||||
using Poco::StringTokenizer;
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
struct TestUDPHandler : public Poco::Net::UDPHandler
|
||||
{
|
||||
TestUDPHandler() : counter(0), errCounter(0) {}
|
||||
|
||||
void processData(char *buf)
|
||||
{
|
||||
if (!addr.empty() && addr != address(buf).toString()) ++errors;
|
||||
addr = address(buf).toString();
|
||||
counter = counter.value() + static_cast<AtomicCounter::ValueType>(payload(buf, '\n').count());
|
||||
if (counter % 10)
|
||||
{
|
||||
if (payload(buf, '\n').count() == 0) ++errors;
|
||||
std::memset(buf, 0, blockSize());
|
||||
}
|
||||
else // fake error
|
||||
{
|
||||
errCounter = errCounter.value() + static_cast<AtomicCounter::ValueType>(payload(buf, '\n').count());
|
||||
setError(buf, "error");
|
||||
processError(buf);
|
||||
}
|
||||
}
|
||||
|
||||
void processError(char *buf)
|
||||
{
|
||||
if (std::string(error(buf)) != "error") ++errors;
|
||||
std::memset(buf, 0, blockSize());
|
||||
}
|
||||
|
||||
AtomicCounter counter;
|
||||
AtomicCounter errCounter;
|
||||
static AtomicCounter errors;
|
||||
std::string addr;
|
||||
};
|
||||
|
||||
AtomicCounter TestUDPHandler::errors;
|
||||
|
||||
template<typename S>
|
||||
bool server(int handlerCount, int reps, int port = 0)
|
||||
{
|
||||
Poco::Net::UDPHandler::List handlers;
|
||||
for (int i = 0; i < handlerCount; ++i)
|
||||
handlers.push_back(new TestUDPHandler());
|
||||
|
||||
S server(handlers, Poco::Net::SocketAddress("127.0.0.1", port));
|
||||
Poco::Thread::sleep(100);
|
||||
|
||||
Poco::Net::UDPClient client("127.0.0.1", server.port(), true);
|
||||
Poco::Thread::sleep(10);
|
||||
|
||||
std::vector<std::string> data;
|
||||
int i = 0;
|
||||
const char *str = "hello\n";
|
||||
for (; i < reps; ++i)
|
||||
{
|
||||
data.push_back(str);
|
||||
if (data.size() == 230 || i == reps - 1)
|
||||
{
|
||||
data.back().append(1, '\0');
|
||||
std::size_t sz = (data.size() * strlen(str)) + 1;
|
||||
int sent = client.send(Poco::Net::Socket::makeBufVec(data));
|
||||
if (sz != sent)
|
||||
{
|
||||
std::cerr << "Send count mismatch, expected: " << sz
|
||||
<< ", sent: " << sent << std::endl;
|
||||
return false;
|
||||
}
|
||||
Poco::Thread::sleep(10);
|
||||
data.clear();
|
||||
}
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
int errCount = 0;
|
||||
do
|
||||
{
|
||||
count = 0;
|
||||
errCount = 0;
|
||||
Poco::Thread::sleep(10);
|
||||
Poco::Net::UDPHandler::Iterator it = handlers.begin();
|
||||
Poco::Net::UDPHandler::Iterator end = handlers.end();
|
||||
for (; it != end; ++it)
|
||||
{
|
||||
count += dynamic_cast<TestUDPHandler &>(*(*it)).counter.value();
|
||||
errCount += count / 10;
|
||||
}
|
||||
} while (count < i);
|
||||
if (reps != count)
|
||||
{
|
||||
std::cerr << "Response mismatch, expected: " << reps
|
||||
<< ", received: " << count << std::endl;
|
||||
return false;
|
||||
}
|
||||
Poco::Net::UDPHandler::Iterator it = handlers.begin();
|
||||
Poco::Net::UDPHandler::Iterator end = handlers.end();
|
||||
for (; it != end; ++it)
|
||||
{
|
||||
TestUDPHandler &h = dynamic_cast<TestUDPHandler &>(*(*it));
|
||||
count = h.counter.value();
|
||||
errCount = h.errCounter.value();
|
||||
if (errCount < count / 10)
|
||||
{
|
||||
std::cerr << "Error count mismatch, expected: <" << count / 10
|
||||
<< ", received: " << errCount << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (h.counter && (h.addr.empty() || h.addr != client.address().toString()))
|
||||
{
|
||||
std::cerr << "Address mismatch, expected: " << client.address().toString()
|
||||
<< ", received: " << h.addr << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
UDPServerTest::UDPServerTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
UDPServerTest::~UDPServerTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void UDPServerTest::testServer()
|
||||
{
|
||||
int msgs = 10000;
|
||||
assertTrue (server<Poco::Net::UDPServer>(1, msgs));
|
||||
assertTrue (server<Poco::Net::UDPMultiServer>(10, msgs, 22080));
|
||||
assertTrue (TestUDPHandler::errors == 0);
|
||||
}
|
||||
|
||||
|
||||
void UDPServerTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void UDPServerTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* UDPServerTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("UDPServerTest");
|
||||
|
||||
CppUnit_addTest(pSuite, UDPServerTest, testServer);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
38
Net/testsuite/src/UDPServerTest.h
Normal file
38
Net/testsuite/src/UDPServerTest.h
Normal file
@@ -0,0 +1,38 @@
|
||||
//
|
||||
// UDPServerTest.h
|
||||
//
|
||||
// Definition of the UDPServerTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef UDPServerTest_INCLUDED
|
||||
#define UDPServerTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
#include "Poco/Thread.h"
|
||||
|
||||
class UDPServerTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
UDPServerTest(const std::string& name);
|
||||
~UDPServerTest();
|
||||
|
||||
void testServer();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // UDPServerTest_INCLUDED
|
||||
22
Net/testsuite/src/UDPServerTestSuite.cpp
Normal file
22
Net/testsuite/src/UDPServerTestSuite.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// UDPServerTestSuite.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "UDPServerTestSuite.h"
|
||||
#include "UDPServerTest.h"
|
||||
|
||||
|
||||
CppUnit::Test* UDPServerTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("UDPServerTestSuite");
|
||||
|
||||
pSuite->addTest(UDPServerTest::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
27
Net/testsuite/src/UDPServerTestSuite.h
Normal file
27
Net/testsuite/src/UDPServerTestSuite.h
Normal file
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// UDPServerTestSuite.h
|
||||
//
|
||||
// Definition of the UDPServerTestSuite class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef UDPServerTestSuite_INCLUDED
|
||||
#define UDPServerTestSuite_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/TestSuite.h"
|
||||
|
||||
|
||||
class UDPServerTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // UDPServerTestSuite_INCLUDED
|
||||
@@ -247,7 +247,7 @@ void WebSocketTest::testOneLargeFrame(int msgSize)
|
||||
int flags;
|
||||
int n;
|
||||
|
||||
n = ws.receiveFrame(buffer.begin(), buffer.size(), flags);
|
||||
n = ws.receiveFrame(buffer.begin(), static_cast<int>(buffer.size()), flags);
|
||||
assertTrue (n == payload.size());
|
||||
assertTrue (payload.compare(0, payload.size(), buffer.begin(), n) == 0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user