From 3f2bec7b6ee2f27b2de056cdc0137744d2e9e253 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 16 Apr 2020 00:38:08 +0200 Subject: Add feature to Socket so that it can send digests of data it has sent and check those digests on receive. --- src/lib/dcpomatic_socket.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/lib/dcpomatic_socket.h') 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 #include +#include +#include /** @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); + bool check (); + private: + boost::weak_ptr _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); + ~WriteDigestScope (); + private: + boost::weak_ptr _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 _read_digester; + boost::scoped_ptr _write_digester; }; -- cgit v1.2.3