preCICE v3.1.1
Loading...
Searching...
No Matches
SocketSendQueue.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <boost/asio.hpp>
4#include <deque>
5#include <functional>
6#include <memory>
7#include <mutex>
8#include <string>
9#include "logging/Logger.hpp"
10
11namespace precice {
12namespace com {
13
17public:
18 using Socket = boost::asio::ip::tcp::socket;
19
20 SocketSendQueue() = default;
22
25
27 void dispatch(std::shared_ptr<Socket> sock, boost::asio::const_buffers_1 data, std::function<void()> callback);
28
30 void sendCompleted();
31
32private:
34 void process();
35
36 struct SendItem {
38 boost::asio::const_buffers_1 data;
40 };
41
47 bool _ready = true;
48};
49
50} // namespace com
51} // namespace precice
bool _ready
Is the queue allowed to start another asynchronous send?
boost::asio::ip::tcp::socket Socket
SocketSendQueue(SocketSendQueue const &)=delete
void sendCompleted()
Notifies the queue that the last asynchronous send operation has completed.
std::mutex _queueMutex
The mutex protecting access to the queue.
std::deque< SendItem > _itemQueue
The queue, containing items to asynchronously send using boost.asio.
void dispatch(std::shared_ptr< Socket > sock, boost::asio::const_buffers_1 data, std::function< void()> callback)
Put data in the queue, start processing the queue.
~SocketSendQueue()
If items are left in the queue upon destruction, something went really wrong.
SocketSendQueue & operator=(SocketSendQueue const &)=delete
void process()
This method can be called arbitrarily many times, but enough times to ensure the queue makes progress...
Main namespace of the precice library.