MCPcopy Create free account
hub / github.com/boostorg/asio / handle_timer

Method handle_timer

example/cpp11/porthopper/server.cpp:120–145  ·  view source on GitHub ↗

Every time the timer fires we will generate a new frame and send it to all subscribers.

Source from the content-addressed store, hash-verified

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
147private:
148 // The acceptor used to accept incoming control connections.

Callers

nothing calls this directly

Calls 7

bindFunction · 0.50
beginMethod · 0.45
endMethod · 0.45
send_toMethod · 0.45
to_buffersMethod · 0.45
expires_afterMethod · 0.45
async_waitMethod · 0.45

Tested by

no test coverage detected