Every time the timer fires we will generate a new frame and send it to all subscribers.
| 118 | // Every time the timer fires we will generate a new frame and send it to all |
| 119 | // subscribers. |
| 120 | void handle_timer() |
| 121 | { |
| 122 | // Generate payload. |
| 123 | double x = next_frame_number_ * 0.2; |
| 124 | double y = std::sin(x); |
| 125 | int char_index = static_cast<int>((y + 1.0) * (frame::payload_size / 2)); |
| 126 | std::string payload; |
| 127 | for (int i = 0; i < frame::payload_size; ++i) |
| 128 | payload += (i == char_index ? '*' : '.'); |
| 129 | |
| 130 | // Create the frame to be sent to all subscribers. |
| 131 | frame f(next_frame_number_++, payload); |
| 132 | |
| 133 | // Send frame to all subscribers. We can use synchronous calls here since |
| 134 | // UDP send operations typically do not block. |
| 135 | std::set<udp::endpoint>::iterator j; |
| 136 | for (j = subscribers_.begin(); j != subscribers_.end(); ++j) |
| 137 | { |
| 138 | boost::system::error_code ec; |
| 139 | udp_socket_.send_to(f.to_buffers(), *j, 0, ec); |
| 140 | } |
| 141 | |
| 142 | // Wait for next timeout. |
| 143 | timer_.expires_after(boost::asio::chrono::milliseconds(100)); |
| 144 | timer_.async_wait(std::bind(&server::handle_timer, this)); |
| 145 | } |
| 146 | |
| 147 | private: |
| 148 | // The acceptor used to accept incoming control connections. |
nothing calls this directly
no test coverage detected