Untested first cut.
[dcpomatic.git] / src / lib / util.h
index 568fe05d035ea56589be3e98639323da74df903b..c3a42e448e55dbc75f425f8b10676fc69f494611 100644 (file)
@@ -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<boost::asio::ip::tcp::socket>);
-
-       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<boost::asio::ip::tcp::socket> _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<boost::asio::ip::tcp::socket> socket);
+
+       void connect (boost::asio::ip::basic_resolver_entry<boost::asio::ip::tcp> 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<boost::asio::ip::tcp::socket> _socket;
+       /** a buffer for small reads */
+       uint8_t _buffer[256];
+       /** amount of valid data in the buffer */
+       int _buffer_data;
+};
+
 #endif