- if (special[DLOG_CONS]) {
- char * start = special_buf[DLOG_CONS] + msg_index[DLOG_CONS];
- char * end = std::find(special_buf[DLOG_CONS] + msg_index[DLOG_CONS], (char *)nullptr, '\n');
- int r = write(1, start, end - start + 1);
+ release = true;
+
+ // Try to flush any messages that are currently buffered. (Console is non-blocking
+ // so it will fail gracefully).
+ if (gotEvent(&eventLoop, fd, OUT_EVENTS) == Rearm::DISARM) {
+ // Console has already been released at this point.
+ setEnabled(&eventLoop, false);
+ }
+ // gotEvent didn't want to disarm, so must be partway through a message; will
+ // release when it's finished.
+}
+
+Rearm BufferedLogStream::gotEvent(EventLoop_t *loop, int fd, int flags) noexcept
+{
+ auto &log_stream = *this;
+
+ if ((! partway) && log_stream.special) {
+ char * start = log_stream.special_buf + log_stream.msg_index;
+ char * end = std::find(log_stream.special_buf + log_stream.msg_index, (char *)nullptr, '\n');
+ int r = write(fd, start, end - start + 1);