Skip to content

Commit

Permalink
Massive refactor to start using new "pools" concept.
Browse files Browse the repository at this point in the history
  • Loading branch information
ibd1279 committed Oct 11, 2014
1 parent 5ab131b commit aefd12f
Show file tree
Hide file tree
Showing 62 changed files with 2,619 additions and 2,763 deletions.
2 changes: 1 addition & 1 deletion sample1.cfg
@@ -1,6 +1,6 @@
{
'server': {
'listen':12345,
'listen':'localhost@12345',
'identity': {
'method': { '__bson_type': 'UUID', '__bson_value': '{7af8ce1e-88e4-5392-a07a-977966f927e9}' },
'provider': { '__bson_type': 'UUID', '__bson_value': '{64fee549-1666-5c4f-a81b-9e2704aaebfe}' },
Expand Down
9 changes: 2 additions & 7 deletions src/lj/Log.cpp
Expand Up @@ -204,16 +204,11 @@ namespace lj
delete this;
}

Logger_cout::Logger_cout(const std::string lvl,
Logger_clog::Logger_clog(const std::string lvl,
const std::string& fmt) :
Logger_stream(lvl, fmt, &(std::cout))
Logger_stream(lvl, fmt, &(std::clog))
{
}

Logger_cout::~Logger_cout()
{
}

}; // namespace log
}; // namespace lj

28 changes: 23 additions & 5 deletions src/lj/Log.h
Expand Up @@ -39,6 +39,7 @@
#include <cstdint>
#include <exception>
#include <list>
#include <map>
#include <sstream>
#include <string>

Expand Down Expand Up @@ -389,6 +390,23 @@ namespace lj
*/
inline Logger& operator<<(const std::exception& ex) { return write_string(ex.what()); };

//! Log a map
/*!
\param m The map.
\tparam K the key type
\tparam V the value type.
\return The current Log.
*/
template <class K, class V>
inline Logger& operator<<(const std::map<K, V> m)
{
for (const typename std::map<K, V>::value_type& item : m)
{
(*this) << "[" << item.first << "=" << item.second << "]";
}
return *this;
}

//! Close the logger.
/*!
\param msg The message to write to the output.
Expand Down Expand Up @@ -454,18 +472,18 @@ namespace lj
};

//! Logger that outputs to cout.
class Logger_cout : public Logger_stream
class Logger_clog : public Logger_stream
{
public:
//! Constructor.
/*!
\param lvl The logging level string.
\param fmt The logging format string.
*/
Logger_cout(const std::string lvl,
Logger_clog(const std::string lvl,
const std::string& fmt);
//! Destructor.
virtual ~Logger_cout();
virtual ~Logger_clog() = default;
};

//! Check or set the enabled flags for a level.
Expand Down Expand Up @@ -521,7 +539,7 @@ namespace lj
\par
This functions tests the Logging level to see if it is enabled.
and a new logger object is created based on that result. At the moment,
it is hard coded to always used the lj::log::Logger_cout.
it is hard coded to always used the lj::log::Logger_clog.
\todo The logger type should be able to be driven by some form of
configuration.
\param fmt The format of the log message.
Expand All @@ -534,7 +552,7 @@ namespace lj
if (enabled_flag<Level>())
{
Level lvl;
return *(new Logger_cout(lvl.name(), fmt));
return *(new Logger_clog(lvl.name(), fmt));
}
else
{
Expand Down
53 changes: 39 additions & 14 deletions src/lj/Streambuf_bsd.h
Expand Up @@ -69,7 +69,7 @@ namespace lj
/*!
\param data The socket descriptor.
*/
Socket(int data) : fd(data)
explicit Socket(int data) : fd_(data)
{
}

Expand All @@ -84,9 +84,9 @@ namespace lj
\param len Maximum number of bytes to write.
\return The number of bytes actually written.
*/
int write(const uint8_t* ptr, size_t len)
virtual int write(const uint8_t* ptr, size_t len)
{
return ::send(fd, ptr, len, 0);
return ::send(fd_, ptr, len, 0);
}

//! Read data from the socket.
Expand All @@ -95,21 +95,21 @@ namespace lj
\param len Maximum number of bytes to read.
\return The number of bytes actually read.
*/
int read(uint8_t* ptr, size_t len)
virtual int read(uint8_t* ptr, size_t len)
{
return ::recv(fd, ptr, len, 0);
return ::recv(fd_, ptr, len, 0);
}

//! Convert the last error into a string and return.
/*!
\return String representation of the error.
*/
std::string error()
virtual std::string error()
{
return ::strerror(errno);
}
private:
int fd;
protected:
int fd_;
};
}; // namespace lj::medium

Expand Down Expand Up @@ -158,20 +158,22 @@ namespace lj

