Я пытаюсь отправить запрос на вход на сервер IMAP. Я создаю сокет как:
int main(int argc, char *argv[])
{
boost::asio::io_service ioService;
boost::asio::ssl::context sslContext(boost::asio::ssl::context::sslv23);
boost::asio::ssl::stream<boost::asio::ip::tcp::socket> sslSocket(ioService, sslContext);
sslSocket.set_verify_mode(boost::asio::ssl::verify_none);
boost::asio::ip::tcp::socket::lowest_layer_type &socket = sslSocket.lowest_layer();
// Resolve endpoint and connect successfully...
std::stringstream ss;
ss << "$ LOGIN " << username << " " << password;
const char *req = ss.str().c_str();
char data[500];
strcpy(data, req);
boost::asio::write(socket, boost::asio::buffer(data, sizeof(data)));
char buffer[1000];
boost::asio::read(socket, boost::asio::buffer(buffer));
std::string response = std::string(buffer);
std::cout << "Received response: " << response << std::endl;
return 0;
}
Мой CMakeLists.txt выглядит так:
cmake_minimum_required(VERSION 3.16)
project(Cindel LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
add_executable(app main.cpp)
find_package(OpenSSL REQUIRED)
include_directories(${OPENSSL_INCLUDE_DIRS})
target_link_libraries(app ${OPENSSL_LIBRARIES})
set(Boost_USE_STATIC_LIBS ON)
find_package(Boost COMPONENTS system REQUIRED)
include_directories(${Boost_INCLUDE_DIR})
target_link_libraries(app ${BOOST_LIBRARIES})
Когда я компилирую это, я получаю следующие ошибки:
/usr/bin/clang++ -I/ -pthread -std=gnu++17 -MD -MT CMakeFiles/app.dir/main.cpp.o -MF CMakeFiles/app.dir/main.cpp.o.d -o CMakeFiles/app.dir/main.cpp.o -c /src/main.cpp
In file included from /src/main.cpp:3:
In file included from /usr/include/boost/asio/write.hpp:1246:
/usr/include/boost/asio/impl/write.hpp:54:23: error: no member named 'write_some' in 'boost::asio::basic_socket<boost::asio::ip::tcp, boost::asio::executor>'
tmp.consume(s.write_some(tmp.prepare(max_size), ec));
~ ^
/usr/include/boost/asio/impl/write.hpp:70:18: note: in instantiation of function template specialization 'boost::asio::detail::write_buffer_sequence<boost::asio::basic_socket<boost::asio::ip::tcp, boost::asio::executor>, boost::asio::mutable_buffers_1, const boost::asio::mutable_buffer *, boost::asio::detail::transfer_all_t>' requested here
return detail::write_buffer_sequence(s, buffers,
^
/usr/include/boost/asio/impl/write.hpp:82:35: note: in instantiation of function template specialization 'boost::asio::write<boost::asio::basic_socket<boost::asio::ip::tcp, boost::asio::executor>, boost::asio::mutable_buffers_1, boost::asio::detail::transfer_all_t>' requested here
std::size_t bytes_transferred = write(s, buffers, transfer_all(), ec);
^
/src/main.cpp:59:18: note: in instantiation of function template specialization 'boost::asio::write<boost::asio::basic_socket<boost::asio::ip::tcp, boost::asio::executor>, boost::asio::mutable_buffers_1>' requested here
boost::asio::write(socket, boost::asio::buffer(data, sizeof(data)));
^
In file included from /src/main.cpp:2:
In file included from /usr/include/boost/asio/read.hpp:1288:
/usr/include/boost/asio/impl/read.hpp:56:23: error: no member named 'read_some' in 'boost::asio::basic_socket<boost::asio::ip::tcp, boost::asio::executor>'
tmp.consume(s.read_some(tmp.prepare(max_size), ec));
~ ^
/usr/include/boost/asio/impl/read.hpp:72:18: note: in instantiation of function template specialization 'boost::asio::detail::read_buffer_sequence<boost::asio::basic_socket<boost::asio::ip::tcp, boost::asio::executor>, boost::asio::mutable_buffers_1, const boost::asio::mutable_buffer *, boost::asio::detail::transfer_all_t>' requested here
return detail::read_buffer_sequence(s, buffers,
^
/usr/include/boost/asio/impl/read.hpp:84:35: note: in instantiation of function template specialization 'boost::asio::read<boost::asio::basic_socket<boost::asio::ip::tcp, boost::asio::executor>, boost::asio::mutable_buffers_1, boost::asio::detail::transfer_all_t>' requested here
std::size_t bytes_transferred = read(s, buffers, transfer_all(), ec);
^
/src/main.cpp:62:18: note: in instantiation of function template specialization 'boost::asio::read<boost::asio::basic_socket<boost::asio::ip::tcp, boost::asio::executor>, boost::asio::mutable_buffers_1>' requested here
boost::asio::read(socket, boost::asio::buffer(buffer));
РЕДАКТИРОВАТЬ:
Моя версия Boost 1.72.