summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNicolas "Pixel" Noble <pixel@nobis-crew.org>2013-12-19 23:45:50 -0800
committerNicolas "Pixel" Noble <pixel@nobis-crew.org>2013-12-19 23:45:50 -0800
commit28e250cda01038c91fb9b69206c6f61f24764469 (patch)
treedffa27bd9433c7822896046f2842f25f2bacc047 /src
parentc740946b5871745e72444136fd229304c9658b41 (diff)
parent367ba1df2786888451328416a2db991fa8018083 (diff)
Merge branch 'master' of ssh+git://git.grumpycoder.net/pub/repo.git/Balau
Diffstat (limited to 'src')
-rw-r--r--src/Handle.cc29
-rw-r--r--src/Input.cc2
2 files changed, 28 insertions, 3 deletions
diff --git a/src/Handle.cc b/src/Handle.cc
index 3b40c84..e6c0777 100644
--- a/src/Handle.cc
+++ b/src/Handle.cc
@@ -106,14 +106,30 @@ Balau::Future<T> genericRead(Balau::IO<Balau::Handle> t) {
int c = 0;
return Balau::Future<T>([t, b, c]() mutable {
do {
- int r = t->read(((uint8_t *) b.get()) + c, sizeof(T));
+ int r = t->read(((uint8_t *) b.get()) + c, sizeof(T) - c);
c += r;
} while (c < sizeof(T));
return *b;
});
}
-Balau::Future<uint8_t> Balau::Handle::readU8 () { return genericRead<uint8_t >(this); }
+template<class T>
+Balau::Future<T> genericReadBE(Balau::IO<Balau::Handle> t) {
+ std::shared_ptr<T> b(new T);
+ int c = 0;
+ *b.get() = 0;
+ return Balau::Future<T>([t, b, c]() mutable {
+ do {
+ uint8_t v = t->readU8().get();
+ *b.get() <<= 8;
+ *b.get() += v;
+ c++;
+ } while (c < sizeof(T));
+ return *b;
+ });
+}
+
+Balau::Future<uint8_t> Balau::Handle::readU8() { return genericRead<uint8_t> (this); }
Balau::Future<uint16_t> Balau::Handle::readU16() { return genericRead<uint16_t>(this); }
Balau::Future<uint32_t> Balau::Handle::readU32() { return genericRead<uint32_t>(this); }
Balau::Future<uint64_t> Balau::Handle::readU64() { return genericRead<uint64_t>(this); }
@@ -122,6 +138,15 @@ Balau::Future<int16_t> Balau::Handle::readI16() { return genericRead<int16_t> (
Balau::Future<int32_t> Balau::Handle::readI32() { return genericRead<int32_t> (this); }
Balau::Future<int64_t> Balau::Handle::readI64() { return genericRead<int64_t> (this); }
+Balau::Future<uint8_t> Balau::Handle::readBEU8() { return genericReadBE<uint8_t> (this); }
+Balau::Future<uint16_t> Balau::Handle::readBEU16() { return genericReadBE<uint16_t>(this); }
+Balau::Future<uint32_t> Balau::Handle::readBEU32() { return genericReadBE<uint32_t>(this); }
+Balau::Future<uint64_t> Balau::Handle::readBEU64() { return genericReadBE<uint64_t>(this); }
+Balau::Future<int8_t> Balau::Handle::readBEI8() { return genericReadBE<int8_t> (this); }
+Balau::Future<int16_t> Balau::Handle::readBEI16() { return genericReadBE<int16_t> (this); }
+Balau::Future<int32_t> Balau::Handle::readBEI32() { return genericReadBE<int32_t> (this); }
+Balau::Future<int64_t> Balau::Handle::readBEI64() { return genericReadBE<int64_t> (this); }
+
template<class T>
Balau::Future<void> genericWrite(Balau::IO<Balau::Handle> t, T val) {
std::shared_ptr<T> b(new T(val));
diff --git a/src/Input.cc b/src/Input.cc
index 2a87a5d..64a05ec 100644
--- a/src/Input.cc
+++ b/src/Input.cc
@@ -40,7 +40,7 @@ class AsyncOpOpen : public Balau::AsyncOperation {
AsyncOpOpen(const char * path, cbResults_t * results) : m_path(path), m_results(results) { }
virtual void run() {
#ifdef _MSC_VER
- const ssize_t r = m_results->result = _open(m_path, O_RDONLY);
+ const ssize_t r = m_results->result = _open(m_path, O_RDONLY | O_BINARY);
#else
const ssize_t r = m_results->result = open(m_path, O_RDONLY);
#endif