summaryrefslogtreecommitdiff
path: root/src/Handle.cc
diff options
context:
space:
mode:
authorNicolas "Pixel" Noble <pixel@nobis-crew.org>2014-08-09 19:23:48 -0700
committerNicolas "Pixel" Noble <pixel@nobis-crew.org>2014-08-09 19:23:48 -0700
commitbddaf98342a461f4e02389d4db390098fb423fbf (patch)
tree30e472aa10754b2c93a24a3519387b766e814907 /src/Handle.cc
parent032872bf6f7c14b0fdbc9cd75daae56bbeb50af0 (diff)
Fixing even more warnings.
Diffstat (limited to 'src/Handle.cc')
-rw-r--r--src/Handle.cc31
1 files changed, 15 insertions, 16 deletions
diff --git a/src/Handle.cc b/src/Handle.cc
index e75edbb..e73d2fc 100644
--- a/src/Handle.cc
+++ b/src/Handle.cc
@@ -102,30 +102,29 @@ ssize_t Balau::Handle::forceWrite(const void * _buf, size_t count, Events::BaseE
template<class T>
Balau::Future<T> genericRead(Balau::IO<Balau::Handle> t) {
- std::shared_ptr<T> b(new T);
- int c = 0;
+ T b;
+ size_t c = 0;
return Balau::Future<T>([t, b, c]() mutable {
do {
- int r = t->read(((uint8_t *) b.get()) + c, sizeof(T) - c);
+ ssize_t r = t->read(((uint8_t *) &b) + c, sizeof(T) - c);
+ AAssert(r >= 0, "genericRead got an error: %zi", r);
c += r;
- } while (c < sizeof(T));
- return *b;
+ } while ((c < sizeof(T)) && !t->isEOF());
+ return b;
});
}
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;
+ T b;
+ size_t c = sizeof(T);
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;
+ ssize_t r = t->read(((uint8_t *) &b) + c - 1, 1);
+ AAssert(r >= 0, "genericReadBE got an error: %zi", r);
+ c -= r;
+ } while (c && !t->isEOF());
+ return b;
});
}
@@ -186,10 +185,10 @@ Balau::Future<int64_t> Balau::Handle::readBEI64() { return genericReadBE<int64_
template<class T>
Balau::Future<void> genericWrite(Balau::IO<Balau::Handle> t, T val) {
std::shared_ptr<T> b(new T(val));
- int c = 0;
+ size_t c = 0;
return Balau::Future<void>([t, b, c]() mutable {
do {
- int r = t->write(((uint8_t *) b.get()) + c, sizeof(T));
+ ssize_t r = t->write(((uint8_t *) b.get()) + c, sizeof(T));
c += r;
} while (c < sizeof(T));
});