summaryrefslogtreecommitdiff
path: root/src/lib/util.h
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2012-09-23 14:02:01 +0100
committerCarl Hetherington <cth@carlh.net>2012-09-23 14:02:01 +0100
commit93c3365a547fbb7467b6c47571c5a68e17b31e0c (patch)
tree9c850dfaf6a63f8ddad26c5d2bced2244505cb8d /src/lib/util.h
parentc2709fbe5438da124b2d493cb714a6c58720cf5b (diff)
Untested first cut.
Diffstat (limited to 'src/lib/util.h')
-rw-r--r--src/lib/util.h50
1 files changed, 27 insertions, 23 deletions
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<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