summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Noble <pixel@nobis-crew.org>2014-08-11 15:17:00 -0700
committerNicolas Noble <pixel@nobis-crew.org>2014-08-11 15:17:00 -0700
commit99992fdf4c09b6ee582874b6b563a2c242498640 (patch)
treebd5bac1a578ff9d18ae6bf9073f6caa9687a1512
parent39c7dcb8e2c3c13d1adce2e482b6579fe763504f (diff)
Turns out, sometime I have good ideas; the shared_ptr in that Future is here so that the memory won't move even if the Future itself does. Putting that back in.
-rw-r--r--src/Handle.cc12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/Handle.cc b/src/Handle.cc
index ef24716..7162cd8 100644
--- a/src/Handle.cc
+++ b/src/Handle.cc
@@ -96,29 +96,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) {
- T b;
+ std::shared_ptr<T> b(new T);
size_t c = 0;
return Balau::Future<T>([t, b, c]() mutable {
do {
- ssize_t r = t->read(((uint8_t *) &b) + c, sizeof(T) - c);
+ ssize_t r = t->read(((uint8_t *) b.get()) + c, sizeof(T) - c);
AAssert(r >= 0, "genericRead got an error: %zi", r);
c += r;
} while ((c < sizeof(T)) && !t->isEOF());
- return b;
+ return *b;
});
}
template<class T>
Balau::Future<T> genericReadBE(Balau::IO<Balau::Handle> t) {
- T b;
+ std::shared_ptr<T> b(new T);
size_t c = sizeof(T);
return Balau::Future<T>([t, b, c]() mutable {
do {
- ssize_t r = t->read(((uint8_t *) &b) + c - 1, 1);
+ ssize_t r = t->read(((uint8_t *) b.get()) + c - 1, 1);
AAssert(r >= 0, "genericReadBE got an error: %zi", r);
c -= r;
} while (c && !t->isEOF());
- return b;
+ return *b;
});
}