Jonny Dens
Jonny Dens

Reputation: 49

Boost.Beast rate limiting

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?

Upvotes: 2

Views: 655

Answers (1)

Vinnie Falco
Vinnie Falco

Reputation: 5353

The limits only work for asynchronous operations.

Upvotes: 1

Related Questions