51 lines
1.4 KiB
C++
51 lines
1.4 KiB
C++
// BoostSocket.h
|
|
#include <boost/asio.hpp>
|
|
#include "SocketInterface.h"
|
|
|
|
class BoostSocket : public SocketInterface {
|
|
public:
|
|
BoostSocket() : socket_(io_service_) {}
|
|
|
|
void connect(const std::string& host, unsigned short port) override {
|
|
boost::asio::ip::tcp::resolver resolver(io_service_);
|
|
boost::asio::ip::tcp::resolver::results_type endpoints = resolver.resolve(host, std::to_string(port));
|
|
boost::asio::connect(socket_, endpoints);
|
|
}
|
|
|
|
void writeLine(const std::string& data) override {
|
|
boost::asio::write(socket_, boost::asio::buffer(data + "\r\n"));
|
|
}
|
|
|
|
std::string readLine() override {
|
|
boost::asio::streambuf buf;
|
|
boost::asio::read_until(socket_, buf, "\r\n");
|
|
std::istream is(&buf);
|
|
std::string line;
|
|
std::getline(is, line);
|
|
return line;
|
|
}
|
|
|
|
bool canRead(double timeout) override {
|
|
// Implementation to check if data is available to read.
|
|
}
|
|
|
|
bool isClosed() override {
|
|
return !socket_.is_open();
|
|
}
|
|
|
|
void close() override {
|
|
socket_.close();
|
|
}
|
|
|
|
void prepareSSL(bool incoming) override {
|
|
// Implement SSL preparation here if needed.
|
|
}
|
|
|
|
void startSSL(bool incoming) override {
|
|
// Implement starting SSL here if needed.
|
|
}
|
|
|
|
private:
|
|
boost::asio::io_service io_service_;
|
|
boost::asio::ip::tcp::socket socket_;
|
|
};
|