简体   繁体   中英

C++ Iterator Facade for sockets

I was wondering if there is a good implementation (library) of a C++ iterator facade around sockets. I've gone through the Boost Iterator library and ASIO, and can't seem to find anything. An open source solution would be great!

I'm looking for a solution to 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.

@Gerdiner, Boost.Asio is the winner. Regarding your istream_iterator, check out the following:

boost::asio::streambuf myBuffer;
std::string myString;

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

With ASIO, you won't need an iterator, however. See the following async client for a starting place.

Async HTTP Client

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM