2

I am reading Boost.Beast documentation and I am trying to use rate limiting in my code:

  io_context context;
  tcp::resolver resolver(context);
  basic_stream<tcp, executor, simple_rate_policy> stream(context);

  stream.rate_policy().write_limit(1);

  stream.connect(resolver.resolve("www.example.com", "http"));

  string response;

  write(stream, buffer("GET /index.html HTTP/1.1\r\nHost: www.example.com\r\n\r\n"));

  read_until(stream, dynamic_buffer(response), "\r\n\r\n");

  cout << response << endl;

  context.run();

If I am correct, this sample code should cause very long writing via socket connected with endpoint www.example.com:80. But simple_rate_policy seems to work only for asyc reads and writes. Am I doing something wrong or is it purposeful behaviour?

Will Ness
  • 70,110
  • 9
  • 98
  • 181
Jonny Dens
  • 49
  • 1

1 Answers1

1

The limits only work for asynchronous operations.

Vinnie Falco
  • 5,173
  • 28
  • 43
  • 1
    Is there anything about it in documentation? I wanted to help here, but only thing I managed to find is related to timeouts: `For portability reasons, networking does not provide timeouts or cancellation features for synchronous stream operations`. – Kasata Ata Oct 28 '19 at 14:11