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

Method do_operations

example/cpp11/nonblocking/third_party_lib.cpp:95–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

93
94private:
95 void do_operations()
96 {
97 auto self(shared_from_this());
98
99 // Start a read operation if the third party library wants one.
100 if (session_impl_.want_read() && !read_in_progress_)
101 {
102 read_in_progress_ = true;
103 socket_.async_wait(tcp::socket::wait_read,
104 [this, self](boost::system::error_code ec)
105 {
106 read_in_progress_ = false;
107
108 // Notify third party library that it can perform a read.
109 if (!ec)
110 session_impl_.do_read(ec);
111
112 // The third party library successfully performed a read on the
113 // socket. Start new read or write operations based on what it now
114 // wants.
115 if (!ec || ec == boost::asio::error::would_block)
116 do_operations();
117
118 // Otherwise, an error occurred. Closing the socket cancels any
119 // outstanding asynchronous read or write operations. The
120 // connection object will be destroyed automatically once those
121 // outstanding operations complete.
122 else
123 socket_.close();
124 });
125 }
126
127 // Start a write operation if the third party library wants one.
128 if (session_impl_.want_write() && !write_in_progress_)
129 {
130 write_in_progress_ = true;
131 socket_.async_wait(tcp::socket::wait_write,
132 [this, self](boost::system::error_code ec)
133 {
134 write_in_progress_ = false;
135
136 // Notify third party library that it can perform a write.
137 if (!ec)
138 session_impl_.do_write(ec);
139
140 // The third party library successfully performed a write on the
141 // socket. Start new read or write operations based on what it now
142 // wants.
143 if (!ec || ec == boost::asio::error::would_block)
144 do_operations();
145
146 // Otherwise, an error occurred. Closing the socket cancels any
147 // outstanding asynchronous read or write operations. The
148 // connection object will be destroyed automatically once those
149 // outstanding operations complete.
150 else
151 socket_.close();
152 });

Callers

nothing calls this directly

Calls 6

want_readMethod · 0.80
want_writeMethod · 0.80
async_waitMethod · 0.45
do_readMethod · 0.45
closeMethod · 0.45
do_writeMethod · 0.45

Tested by

no test coverage detected