summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Mazieres <dm@uun.org>2017-05-04 21:47:02 -0700
committerDavid Mazieres <dm@uun.org>2017-05-04 21:47:02 -0700
commit3c16f97fa5e1fabc94be03d6495c2f09e1dca7de (patch)
treeedf50e9b7698d220b0ac31fd6bc0e064f3bd838d
parent64987595db97297cdea8c25da6685b0061779111 (diff)
bump version to 3muchsync-3
-rw-r--r--NEWS2
-rw-r--r--configure.ac2
-rw-r--r--infinibuf.h23
-rw-r--r--protocol.cc4
-rw-r--r--sql_db.cc2
5 files changed, 27 insertions, 6 deletions
diff --git a/NEWS b/NEWS
index b8ff40b..cc549e7 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,7 @@
* Changes in release 3
+Cleaned up a few compilation warnings.
+
Added help command to --server mode.
Added --newid command-line option.
diff --git a/configure.ac b/configure.ac
index 9aedcba..e9c7bcf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
-AC_INIT(muchsync, 2)
+AC_INIT(muchsync, 3)
AM_INIT_AUTOMAKE([-Wall])
AC_CONFIG_SRCDIR([configure.ac])
AC_CONFIG_MACRO_DIR([m4])
diff --git a/infinibuf.h b/infinibuf.h
index 67a5953..1fd4788 100644
--- a/infinibuf.h
+++ b/infinibuf.h
@@ -108,6 +108,16 @@ public:
* `errno` is not `EAGAIN`. */
int input(int fd);
+ /** Calls `output` over and over in a loop on an `infinibuf`.
+ *
+ * \param ib The `infinibuf` on which to call `output`.
+ *
+ * \param fd The file descriptor to which to write consumed data.
+ *
+ * \param oblocked If non-null is called with `true` whenever the
+ * output is blocked by flow control, and then called again with
+ * `false` when the output becomes unblocked.
+ */
static void output_loop(std::shared_ptr<infinibuf> ib, int fd,
std::function<void(bool)> oblocked = nullptr);
static void input_loop(std::shared_ptr<infinibuf> ib, int fd);
@@ -167,7 +177,7 @@ public:
void gwait() override {
if (empty() && !eof()) {
std::unique_lock<std::mutex> ul (m_, std::adopt_lock);
- if (empty() && !eof())
+ while (empty() && !eof())
cv_.wait(ul);
ul.release();
}
@@ -237,6 +247,8 @@ public:
* another thread. Closes the file descriptor after receiving EOF.
* Kill the input thread if any further input is received, but the
* input thread could get stuck if no input and no EOF happens.
+ * Maximum buffer size defaults to infinity but can be adjusted with
+ * `ifdinfinistream::set_max_buf_size`.
*/
class ifdinfinistream : public std::istream {
std::shared_ptr<infinibuf_mt> ib_ { new infinibuf_mt() };
@@ -249,6 +261,10 @@ public:
t.detach();
init(&isb_);
}
+ /** Sets maximum buffer size, above which it will stop reading from
+ * the file descriptor until more is consumed locally.
+ *
+ * A value of 0 means no maximum buffer size. */
void set_max_buf_size(std::size_t size) { ib_->set_max_buf_size(size); }
~ifdinfinistream() {
std::lock_guard<infinibuf> _lk (*isb_.get_infinibuf());
@@ -271,6 +287,7 @@ public:
}
};
+#if 0
/** \brief `ostream` from file descriptor with unbounded buffer.
*
* Buffers unbounded amounts of data which are drained to a file
@@ -287,7 +304,8 @@ public:
t_ = std::move(t);
rdbuf(&isb_);
}
- ~ofdinfinistream() {
+ // Doesn't work because std::ostream's virtual destructor is noexcept.
+ ~ofdinfinistream() noexcept(false) {
isb_.sputeof();
if (!std::uncaught_exception()) {
t_.join();
@@ -298,5 +316,6 @@ public:
}
}
};
+#endif
#endif /* !_INFINIBUF_H_ */
diff --git a/protocol.cc b/protocol.cc
index d8992c0..94954bf 100644
--- a/protocol.cc
+++ b/protocol.cc
@@ -87,8 +87,8 @@ inline uint32_t
randint()
{
uint32_t v;
- if (RAND_pseudo_bytes ((unsigned char *) &v, sizeof (v)) == -1)
- throw runtime_error ("RAND_pseudo_bytes failed");
+ if (RAND_bytes ((unsigned char *) &v, sizeof (v)) == -1)
+ throw runtime_error ("RAND_bytes failed");
return v;
}
diff --git a/sql_db.cc b/sql_db.cc
index ea39b7b..145164a 100644
--- a/sql_db.cc
+++ b/sql_db.cc
@@ -69,7 +69,7 @@ i64
create_random_id()
{
i64 id = 0;
- if (RAND_pseudo_bytes ((unsigned char *) &id, sizeof (id)) == -1 || id == 0) {
+ if (RAND_bytes ((unsigned char *) &id, sizeof (id)) == -1 || id == 0) {
cerr << "RAND_pseudo_bytes failed\n";
return -1;
}