mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-06-18 08:07:12 +02:00
Major plugin refactor and cleanup.
Switched to POCO library for unified platform/library interface. Deprecated the external module API. It was creating more problems than solving. Removed most built-in libraries in favor of system libraries for easier maintenance. Cleaned and secured code with help from static analyzers.
This commit is contained in:
82
vendor/POCO/Net/testsuite/src/EchoServer.cpp
vendored
Normal file
82
vendor/POCO/Net/testsuite/src/EchoServer.cpp
vendored
Normal file
@ -0,0 +1,82 @@
|
||||
//
|
||||
// EchoServer.cpp
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "EchoServer.h"
|
||||
#include "Poco/Net/StreamSocket.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include "Poco/Timespan.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using Poco::Net::Socket;
|
||||
using Poco::Net::StreamSocket;
|
||||
using Poco::Net::SocketAddress;
|
||||
|
||||
|
||||
EchoServer::EchoServer():
|
||||
_socket(SocketAddress()),
|
||||
_thread("EchoServer"),
|
||||
_stop(false)
|
||||
{
|
||||
_thread.start(*this);
|
||||
_ready.wait();
|
||||
}
|
||||
|
||||
|
||||
EchoServer::EchoServer(const Poco::Net::SocketAddress& address):
|
||||
_socket(address),
|
||||
_thread("EchoServer"),
|
||||
_stop(false)
|
||||
{
|
||||
_thread.start(*this);
|
||||
_ready.wait();
|
||||
}
|
||||
|
||||
|
||||
EchoServer::~EchoServer()
|
||||
{
|
||||
_stop = true;
|
||||
_thread.join();
|
||||
}
|
||||
|
||||
|
||||
Poco::UInt16 EchoServer::port() const
|
||||
{
|
||||
return _socket.address().port();
|
||||
}
|
||||
|
||||
|
||||
void EchoServer::run()
|
||||
{
|
||||
_ready.set();
|
||||
Poco::Timespan span(250000);
|
||||
while (!_stop)
|
||||
{
|
||||
if (_socket.poll(span, Socket::SELECT_READ))
|
||||
{
|
||||
StreamSocket ss = _socket.acceptConnection();
|
||||
try
|
||||
{
|
||||
char buffer[256];
|
||||
int n = ss.receiveBytes(buffer, sizeof(buffer));
|
||||
while (n > 0 && !_stop)
|
||||
{
|
||||
ss.sendBytes(buffer, n);
|
||||
n = ss.receiveBytes(buffer, sizeof(buffer));
|
||||
}
|
||||
}
|
||||
catch (Poco::Exception& exc)
|
||||
{
|
||||
std::cerr << "EchoServer: " << exc.displayText() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user