//! Create a new streambuf object around a BSD socket.
/*!
\par
\par Buffer Size
Buffer size is measured in terms of the character type associated with
the stream buffer (e.g. char, wchar, etc.). It is not the number of
bytes associated with the buffer.
\par
\par lj::medium Object
The \c Streambuf_bsd object assumes responsibility for releasing the
\c medium object. It is stored in a std::unique_ptr.
\c medium object. It is stored in a \c std::unique_ptr.
\param medium Pointer to the underlying medium.
\param in_sz The size of the read buffer.
\param out_sz The size of the writer buffer.
*/
Streambuf_bsd(mediumT* medium, const size_t in_sz, const size_t out_sz) :
Streambuf_bsd(std::unique_ptr<mediumT>&& medium,
const size_t in_sz,
const size_t out_sz) :
Streambuf_mutex<charT, traits>(),
medium_(medium),
medium_(std::move(medium)),
in_size_(in_sz),
out_size_(out_sz)
{
Expand All @@ -189,6 +191,29 @@ namespace lj
in_buffer_[0] = 0;
out_buffer_[0] = 0;
}

//! Create a new streambuf object around a BSD socket.
/*!
\par Buffer Size
Buffer size is measured in terms of the character type associated with
the stream buffer (e.g. char, wchar, etc.). It is not the number of
bytes associated with the buffer.
\par lj::medium Object
The \c Streambuf_bsd object assumes responsibility for releasing the
\c medium object. It is stored in a \c std::unique_ptr.
\param medium Pointer to the underlying medium.
\param in_sz The size of the read buffer.
\param out_sz The size of the writer buffer.
*/
Streambuf_bsd(mediumT* medium,
const size_t in_sz,
const size_t out_sz) :
Streambuf_bsd(std::unique_ptr<mediumT>(medium),
in_sz,
out_sz)
{
}


//! Clean up our resources.
virtual ~Streambuf_bsd()
Expand Down Expand Up @@ -475,4 +500,4 @@ namespace lj
uint8_t in_buffer_[sizeof(charT)]; //!< buffer for any left over bytes. first byte is the number of bytes buffered.
uint8_t out_buffer_[sizeof(charT)]; //!< buffer for any left over bytes. first byte is the number of bytes buffered.
}; // class lj::Streambuf_bsd
}; // namespace lj
}; // namespace lj
11 changes: 6 additions & 5 deletions src/logjam/Client_socket.cpp
Expand Up @@ -35,6 +35,7 @@

#include "logjam/Client_socket.h"
#include "logjam/Network_address_info.h"
#include "logjam/Network_socket.h"
#include "logjam/Tls_credentials.h"
#include "logjam/Tls_session.h"
#include "lj/Bson.h"
Expand All @@ -48,7 +49,7 @@ namespace
class iostream_secure : public std::iostream
{
public:
iostream_secure(logjam::Network_connection&& conn,
iostream_secure(logjam::Network_socket&& conn,
logjam::Tls_session<credT>* sess,
lj::Streambuf_bsd<logjam::Tls_session<credT>>* buf) :
std::iostream(buf),
Expand All @@ -64,7 +65,7 @@ namespace
delete buffer_;
}
private:
logjam::Network_connection connection_;
logjam::Network_socket connection_;
logjam::Tls_session<credT>* session_;
lj::Streambuf_bsd<logjam::Tls_session<credT>>* buffer_;
};
Expand Down Expand Up @@ -110,12 +111,12 @@ namespace logjam
SOCK_STREAM,
0);

logjam::Network_connection connection;
logjam::Network_socket connection;
while (info.next() && !connection.is_open())
{
try
{
connection.connect(info.current());
connection = logjam::socket_for_target(info.current());
}
catch (lj::Exception ex)
{
Expand Down Expand Up @@ -197,4 +198,4 @@ namespace logjam
return sec_io;
}
}; // namespace logjam::client
}; // namespace logjam
}; // namespace logjam
5 changes: 2 additions & 3 deletions src/logjam/Client_socket.h
Expand Up @@ -34,7 +34,6 @@
POSSIBILITY OF SUCH DAMAGE.
*/

#include "logjam/Network_connection.h"
#include "lj/Bson.h"
#include <iostream>

Expand All @@ -50,7 +49,7 @@ namespace logjam

//! Create a connection object.
/*!
Creates a fully connected Network_connection (BSD socket) to the target.
Creates a fully connected Network_socket (BSD socket) to the target.
If the target resolves as several network addresses, each name is
tried.
\todo This does not currently support any of the TLS authentication
Expand All @@ -64,4 +63,4 @@ namespace logjam
const std::string& target_mode);

};
};
};

0 comments on commit aefd12f

Please sign in to comment.