Add logger class, fix include orders
This commit is contained in:
parent
28b5a2457a
commit
f7831afc9d
|
@ -43,6 +43,7 @@ add_library(usenetsearch
|
||||||
"src/Filter.cpp"
|
"src/Filter.cpp"
|
||||||
"src/Indexer.cpp"
|
"src/Indexer.cpp"
|
||||||
"src/IoSocket.cpp"
|
"src/IoSocket.cpp"
|
||||||
|
"src/Logger.cpp"
|
||||||
"src/Serialize.cpp"
|
"src/Serialize.cpp"
|
||||||
"src/SSLConnection.cpp"
|
"src/SSLConnection.cpp"
|
||||||
"src/StringUtils.cpp"
|
"src/StringUtils.cpp"
|
||||||
|
|
|
@ -17,14 +17,14 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <filesystem>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "usenetsearch/Configuration.h"
|
#include "usenetsearch/Configuration.h"
|
||||||
#include "usenetsearch/Database.h"
|
#include "usenetsearch/Database.h"
|
||||||
#include "usenetsearch/Filter.h"
|
#include "usenetsearch/Filter.h"
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace usenetsearch {
|
namespace usenetsearch {
|
||||||
|
|
||||||
enum class CommandLineOptionType
|
enum class CommandLineOptionType
|
||||||
|
|
|
@ -17,12 +17,12 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "usenetsearch/Except.h"
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "usenetsearch/Except.h"
|
|
||||||
|
|
||||||
namespace usenetsearch {
|
namespace usenetsearch {
|
||||||
|
|
||||||
struct ConfigurationException: public UsenetSearchException
|
struct ConfigurationException: public UsenetSearchException
|
||||||
|
|
|
@ -17,6 +17,10 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "usenetsearch/Filter.h"
|
||||||
|
#include "usenetsearch/Serialize.h"
|
||||||
|
#include "usenetsearch/UsenetClient.h"
|
||||||
|
|
||||||
#include <codecvt>
|
#include <codecvt>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
@ -26,10 +30,6 @@
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "usenetsearch/Filter.h"
|
|
||||||
#include "usenetsearch/Serialize.h"
|
|
||||||
#include "usenetsearch/UsenetClient.h"
|
|
||||||
|
|
||||||
namespace usenetsearch {
|
namespace usenetsearch {
|
||||||
|
|
||||||
class Application;
|
class Application;
|
||||||
|
|
|
@ -17,13 +17,13 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <chrono>
|
#include "usenetsearch/Except.h"
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <netdb.h> // struct addrinfo
|
#include <netdb.h> // struct addrinfo
|
||||||
|
|
||||||
#include "usenetsearch/Except.h"
|
#include <chrono>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace usenetsearch {
|
namespace usenetsearch {
|
||||||
|
|
||||||
|
|
|
@ -17,14 +17,14 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "usenetsearch/Configuration.h"
|
||||||
|
|
||||||
#include <codecvt>
|
#include <codecvt>
|
||||||
#include <locale>
|
#include <locale>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
#include "usenetsearch/Configuration.h"
|
|
||||||
|
|
||||||
namespace usenetsearch {
|
namespace usenetsearch {
|
||||||
|
|
||||||
class Filter
|
class Filter
|
||||||
|
|
|
@ -17,16 +17,16 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <codecvt>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <locale>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "usenetsearch/Application.h"
|
#include "usenetsearch/Application.h"
|
||||||
#include "usenetsearch/Filter.h"
|
#include "usenetsearch/Filter.h"
|
||||||
#include "usenetsearch/UsenetClient.h"
|
#include "usenetsearch/UsenetClient.h"
|
||||||
#include "usenetsearch/ThreadPool.h"
|
#include "usenetsearch/ThreadPool.h"
|
||||||
|
|
||||||
|
#include <codecvt>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <locale>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace usenetsearch {
|
namespace usenetsearch {
|
||||||
|
|
||||||
class SearchResult
|
class SearchResult
|
||||||
|
|
|
@ -0,0 +1,90 @@
|
||||||
|
/*
|
||||||
|
Copyright© 2021 John Sennesael
|
||||||
|
|
||||||
|
UsenetSearch is Free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
UsenetSearch is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with UsenetSearch. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <memory>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
namespace usenetsearch {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple logging class singleton.
|
||||||
|
*/
|
||||||
|
class Logger
|
||||||
|
{
|
||||||
|
|
||||||
|
/// Holds a pointer to the singleton instance.
|
||||||
|
static std::unique_ptr<Logger> m_instance;
|
||||||
|
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*/
|
||||||
|
Logger();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destructor.
|
||||||
|
*/
|
||||||
|
virtual ~Logger() = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets an instance to the logger.
|
||||||
|
*/
|
||||||
|
static Logger& get();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logs a debug message.
|
||||||
|
*
|
||||||
|
* @param[in] msg Message to be logged.
|
||||||
|
*/
|
||||||
|
void debug(const std::string& msg) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logs an info message.
|
||||||
|
*
|
||||||
|
* @param[in] msg Message to be logged.
|
||||||
|
*/
|
||||||
|
void info(const std::string& msg) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logs an error message.
|
||||||
|
*
|
||||||
|
* @param[in] msg Message to be logged.
|
||||||
|
*/
|
||||||
|
void error(const std::string& msg) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logs an error message and throws.
|
||||||
|
*
|
||||||
|
* @tparam EXCEPTION Type of exception to throw.
|
||||||
|
* @param[in] msg Error message to be logged.
|
||||||
|
*/
|
||||||
|
template <typename EXCEPTION>
|
||||||
|
inline void fatal(const std::string& msg) const
|
||||||
|
{
|
||||||
|
static_assert(
|
||||||
|
std::is_base_of<std::exception, EXCEPTION>::value,
|
||||||
|
"EXCEPTION must be an std::exception or derrived child.");
|
||||||
|
error(msg);
|
||||||
|
throw EXCEPTION(msg);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace usenetsearch
|
|
@ -17,12 +17,12 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <memory>
|
#include "usenetsearch/IoSocket.h"
|
||||||
|
#include "usenetsearch/TcpConnection.h"
|
||||||
|
|
||||||
#include <openssl/ssl.h>
|
#include <openssl/ssl.h>
|
||||||
|
|
||||||
#include "usenetsearch/IoSocket.h"
|
#include <memory>
|
||||||
#include "usenetsearch/TcpConnection.h"
|
|
||||||
|
|
||||||
namespace usenetsearch {
|
namespace usenetsearch {
|
||||||
|
|
||||||
|
|
|
@ -17,13 +17,14 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "usenetsearch/Except.h"
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <locale>
|
#include <locale>
|
||||||
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "usenetsearch/Except.h"
|
|
||||||
|
|
||||||
namespace usenetsearch {
|
namespace usenetsearch {
|
||||||
|
|
||||||
struct ArticleEntry;
|
struct ArticleEntry;
|
||||||
|
|
|
@ -17,14 +17,14 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "usenetsearch/Except.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "usenetsearch/Except.h"
|
|
||||||
|
|
||||||
namespace usenetsearch {
|
namespace usenetsearch {
|
||||||
|
|
||||||
struct StringException: public UsenetSearchException
|
struct StringException: public UsenetSearchException
|
||||||
|
|
|
@ -17,12 +17,12 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <chrono>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "usenetsearch/Except.h"
|
#include "usenetsearch/Except.h"
|
||||||
#include "usenetsearch/IoSocket.h"
|
#include "usenetsearch/IoSocket.h"
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace usenetsearch {
|
namespace usenetsearch {
|
||||||
|
|
||||||
struct SocketException: public UsenetSearchException
|
struct SocketException: public UsenetSearchException
|
||||||
|
|
|
@ -17,6 +17,9 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "usenetsearch/SSLConnection.h"
|
||||||
|
#include "usenetsearch/TcpConnection.h"
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <codecvt>
|
#include <codecvt>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
@ -27,9 +30,6 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "usenetsearch/SSLConnection.h"
|
|
||||||
#include "usenetsearch/TcpConnection.h"
|
|
||||||
|
|
||||||
namespace usenetsearch {
|
namespace usenetsearch {
|
||||||
|
|
||||||
class Application;
|
class Application;
|
||||||
|
|
|
@ -15,15 +15,15 @@
|
||||||
along with UsenetSearch. If not, see <https://www.gnu.org/licenses/>.
|
along with UsenetSearch. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "usenetsearch/Application.h"
|
||||||
|
|
||||||
|
#include "usenetsearch/StringUtils.h"
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "usenetsearch/StringUtils.h"
|
|
||||||
|
|
||||||
#include "usenetsearch/Application.h"
|
|
||||||
|
|
||||||
namespace usenetsearch {
|
namespace usenetsearch {
|
||||||
|
|
||||||
void Application::AddBooleanOption(
|
void Application::AddBooleanOption(
|
||||||
|
|
|
@ -15,15 +15,15 @@
|
||||||
along with UsenetSearch. If not, see <https://www.gnu.org/licenses/>.
|
along with UsenetSearch. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <filesystem>
|
#include "usenetsearch/Configuration.h"
|
||||||
#include <fstream>
|
|
||||||
#include <regex>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "usenetsearch/ScopeExit.h"
|
#include "usenetsearch/ScopeExit.h"
|
||||||
#include "usenetsearch/StringUtils.h"
|
#include "usenetsearch/StringUtils.h"
|
||||||
|
|
||||||
#include "usenetsearch/Configuration.h"
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
|
#include <regex>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace usenetsearch {
|
namespace usenetsearch {
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,14 @@
|
||||||
along with UsenetSearch. If not, see <https://www.gnu.org/licenses/>.
|
along with UsenetSearch. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "usenetsearch/Database.h"
|
||||||
|
|
||||||
|
#include "usenetsearch/Application.h"
|
||||||
|
#include "usenetsearch/StringUtils.h"
|
||||||
|
#include "usenetsearch/UsenetClient.h"
|
||||||
|
#include "usenetsearch/ScopeExit.h"
|
||||||
|
#include "usenetsearch/Serialize.h"
|
||||||
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
@ -24,14 +32,6 @@
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "usenetsearch/Application.h"
|
|
||||||
#include "usenetsearch/StringUtils.h"
|
|
||||||
#include "usenetsearch/UsenetClient.h"
|
|
||||||
#include "usenetsearch/ScopeExit.h"
|
|
||||||
#include "usenetsearch/Serialize.h"
|
|
||||||
|
|
||||||
#include "usenetsearch/Database.h"
|
|
||||||
|
|
||||||
namespace usenetsearch {
|
namespace usenetsearch {
|
||||||
|
|
||||||
// Database class --------------------------------------------------------------
|
// Database class --------------------------------------------------------------
|
||||||
|
|
|
@ -15,11 +15,11 @@
|
||||||
along with UsenetSearch. If not, see <https://www.gnu.org/licenses/>.
|
along with UsenetSearch. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "usenetsearch/Dns.h"
|
||||||
|
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
#include "usenetsearch/Dns.h"
|
|
||||||
|
|
||||||
namespace usenetsearch {
|
namespace usenetsearch {
|
||||||
|
|
||||||
std::vector<struct addrinfo> DnsResolve(
|
std::vector<struct addrinfo> DnsResolve(
|
||||||
|
|
|
@ -15,13 +15,13 @@
|
||||||
along with UsenetSearch. If not, see <https://www.gnu.org/licenses/>.
|
along with UsenetSearch. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <algorithm>
|
#include "usenetsearch/Filter.h"
|
||||||
#include <iostream>
|
|
||||||
#include <regex>
|
|
||||||
|
|
||||||
#include "usenetsearch/StringUtils.h"
|
#include "usenetsearch/StringUtils.h"
|
||||||
|
|
||||||
#include "usenetsearch/Filter.h"
|
#include <algorithm>
|
||||||
|
#include <iostream>
|
||||||
|
#include <regex>
|
||||||
|
|
||||||
namespace usenetsearch {
|
namespace usenetsearch {
|
||||||
|
|
||||||
|
|
|
@ -15,11 +15,12 @@
|
||||||
along with UsenetSearch. If not, see <https://www.gnu.org/licenses/>.
|
along with UsenetSearch. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
#include "usenetsearch/Indexer.h"
|
||||||
|
|
||||||
|
#include "usenetsearch/Logger.h"
|
||||||
#include "usenetsearch/StringUtils.h"
|
#include "usenetsearch/StringUtils.h"
|
||||||
|
|
||||||
#include "usenetsearch/Indexer.h"
|
#include <iostream>
|
||||||
|
|
||||||
namespace usenetsearch {
|
namespace usenetsearch {
|
||||||
|
|
||||||
|
@ -197,9 +198,6 @@ void Indexer::Index(const std::vector<NntpListEntry>& newsgroups)
|
||||||
dbref.get().SetLastIndexedArticle(
|
dbref.get().SetLastIndexedArticle(
|
||||||
groupID, lastArticle
|
groupID, lastArticle
|
||||||
);
|
);
|
||||||
std::cout << "Setting last indexed article for newsgroup ID "
|
|
||||||
<< groupID << " to: "
|
|
||||||
<< lastArticle << std::endl;
|
|
||||||
}
|
}
|
||||||
std::cout << ".";
|
std::cout << ".";
|
||||||
std::cout.flush();
|
std::cout.flush();
|
||||||
|
|
|
@ -15,11 +15,11 @@
|
||||||
along with UsenetSearch. If not, see <https://www.gnu.org/licenses/>.
|
along with UsenetSearch. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "usenetsearch/IoSocket.h"
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "usenetsearch/IoSocket.h"
|
|
||||||
|
|
||||||
namespace usenetsearch {
|
namespace usenetsearch {
|
||||||
|
|
||||||
std::chrono::milliseconds IoSocket::ConnectionTimeout() const
|
std::chrono::milliseconds IoSocket::ConnectionTimeout() const
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
/*
|
||||||
|
Copyright© 2021 John Sennesael
|
||||||
|
|
||||||
|
UsenetSearch is Free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
UsenetSearch is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with UsenetSearch. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "usenetsearch/Logger.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace usenetsearch {
|
||||||
|
|
||||||
|
std::unique_ptr<Logger> Logger::m_instance;
|
||||||
|
|
||||||
|
Logger::Logger() {}
|
||||||
|
|
||||||
|
Logger& Logger::get()
|
||||||
|
{
|
||||||
|
if (m_instance == nullptr)
|
||||||
|
{
|
||||||
|
m_instance = std::make_unique<Logger>();
|
||||||
|
}
|
||||||
|
return *m_instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logger::debug(const std::string& msg) const
|
||||||
|
{
|
||||||
|
std::cout << "[debug] " << msg << std::endl << std::flush;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logger::info(const std::string& msg) const
|
||||||
|
{
|
||||||
|
std::cout << "[info] " << msg << std::endl << std::flush;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logger::error(const std::string& msg) const
|
||||||
|
{
|
||||||
|
std::cerr << "[error] " << msg << std::endl << std::flush;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace usenetsearch
|
|
@ -15,14 +15,14 @@
|
||||||
along with UsenetSearch. If not, see <https://www.gnu.org/licenses/>.
|
along with UsenetSearch. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <cerrno>
|
#include "usenetsearch/SSLConnection.h"
|
||||||
#include <cstring>
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
#include <openssl/ssl.h>
|
#include <openssl/ssl.h>
|
||||||
#include <openssl/err.h>
|
#include <openssl/err.h>
|
||||||
|
|
||||||
#include "usenetsearch/SSLConnection.h"
|
#include <cerrno>
|
||||||
|
#include <cstring>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace usenetsearch {
|
namespace usenetsearch {
|
||||||
|
|
||||||
|
|
|
@ -13,13 +13,11 @@
|
||||||
along with UsenetSearch. If not, see <https://www.gnu.org/licenses/>.
|
along with UsenetSearch. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <cerrno>
|
#include "usenetsearch/Serialize.h"
|
||||||
#include <codecvt>
|
|
||||||
#include <cstdint>
|
#include "usenetsearch/Database.h"
|
||||||
#include <cstring>
|
#include "usenetsearch/ScopeExit.h"
|
||||||
#include <locale>
|
#include "usenetsearch/UsenetClient.h"
|
||||||
#include <fstream>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
|
@ -27,11 +25,13 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "usenetsearch/Database.h"
|
#include <cerrno>
|
||||||
#include "usenetsearch/ScopeExit.h"
|
#include <codecvt>
|
||||||
#include "usenetsearch/UsenetClient.h"
|
#include <cstdint>
|
||||||
|
#include <cstring>
|
||||||
#include "usenetsearch/Serialize.h"
|
#include <locale>
|
||||||
|
#include <fstream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace usenetsearch {
|
namespace usenetsearch {
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,10 @@
|
||||||
along with UsenetSearch. If not, see <https://www.gnu.org/licenses/>.
|
along with UsenetSearch. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "usenetsearch/StringUtils.h"
|
||||||
|
|
||||||
|
#include <openssl/md5.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <codecvt>
|
#include <codecvt>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
@ -24,10 +28,6 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <openssl/md5.h>
|
|
||||||
|
|
||||||
#include "usenetsearch/StringUtils.h"
|
|
||||||
|
|
||||||
namespace usenetsearch {
|
namespace usenetsearch {
|
||||||
|
|
||||||
static std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> conv;
|
static std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> conv;
|
||||||
|
|
|
@ -15,6 +15,12 @@
|
||||||
along with UsenetSearch. If not, see <https://www.gnu.org/licenses/>.
|
along with UsenetSearch. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "usenetsearch/TcpConnection.h"
|
||||||
|
|
||||||
|
#include "usenetsearch/Dns.h"
|
||||||
|
|
||||||
|
#include <unistd.h> // close(), read(), write()
|
||||||
|
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
@ -22,12 +28,6 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
#include <unistd.h> // close(), read(), write()
|
|
||||||
|
|
||||||
#include "usenetsearch/Dns.h"
|
|
||||||
|
|
||||||
#include "usenetsearch/TcpConnection.h"
|
|
||||||
|
|
||||||
namespace usenetsearch {
|
namespace usenetsearch {
|
||||||
|
|
||||||
TcpConnection::~TcpConnection()
|
TcpConnection::~TcpConnection()
|
||||||
|
|
|
@ -15,6 +15,9 @@
|
||||||
|
|
||||||
#include "usenetsearch/ThreadPool.h"
|
#include "usenetsearch/ThreadPool.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
namespace usenetsearch {
|
namespace usenetsearch {
|
||||||
|
|
||||||
ThreadPool::ThreadPool()
|
ThreadPool::ThreadPool()
|
||||||
|
@ -57,71 +60,19 @@ void ThreadPool::Queue(std::function<void()> fn)
|
||||||
// Wait for an available thread.
|
// Wait for an available thread.
|
||||||
while (m_threads.size() >= m_maxThreads)
|
while (m_threads.size() >= m_maxThreads)
|
||||||
{
|
{
|
||||||
//std::lock_guard<std::mutex> threadsLock(m_threadsMutex);
|
|
||||||
auto foundThread = m_threads.end();
|
auto foundThread = m_threads.end();
|
||||||
//auto foundStatus = m_threadStates->end();
|
|
||||||
for (auto it = m_threads.begin(); it != m_threads.end(); ++it)
|
for (auto it = m_threads.begin(); it != m_threads.end(); ++it)
|
||||||
{
|
{
|
||||||
const auto& t = (*it);
|
const auto& t = (*it);
|
||||||
if (!t) continue;
|
if (!t) continue;
|
||||||
//const auto threadID = t->get_id();
|
|
||||||
//if (threadID == std::thread::id{}) continue;
|
|
||||||
//ThreadStates::iterator statusIt;
|
|
||||||
//{
|
|
||||||
// std::lock_guard<std::mutex> tsl(m_threadStatesMutex);
|
|
||||||
// statusIt = m_threadStates->find(threadID);
|
|
||||||
//}
|
|
||||||
//if (statusIt == m_threadStates->end()) continue;
|
|
||||||
//bool state = statusIt->second;
|
|
||||||
//if (state == true)
|
|
||||||
//{
|
|
||||||
if (t->joinable()) t->join();
|
if (t->joinable()) t->join();
|
||||||
foundThread = it;
|
foundThread = it;
|
||||||
// foundStatus = statusIt;
|
|
||||||
break;
|
break;
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
if (foundThread != m_threads.end()) m_threads.erase(foundThread);
|
if (foundThread != m_threads.end()) m_threads.erase(foundThread);
|
||||||
/*
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> tsl(m_threadStatesMutex);
|
|
||||||
if (foundStatus != m_threadStates->end()) m_threadStates->erase(foundStatus);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
// Spawn a new thread.
|
// Spawn a new thread.
|
||||||
auto thread = std::make_unique<std::thread>(fn);
|
auto thread = std::make_unique<std::thread>(fn);
|
||||||
/*
|
|
||||||
auto thread = std::make_unique<std::thread>(
|
|
||||||
[](std::function<void()> func, std::mutex& tsm, std::shared_ptr<ThreadStates> ts)
|
|
||||||
{
|
|
||||||
if (ts == nullptr) return;
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> tsl(tsm);
|
|
||||||
const auto threadID = std::this_thread::get_id();
|
|
||||||
if (threadID == std::thread::id{}) return;
|
|
||||||
ts->emplace(threadID, false);
|
|
||||||
}
|
|
||||||
func();
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> tsl(tsm);
|
|
||||||
const auto threadID = std::this_thread::get_id();
|
|
||||||
if (threadID != std::thread::id{})
|
|
||||||
{
|
|
||||||
auto it = ts->find(threadID);
|
|
||||||
if (it == ts->end())
|
|
||||||
{
|
|
||||||
ts->emplace(threadID, true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
(*ts)[threadID] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, fn, std::ref(m_threadStatesMutex), m_threadStates);
|
|
||||||
*/
|
|
||||||
//std::lock_guard<std::mutex> threadsLock(m_threadsMutex);
|
|
||||||
m_threads.emplace_back(std::move(thread));
|
m_threads.emplace_back(std::move(thread));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,12 @@
|
||||||
along with UsenetSearch. If not, see <https://www.gnu.org/licenses/>.
|
along with UsenetSearch. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "usenetsearch/UsenetClient.h"
|
||||||
|
|
||||||
|
#include "usenetsearch/Application.h"
|
||||||
|
#include "usenetsearch/Except.h"
|
||||||
|
#include "usenetsearch/StringUtils.h"
|
||||||
|
|
||||||
#include <codecvt>
|
#include <codecvt>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <locale>
|
#include <locale>
|
||||||
|
@ -22,12 +28,6 @@
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "usenetsearch/Application.h"
|
|
||||||
#include "usenetsearch/Except.h"
|
|
||||||
#include "usenetsearch/StringUtils.h"
|
|
||||||
|
|
||||||
#include "usenetsearch/UsenetClient.h"
|
|
||||||
|
|
||||||
namespace usenetsearch {
|
namespace usenetsearch {
|
||||||
|
|
||||||
// UsenetClient class ----------------------------------------------------------
|
// UsenetClient class ----------------------------------------------------------
|
||||||
|
|
|
@ -15,12 +15,12 @@
|
||||||
along with UsenetSearch. If not, see <https://www.gnu.org/licenses/>.
|
along with UsenetSearch. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "usenetsearch/Application.h"
|
#include "usenetsearch/Application.h"
|
||||||
#include "usenetsearch/StringUtils.h"
|
#include "usenetsearch/StringUtils.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
using namespace usenetsearch;
|
using namespace usenetsearch;
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include "usenetsearch/Application.h"
|
#include "usenetsearch/Application.h"
|
||||||
#include "usenetsearch/UsenetClient.h"
|
#include "usenetsearch/UsenetClient.h"
|
||||||
#include "usenetsearch/Indexer.h"
|
#include "usenetsearch/Indexer.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
using namespace usenetsearch;
|
using namespace usenetsearch;
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
|
|
|
@ -15,13 +15,13 @@
|
||||||
along with UsenetSearch. If not, see <https://www.gnu.org/licenses/>.
|
along with UsenetSearch. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include "usenetsearch/Application.h"
|
#include "usenetsearch/Application.h"
|
||||||
#include "usenetsearch/Except.h"
|
#include "usenetsearch/Except.h"
|
||||||
#include "usenetsearch/Indexer.h"
|
#include "usenetsearch/Indexer.h"
|
||||||
#include "usenetsearch/UsenetClient.h"
|
#include "usenetsearch/UsenetClient.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
using namespace usenetsearch;
|
using namespace usenetsearch;
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
|
|
Loading…
Reference in New Issue