mirror of https://github.com/libp2p/cpp-libp2p.git
Browse Source
* Counting bytes in tcp read write * Bytes counter moved to separate class because of clang tidy * Delete moves for ByteCounter for clang tidy * Copyright headers for ByteCounter * Default destructor for ByteCounter specified for clang tidypull/271/head
Boris
1 month ago
committed by
GitHub
5 changed files with 87 additions and 1 deletions
@ -0,0 +1,40 @@ |
|||||
|
/**
|
||||
|
* Copyright Quadrivium LLC |
||||
|
* All Rights Reserved |
||||
|
* SPDX-License-Identifier: Apache-2.0 |
||||
|
*/ |
||||
|
|
||||
|
#pragma once |
||||
|
|
||||
|
#include <atomic> |
||||
|
|
||||
|
namespace libp2p::transport { |
||||
|
|
||||
|
class ByteCounter { |
||||
|
private: |
||||
|
std::atomic<uint64_t> bytes_read_{0}; |
||||
|
std::atomic<uint64_t> bytes_written_{0}; |
||||
|
|
||||
|
ByteCounter() = default; |
||||
|
|
||||
|
public: |
||||
|
~ByteCounter() = default; |
||||
|
|
||||
|
void incrementBytesRead(uint64_t bytes); |
||||
|
|
||||
|
void incrementBytesWritten(uint64_t bytes); |
||||
|
|
||||
|
uint64_t getBytesRead() const; |
||||
|
|
||||
|
uint64_t getBytesWritten() const; |
||||
|
|
||||
|
static ByteCounter &getInstance(); |
||||
|
|
||||
|
ByteCounter(const ByteCounter &) = delete; |
||||
|
ByteCounter &operator=(const ByteCounter &) = delete; |
||||
|
|
||||
|
ByteCounter(ByteCounter &&) = delete; |
||||
|
ByteCounter &operator=(ByteCounter &&) = delete; |
||||
|
}; |
||||
|
|
||||
|
} // namespace libp2p::transport
|
@ -0,0 +1,32 @@ |
|||||
|
/**
|
||||
|
* Copyright Quadrivium LLC |
||||
|
* All Rights Reserved |
||||
|
* SPDX-License-Identifier: Apache-2.0 |
||||
|
*/ |
||||
|
|
||||
|
#include <libp2p/transport/tcp/bytes_counter.hpp> |
||||
|
|
||||
|
namespace libp2p::transport { |
||||
|
|
||||
|
ByteCounter &ByteCounter::getInstance() { |
||||
|
static ByteCounter instance; |
||||
|
return instance; |
||||
|
} |
||||
|
|
||||
|
void ByteCounter::incrementBytesRead(uint64_t bytes) { |
||||
|
bytes_read_.fetch_add(bytes); |
||||
|
} |
||||
|
|
||||
|
void ByteCounter::incrementBytesWritten(uint64_t bytes) { |
||||
|
bytes_written_.fetch_add(bytes); |
||||
|
} |
||||
|
|
||||
|
uint64_t ByteCounter::getBytesRead() const { |
||||
|
return bytes_read_.load(); |
||||
|
} |
||||
|
|
||||
|
uint64_t ByteCounter::getBytesWritten() const { |
||||
|
return bytes_written_.load(); |
||||
|
} |
||||
|
|
||||
|
} // namespace libp2p::transport
|
Loading…
Reference in new issue