| 256 | } |
| 257 | |
| 258 | void Session::write() |
| 259 | { |
| 260 | bytes const* out = nullptr; |
| 261 | DEV_GUARDED(x_framing) |
| 262 | { |
| 263 | m_io->writeSingleFramePacket(&m_writeQueue[0], m_writeQueue[0]); |
| 264 | out = &m_writeQueue[0]; |
| 265 | } |
| 266 | auto self(shared_from_this()); |
| 267 | ba::async_write(m_socket->ref(), ba::buffer(*out), [this, self](boost::system::error_code ec, std::size_t /*length*/) |
| 268 | { |
| 269 | ThreadContext tc(info().id.abridged()); |
| 270 | ThreadContext tc2(info().clientVersion); |
| 271 | // must check queue, as write callback can occur following dropped() |
| 272 | if (ec) |
| 273 | { |
| 274 | clog(NetWarn) << "Error sending: " << ec.message(); |
| 275 | drop(TCPError); |
| 276 | return; |
| 277 | } |
| 278 | |
| 279 | DEV_GUARDED(x_framing) |
| 280 | { |
| 281 | m_writeQueue.pop_front(); |
| 282 | if (m_writeQueue.empty()) |
| 283 | return; |
| 284 | } |
| 285 | write(); |
| 286 | }); |
| 287 | } |
| 288 | |
| 289 | void Session::writeFrames() |
| 290 | { |