This commit is contained in:
Aria 2025-03-21 22:23:30 +11:00
commit 9c94d113d3
Signed by untrusted user who does not match committer: aria
GPG key ID: 19AB7AA462B8AB3B
10260 changed files with 1237388 additions and 0 deletions

View file

@ -0,0 +1,45 @@
#include "StarNetSocket.hpp"
using namespace Star;
int main(int argc, char** argv) {
class TestSockThread : public Thread {
public:
TestSockThread(NetSocketPtr ns) : Thread("TestSockThread"), m_netSocket(ns) {}
virtual void run() {
int count = 0;
coutf("starting\n");
// Just to test timing out, wait on a packet never sent.
if (!m_netSocket->waitPacket<ClientConnectPacket>(1000))
coutf("timed out waiting for bogus packet (expected)\n");
while (count < 10) {
m_netSocket->sendPacket(make_shared<ClientConnectPacket>());
if (m_netSocket->waitPacket<ClientConnectPacket>(1000)) {
++count;
coutf("packet received\n");
} else {
coutf("timed out\n");
}
}
coutf("received all packets!\n");
}
private:
NetSocketPtr m_netSocket;
};
auto pair = NetSocket::memorySocketPair();
TestSockThread testThread1(pair.first);
TestSockThread testThread2(pair.second);
testThread1.start();
testThread2.start();
testThread1.join();
testThread2.join();
return 0;
}