C ++ Iterator Facade for Sockets

I was wondering if there is a good implementation (library) of the facade of the C ++ iterator around sockets. I went through the Boost Iterator library and ASIO and cannot find anything. An open source solution would be great!

I am looking for a solution for the following use case:

int socket_handler = 0; socket_iterator it(socket_handler); socket_iterator end; //read mode 1: while (it != end) { char c = *it; . . ++it; } //read mode 2: while (it != end) { std::string s = *it; . . ++it; } //write mode 1: unsigned char c = 0; while (c < 100) { *it = c++; . . ++it; } //write mode 2: std::sttring s = "abc"; for (unsigned int i = 0; i < 10; ++i) { *it = s; . . ++it; } 

Note: it == end when the connection is disconnected.

+4
source share
1 answer

@Gerdiner, Boost.Asio is the winner. As for your istream_iterator, check the following:

 boost::asio::streambuf myBuffer; std::string myString; // Convert streambuf to std::string std::istream(&myBuffer) >> myString; 

In ASIO you don't need an iterator. See the following asynchronous client for the source location.

Asynchronous HTTP Client

+2
source

All Articles