testencoding_LDADD = libceph.la libcrush.la -lpthread -lm -lcrypto
bin_PROGRAMS += testencoding
-testsyslog_streambuf_SOURCES = test/TestSyslogStreambuf.cc
-testsyslog_streambuf_LDADD = libceph.la libcrush.la -lpthread
-bin_PROGRAMS += testsyslog_streambuf
+testdout_streambuf_SOURCES = test/TestDoutStreambuf.cc
+testdout_streambuf_LDADD = libceph.la libcrush.la -lpthread
+bin_PROGRAMS += testdout_streambuf
endif
config.cc \
common/page.cc \
common/lockdep.cc \
- common/SyslogStreambuf.cc
+ common/DoutStreambuf.cc
libcrush_a_SOURCES = \
crush/builder.c \
common/Mutex.h\
common/RWLock.h\
common/Semaphore.h\
- common/SyslogStreambuf.h\
+ common/DoutStreambuf.h\
common/Thread.h\
common/Throttle.h\
common/Timer.h\
--- /dev/null
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2010 Dreamhost
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation. See file COPYING.
+ *
+ */
+
+#include "common/DoutStreambuf.h"
+
+#include <assert.h>
+#include <fstream>
+#include <iostream>
+#include <streambuf>
+#include <syslog.h>
+#include <string.h>
+
+template <typename charT, typename traits>
+DoutStreambuf<charT, traits>::DoutStreambuf()
+{
+ // Initialize get pointer to zero so that underflow is called on the first read.
+ this->setg(0, 0, 0);
+
+ // Set up the put pointer.
+ // Overflow is called when this buffer is filled
+ this->setp(obuf, obuf + OBUF_SZ - 2);
+
+ // Zero the output buffer
+ memset(obuf, 0, OBUF_SZ);
+}
+
+// This function is called when the output buffer is filled.
+// In this function, the buffer should be written to wherever it should
+// be written to (in this case, the streambuf object that this is controlling).
+template <typename charT, typename traits>
+typename DoutStreambuf<charT, traits>::int_type
+DoutStreambuf<charT, traits>::overflow(DoutStreambuf<charT, traits>::int_type c)
+{
+ charT* end = this->pptr();
+
+ // Add an eof character to the buffer if we need to.
+ if(!traits_ty::eq_int_type(c, traits_ty::eof())) {
+ *end++ = traits_ty::to_char_type(c);
+ }
+ *end++ = '\0';
+
+ //std::cout << "overflow with '" << obuf << "'" << std::endl;
+
+ // int_type ilen = end - obuf; // Compute the write length.
+ syslog(LOG_USER | LOG_NOTICE, "%s", obuf);
+
+ // Reset put pointers
+ setp(obuf, obuf + OBUF_SZ - 1);
+ obuf[0] = '\0';
+
+ // A value different than EOF (or traits::eof() for other traits) signals success.
+ // If the function fails, either EOF (or traits::eof() for other traits) is returned or an
+ // exception is thrown.
+ return traits_ty::not_eof(c);
+}
+
+// This is called to flush the buffer.
+// This is called when we're done with the file stream (or when .flush() is called).
+template <typename charT, typename traits>
+typename DoutStreambuf<charT, traits>::int_type
+DoutStreambuf<charT, traits>::sync()
+{
+ //std::cout << "flush!" << std::endl;
+
+ // Don't bother calling overflow if there's nothing to syslog
+ if (obuf[0] == '\0')
+ return 0;
+
+ typename DoutStreambuf<charT, traits>::int_type
+ ret(this->overflow(traits_ty::eof()));
+ if (ret == traits_ty::eof())
+ return -1;
+
+ return 0;
+}
+
+template <typename charT, typename traits>
+typename DoutStreambuf<charT, traits>::int_type
+DoutStreambuf<charT, traits>::underflow()
+{
+ // We can't read from this
+ // TODO: some more elegant way of preventing callers from trying to get input from this stream
+ assert(0);
+}
+
+// Explicit template instantiation
+template class DoutStreambuf <char>;
--- /dev/null
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2010 Dreamhost
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation. See file COPYING.
+ *
+ */
+
+/*
+ * DoutStreambuf
+ *
+ * The stream buffer used by dout
+ */
+#ifndef CEPH_DOUT_STREAMBUF_H
+#define CEPH_DOUT_STREAMBUF_H
+
+#include <iosfwd>
+
+template <typename charT, typename traits = std::char_traits<charT> >
+class DoutStreambuf : public std::basic_streambuf<charT, traits>
+{
+public:
+ typedef traits traits_ty;
+ typedef typename traits_ty::int_type int_type;
+ typedef typename traits_ty::pos_type pos_type;
+ typedef typename traits_ty::off_type off_type;
+
+ // The size of the input and output buffers.
+ static const size_t OBUF_SZ = 32000;
+
+ DoutStreambuf();
+
+protected:
+ // Called when the buffer fills up
+ virtual int_type overflow(int_type c);
+
+ // Called when the buffer is flushed
+ virtual int_type sync();
+
+ // Called when we try to read, but there are no more chars in the buffer
+ virtual int_type underflow();
+
+private:
+ // Output buffer
+ charT obuf[OBUF_SZ];
+};
+
+#endif
+++ /dev/null
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
-// vim: ts=8 sw=2 smarttab
-/*
- * Ceph - scalable distributed file system
- *
- * Copyright (C) 2010 Dreamhost
- *
- * This is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1, as published by the Free Software
- * Foundation. See file COPYING.
- *
- */
-
-#include "common/SyslogStreambuf.h"
-
-#include <assert.h>
-#include <fstream>
-#include <iostream>
-#include <streambuf>
-#include <syslog.h>
-#include <string.h>
-
-template <typename charT, typename traits>
-SyslogStreambuf<charT, traits>::SyslogStreambuf()
-{
- // Initialize get pointer to zero so that underflow is called on the first read.
- this->setg(0, 0, 0);
-
- // Set up the put pointer.
- // Overflow is called when this buffer is filled
- this->setp(obuf, obuf + OBUF_SZ - 2);
-
- // Zero the output buffer
- memset(obuf, 0, OBUF_SZ);
-}
-
-// This function is called when the output buffer is filled.
-// In this function, the buffer should be written to wherever it should
-// be written to (in this case, the streambuf object that this is controlling).
-template <typename charT, typename traits>
-typename SyslogStreambuf<charT, traits>::int_type
-SyslogStreambuf<charT, traits>::overflow(SyslogStreambuf<charT, traits>::int_type c)
-{
- charT* end = this->pptr();
-
- // Add an eof character to the buffer if we need to.
- if(!traits_ty::eq_int_type(c, traits_ty::eof())) {
- *end++ = traits_ty::to_char_type(c);
- }
- *end++ = '\0';
-
- //std::cout << "overflow with '" << obuf << "'" << std::endl;
-
- // int_type ilen = end - obuf; // Compute the write length.
- syslog(LOG_USER | LOG_NOTICE, "%s", obuf);
-
- // Reset put pointers
- setp(obuf, obuf + OBUF_SZ - 1);
- obuf[0] = '\0';
-
- // A value different than EOF (or traits::eof() for other traits) signals success.
- // If the function fails, either EOF (or traits::eof() for other traits) is returned or an
- // exception is thrown.
- return traits_ty::not_eof(c);
-}
-
-// This is called to flush the buffer.
-// This is called when we're done with the file stream (or when .flush() is called).
-template <typename charT, typename traits>
-typename SyslogStreambuf<charT, traits>::int_type
-SyslogStreambuf<charT, traits>::sync()
-{
- //std::cout << "flush!" << std::endl;
-
- // Don't bother calling overflow if there's nothing to syslog
- if (obuf[0] == '\0')
- return 0;
-
- typename SyslogStreambuf<charT, traits>::int_type
- ret(this->overflow(traits_ty::eof()));
- if (ret == traits_ty::eof())
- return -1;
-
- return 0;
-}
-
-template <typename charT, typename traits>
-typename SyslogStreambuf<charT, traits>::int_type
-SyslogStreambuf<charT, traits>::underflow()
-{
- // We can't read from this
- // TODO: some more elegant way of preventing callers from trying to get input from this stream
- assert(0);
-}
-
-// Explicit template instantiation
-template class SyslogStreambuf <char>;
+++ /dev/null
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
-// vim: ts=8 sw=2 smarttab
-/*
- * Ceph - scalable distributed file system
- *
- * Copyright (C) 2010 Dreamhost
- *
- * This is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1, as published by the Free Software
- * Foundation. See file COPYING.
- *
- */
-
-/*
- * SyslogStreambuf
- *
- * A stream buffer that writes its output to syslog.
- */
-#ifndef CEPH_SYSLOG_STREAMBUF_H
-#define CEPH_SYSLOG_STREAMBUF_H
-
-#include <iosfwd>
-
-template <typename charT, typename traits = std::char_traits<charT> >
-class SyslogStreambuf : public std::basic_streambuf<charT, traits>
-{
-public:
- typedef traits traits_ty;
- typedef typename traits_ty::int_type int_type;
- typedef typename traits_ty::pos_type pos_type;
- typedef typename traits_ty::off_type off_type;
-
- // The size of the input and output buffers.
- static const size_t OBUF_SZ = 32000;
-
- SyslogStreambuf();
-
-protected:
- // Called when the buffer fills up
- virtual int_type overflow(int_type c);
-
- // Called when the buffer is flushed
- virtual int_type sync();
-
- // Called when we try to read, but there are no more chars in the buffer
- virtual int_type underflow();
-
-private:
- // Output buffer
- charT obuf[OBUF_SZ];
-};
-
-#endif
--- /dev/null
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2010 Dreamhost
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation. See file COPYING.
+ *
+ */
+
+/*
+ * TestDoutStreambuf
+ *
+ * Puts some output into the DoutStreambuf class.
+ * Check your syslog to see what it did.
+ */
+#include "common/DoutStreambuf.h"
+#include "common/common_init.h"
+#include "config.h"
+
+#include <iostream>
+#include <sstream>
+#include <string>
+
+using std::cout;
+using std::cerr;
+using std::string;
+
+int main(int argc, const char **argv)
+{
+ vector<const char*> args;
+ argv_to_vec(argc, argv, args);
+ env_to_vec(args);
+
+ ceph_set_default_id("admin");
+ common_set_defaults(false);
+ common_init(args, "ceph", true);
+
+ std::ostream oss(new DoutStreambuf<char>);
+
+ oss << "I am logging to dout now!" << std::endl;
+
+ oss << "And here is another line!" << std::endl;
+
+ oss.flush();
+
+ oss << "Stuff ";
+ oss << "that ";
+ oss << "will ";
+ oss << "all ";
+ oss << "be ";
+ oss << "on ";
+ oss << "one ";
+ oss << "line.";
+ oss.flush();
+
+ oss << "There will be no blank lines here." << std::endl;
+ oss.flush();
+ oss.flush();
+ oss.flush();
+
+ oss << "But here is a blank line:" << std::endl;
+ oss << std::endl;
+
+ return 0;
+}
+++ /dev/null
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
-// vim: ts=8 sw=2 smarttab
-/*
- * Ceph - scalable distributed file system
- *
- * Copyright (C) 2010 Dreamhost
- *
- * This is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1, as published by the Free Software
- * Foundation. See file COPYING.
- *
- */
-
-/*
- * TestSyslogStreambuf
- *
- * Puts some output into the SyslogStreambuf class.
- * Check your syslog to see what it did.
- */
-#include "common/SyslogStreambuf.h"
-#include "common/common_init.h"
-#include "config.h"
-
-#include <iostream>
-#include <sstream>
-#include <string>
-
-using std::cout;
-using std::cerr;
-using std::string;
-
-int main(int argc, const char **argv)
-{
- vector<const char*> args;
- argv_to_vec(argc, argv, args);
- env_to_vec(args);
-
- ceph_set_default_id("admin");
- common_set_defaults(false);
- common_init(args, "ceph", true);
-
- std::ostream oss(new SyslogStreambuf<char>);
-
- oss << "I am logging to syslog now!" << std::endl;
-
- oss << "And here is another line!" << std::endl;
-
- oss.flush();
-
- oss << "Stuff ";
- oss << "that ";
- oss << "will ";
- oss << "all ";
- oss << "be ";
- oss << "on ";
- oss << "one ";
- oss << "line.";
- oss.flush();
-
- oss << "There will be no blank lines here." << std::endl;
- oss.flush();
- oss.flush();
- oss.flush();
-
- oss << "But here is a blank line:" << std::endl;
- oss << std::endl;
-
- return 0;
-}