Implement basic input buffer handling functions for IOImplementation
[libasyncio] / asyncio / async_io.cpp
index c85edb5..a0e5d3a 100644 (file)
@@ -1032,6 +1032,49 @@ void IOImplementation::doWrite()
     }
 } // eo IOImplementation::doWrite
 
+/**
+ * Return a copy of the input buffer.
+ */
+std::string IOImplementation::getInput() const
+{
+    return m_input_buffer;
+}
+
+/**
+ * Return the input buffer and clear it.
+ */
+std::string IOImplementation::getInputClear()
+{
+    std::string retbuf;
+
+    retbuf.swap(m_input_buffer);
+
+    return retbuf;
+}
+
+/**
+ * Return true if there are bytes available in the input buffer.
+ */
+bool IOImplementation::inputAvailable() const
+{
+    return !m_input_buffer.empty();
+}
+
+/**
+ * Cut off the first len bytes from the input buffer.
+ * @returns The number of bytes actually shortened
+ */
+std::string::size_type IOImplementation::shortenInput(std::string::size_type len)
+{
+    std::string::size_type real_len=len;
+    if (real_len > m_input_buffer.size())
+        real_len=m_input_buffer.size();
+
+    if (real_len > 0)
+        m_input_buffer.erase(0,real_len);
+
+    return real_len;
+}
 
 /*
  * implementation of SimpleIO