Skip to content

Commit

Permalink
std::chrono: Use instead of boost::chrono
Browse files Browse the repository at this point in the history
  • Loading branch information
rawler committed Oct 8, 2017
1 parent a2c089d commit c8f4d2d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
3 changes: 2 additions & 1 deletion lib/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <boost/assert.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/lexical_cast.hpp>
#include <chrono>
#include <functional>
#include <iostream>
#include <memory>
Expand Down Expand Up @@ -470,7 +471,7 @@ void Client::onMessage( const std::shared_ptr< MessageContext< HandShakeConfirme
void Client::onMessage( const std::shared_ptr< MessageContext< Ping > >& msgCtx ) {
if (msgCtx->message().timeout()) {
bithorde::Ping reply;
auto deadline = boost::chrono::steady_clock::now() + boost::chrono::milliseconds(msgCtx->message().timeout());
auto deadline = std::chrono::steady_clock::now() + std::chrono::milliseconds(msgCtx->message().timeout());
sendMessage(Connection::MessageType::Ping, reply, deadline, false);
}
}
Expand Down
5 changes: 2 additions & 3 deletions lib/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const size_t SEND_BUF_LOW_WATER_MARK = SEND_BUF/4;
const size_t SEND_CHUNK_MS = 50;

namespace asio = boost::asio;
namespace chrono = boost::chrono;
using namespace std;

using namespace bithorde;
Expand Down Expand Up @@ -166,7 +165,7 @@ class ConnectionImpl : public Connection {
Message::Deadline Message::NEVER(Message::Deadline::max());
Message::Deadline Message::in(int msec)
{
return Clock::now()+chrono::milliseconds(msec);
return Clock::now() + std::chrono::milliseconds(msec);
}

Message::Message(Deadline expires) :
Expand All @@ -193,7 +192,7 @@ MessageQueue::MessageList MessageQueue::dequeue(size_t bytes_per_sec, ushort mil
{
bytes_per_sec = std::max(bytes_per_sec, 1*K);
int32_t wanted(std::max(((bytes_per_sec*millis)/1000), static_cast<size_t>(1)));
auto now = chrono::steady_clock::now();
auto now = std::chrono::steady_clock::now();
MessageList res;
res.reserve(_size);
while ((wanted > 0) && !_queue.empty()) {
Expand Down
6 changes: 3 additions & 3 deletions lib/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include <boost/asio/io_service.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/local/stream_protocol.hpp>
#include <boost/chrono/system_clocks.hpp>
#include <boost/signals2.hpp>
#include <chrono>
#include <functional>
#include <memory>
#include <list>
Expand All @@ -21,14 +21,14 @@ namespace bithorde {
class Keepalive;

struct Message {
typedef boost::chrono::steady_clock Clock;
typedef std::chrono::steady_clock Clock;
typedef Clock::time_point Deadline;
static Deadline NEVER;
static Deadline in(int msec);

Message(Deadline expires);
std::string buf; // TODO: test if ostringstream faster
boost::chrono::steady_clock::time_point expires;
std::chrono::steady_clock::time_point expires;
};

class MessageQueue {
Expand Down
5 changes: 3 additions & 2 deletions tests/test_message_queue.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <chrono>
#include <vector>

#include <boost/test/unit_test.hpp>
Expand All @@ -13,13 +14,13 @@ BOOST_AUTO_TEST_CASE( message_queue )
BOOST_ASSERT( mq.empty() );
BOOST_CHECK_EQUAL( mq.size(), 0 );

auto now = boost::chrono::steady_clock::now();
auto now = std::chrono::steady_clock::now();
for (auto i = 0; i < 32; i++ ) {
std::shared_ptr<bithorde::Message> msg(new bithorde::Message(now));
msg->buf.insert(0, 1024, 'X');
mq.enqueue(msg);
}
auto later = now + boost::chrono::seconds(15);
auto later = now + std::chrono::seconds(15);
for (auto i = 0; i < 32; i++ ) {
std::shared_ptr<bithorde::Message> msg(new bithorde::Message(later));
msg->buf.insert(0, 1024, 'X');
Expand Down

0 comments on commit c8f4d2d

Please sign in to comment.