Created
February 13, 2018 13:28
-
-
Save edouarda/ba33edcdd792a22f7f5e205bc1477041 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <boost/asio.hpp> | |
#include <iostream> | |
int main(int, char **) | |
{ | |
boost::asio::io_context context; | |
auto ip = boost::asio::ip::address::from_string("127.0.0.1"); | |
auto ep = boost::asio::ip::tcp::endpoint{ip, 666}; | |
boost::asio::ip::tcp::acceptor acc{context, ep}; | |
while (true) | |
{ | |
boost::system::error_code ec; | |
auto s = acc.accept(ec); | |
if (ec) | |
{ | |
std::cerr << ec.value() << ec.message() << std::endl; | |
break; | |
} | |
std::array<std::uint8_t, 1024> discard_buffer; | |
while (!ec) | |
{ | |
auto l = s.read_some(boost::asio::buffer(discard_buffer), ec); | |
if (ec) break; | |
boost::asio::write( | |
s, boost::asio::const_buffer{discard_buffer.data(), l}, ec); | |
} | |
s.shutdown(boost::asio::socket_base::shutdown_both, ec); | |
s.close(ec); | |
} | |
acc.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment