Browse Source

Properly implement BufferStream::read

The existing implementation did not advance the buffer at all.
Tyler Rockwood 6 years ago
parent
commit
fcdaa24fc5
1 changed files with 5 additions and 2 deletions
  1. 5 2
      httplib.h

+ 5 - 2
httplib.h

@@ -387,6 +387,7 @@ public:
 
 
 private:
 private:
   std::string buffer;
   std::string buffer;
+  int position = 0;
 };
 };
 
 
 class TaskQueue {
 class TaskQueue {
@@ -2750,10 +2751,12 @@ inline std::string SocketStream::get_remote_addr() const {
 // Buffer stream implementation
 // Buffer stream implementation
 inline int BufferStream::read(char *ptr, size_t size) {
 inline int BufferStream::read(char *ptr, size_t size) {
 #if defined(_MSC_VER) && _MSC_VER < 1900
 #if defined(_MSC_VER) && _MSC_VER < 1900
-  return static_cast<int>(buffer._Copy_s(ptr, size, size));
+  int len_read = static_cast<int>(buffer._Copy_s(ptr, size, size, position));
 #else
 #else
-  return static_cast<int>(buffer.copy(ptr, size));
+  int len_read = static_cast<int>(buffer.copy(ptr, size, position));
 #endif
 #endif
+  position += len_read;
+  return len_read;
 }
 }
 
 
 inline int BufferStream::write(const char *ptr, size_t size) {
 inline int BufferStream::write(const char *ptr, size_t size) {