Change API of raw_istream to be more similar to raw_ostream.

This commit is contained in:
Peter Johnson
2016-09-02 20:53:45 -07:00
parent 94c2b65798
commit c2ae897b02
6 changed files with 43 additions and 17 deletions

View File

@@ -103,7 +103,8 @@ bool ReadUleb128(raw_istream& is, unsigned long* ret) {
while (1) {
unsigned char byte;
if (!is.read((char*)&byte, 1)) return false;
is.read((char*)&byte, 1);
if (is.has_error()) return false;
result |= (byte & 0x7f) << shift;
shift += 7;

View File

@@ -11,10 +11,14 @@
using namespace wpi;
bool raw_mem_istream::read(void* data, std::size_t len) {
if (len > m_left) return false;
void raw_mem_istream::close() {}
void raw_mem_istream::read_impl(void* data, std::size_t len) {
if (len > m_left) {
error_detected();
return;
}
std::memcpy(data, m_cur, len);
m_cur += len;
m_left -= len;
return true;
}

View File

@@ -6,10 +6,11 @@
/*----------------------------------------------------------------------------*/
#include "support/raw_socket_istream.h"
#include "tcpsockets/NetworkStream.h"
using namespace wpi;
bool raw_socket_istream::read(void* data, std::size_t len) {
void raw_socket_istream::read_impl(void* data, std::size_t len) {
char* cdata = static_cast<char*>(data);
std::size_t pos = 0;
@@ -17,10 +18,12 @@ bool raw_socket_istream::read(void* data, std::size_t len) {
NetworkStream::Error err;
std::size_t count =
m_stream.receive(&cdata[pos], len - pos, &err, m_timeout);
if (count == 0) return false;
if (count == 0) {
error_detected();
return;
}
pos += count;
}
return true;
}
void raw_socket_istream::close() { m_stream.close(); }