summaryrefslogtreecommitdiff
path: root/src/lib/dcpomatic_socket.h
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2020-04-16 00:38:08 +0200
committerCarl Hetherington <cth@carlh.net>2020-04-17 00:42:54 +0200
commit3f2bec7b6ee2f27b2de056cdc0137744d2e9e253 (patch)
tree34e0d9f72abe35e8e477d92036444d9c47fb7e28 /src/lib/dcpomatic_socket.h
parent5f4a41f20a189ec2863760cd1f5117435277f40f (diff)
Add feature to Socket so that it can send digests of data it has sent
and check those digests on receive.
Diffstat (limited to 'src/lib/dcpomatic_socket.h')
-rw-r--r--src/lib/dcpomatic_socket.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/lib/dcpomatic_socket.h b/src/lib/dcpomatic_socket.h
index 870e7315c..1fa0b046f 100644
--- a/src/lib/dcpomatic_socket.h
+++ b/src/lib/dcpomatic_socket.h
@@ -18,8 +18,11 @@
*/
+#include "digester.h"
#include <boost/asio.hpp>
#include <boost/noncopyable.hpp>
+#include <boost/scoped_ptr.hpp>
+#include <boost/weak_ptr.hpp>
/** @class Socket
* @brief A class to wrap a boost::asio::ip::tcp::socket with some things
@@ -46,8 +49,36 @@ public:
void read (uint8_t* data, int size);
uint32_t read_uint32 ();
+ class ReadDigestScope
+ {
+ public:
+ ReadDigestScope (boost::shared_ptr<Socket> socket);
+ bool check ();
+ private:
+ boost::weak_ptr<Socket> _socket;
+ };
+
+ /** After one of these is created everything that is sent from the socket will be
+ * added to a digest. When the DigestScope is destroyed the digest will be sent
+ * from the socket.
+ */
+ class WriteDigestScope
+ {
+ public:
+ WriteDigestScope (boost::shared_ptr<Socket> socket);
+ ~WriteDigestScope ();
+ private:
+ boost::weak_ptr<Socket> _socket;
+ };
+
private:
+ friend class DigestScope;
+
void check ();
+ void start_read_digest ();
+ bool check_read_digest ();
+ void start_write_digest ();
+ void finish_write_digest ();
Socket (Socket const &);
@@ -55,4 +86,6 @@ private:
boost::asio::deadline_timer _deadline;
boost::asio::ip::tcp::socket _socket;
int _timeout;
+ boost::scoped_ptr<Digester> _read_digester;
+ boost::scoped_ptr<Digester> _write_digester;
};