X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Futil.h;h=c3a42e448e55dbc75f425f8b10676fc69f494611;hb=93c3365a547fbb7467b6c47571c5a68e17b31e0c;hp=568fe05d035ea56589be3e98639323da74df903b;hpb=c2709fbe5438da124b2d493cb714a6c58720cf5b;p=dcpomatic.git diff --git a/src/lib/util.h b/src/lib/util.h index 568fe05d0..c3a42e448 100644 --- a/src/lib/util.h +++ b/src/lib/util.h @@ -56,29 +56,6 @@ enum ContentType { extern void md5_data (std::string, void const *, int); #endif -/** @class SocketReader - * @brief A helper class from reading from sockets. - * - * You can probably do this stuff directly in boost, but I'm not sure how. - */ -class SocketReader -{ -public: - SocketReader (boost::shared_ptr); - - void read_definite_and_consume (uint8_t *, int); - void read_indefinite (uint8_t *, int); - void consume (int); - -private: - /** socket we are reading from */ - boost::shared_ptr _socket; - /** a buffer for small reads */ - uint8_t _buffer[256]; - /** amount of valid data in the buffer */ - int _buffer_data; -}; - /** @class Size * @brief Representation of the size of something */ struct Size @@ -136,4 +113,31 @@ extern std::string crop_string (Position, Size); extern int dcp_audio_sample_rate (int); extern std::string colour_lut_index_to_name (int index); +class DeadlineWrapper +{ +public: + DeadlineWrapper (boost::asio::io_service& io_service); + + void set_socket (boost::shared_ptr socket); + + void connect (boost::asio::ip::basic_resolver_entry const & endpoint, int timeout); + void write (uint8_t const * data, int size, int timeout); + int read (uint8_t* data, int size, int timeout); + + void read_definite_and_consume (uint8_t* data, int size, int timeout); + void read_indefinite (uint8_t* data, int size, int timeout); + void consume (int amount); + +private: + void check (); + + boost::asio::io_service& _io_service; + boost::asio::deadline_timer _deadline; + boost::shared_ptr _socket; + /** a buffer for small reads */ + uint8_t _buffer[256]; + /** amount of valid data in the buffer */ + int _buffer_data; +}; + #endif