2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
42#include "core/socket/stream/SocketConnection.h"
44#include "core/socket/stream/SocketContext.h"
45#include "core/socket/stream/SocketContextFactory.h"
46#include "net/config/ConfigInstance.h"
48#ifndef DOXYGEN_SHOULD_SKIP_THIS
50#include "log/Logger.h"
60namespace core::socket::
stream {
75 if (socketContext !=
nullptr) {
76 LOG(DEBUG) <<
connectionName <<
": SocketContext created successful";
79 LOG(ERROR) <<
connectionName <<
": SocketContext failed to create";
131 const std::time_t time = std::chrono::system_clock::to_time_t(timePoint);
132 std::tm* tm_ptr = std::gmtime(&time);
135 std::string onlineSince =
"Formatting error";
138 if (std::strftime(buffer,
sizeof(buffer),
"%Y-%m-%d %H:%M:%S", tm_ptr) > 0) {
139 onlineSince = std::string(buffer) +
" UTC";
146 const std::chrono::time_point<std::chrono::system_clock>& later) {
147 using seconds_duration_type = std::chrono::duration<std::chrono::seconds::rep>::rep;
149 const seconds_duration_type totalSeconds = std::chrono::duration_cast<std::chrono::seconds>(later - bevore).count();
152 const seconds_duration_type days = totalSeconds / 86400;
153 seconds_duration_type remainder = totalSeconds % 86400;
154 const seconds_duration_type hours = remainder / 3600;
155 remainder = remainder % 3600;
156 const seconds_duration_type minutes = remainder / 60;
157 const seconds_duration_type seconds = remainder % 60;
160 std::ostringstream oss;
162 oss << days <<
" day" << (days == 1 ?
"" :
"s") <<
", ";
164 oss << std::setw(2) << std::setfill(
'0') << hours <<
":" << std::setw(2) << std::setfill(
'0') << minutes <<
":" << std::setw(2)
165 << std::setfill(
'0') << seconds;
std::string connectionName
virtual void sendToPeer(const char *chunk, std::size_t chunkLen)=0
SocketConnection(int fd, const net::config::ConfigInstance *config)
core::socket::stream::SocketContext * socketContext
static std::string timePointToString(const std::chrono::time_point< std::chrono::system_clock > &timePoint)
virtual ~SocketConnection()
void sentToPeer(const std::vector< char > &data)
void sentToPeer(const std::vector< uint8_t > &data)
void setSocketContext(const std::shared_ptr< SocketContextFactory > &socketContextFactory)
static std::string durationToString(const std::chrono::time_point< std::chrono::system_clock > &bevore, const std::chrono::time_point< std::chrono::system_clock > &later=std::chrono::system_clock::now())
const std::string & getConnectionName() const
void setSocketContext(SocketContext *socketContext)
void sendToPeer(const std::string &data)
std::string getOnlineSince() const
std::string getOnlineDuration() const
SocketContext * getSocketContext() const
std::chrono::time_point< std::chrono::system_clock > onlineSinceTimePoint
const net::config::ConfigInstance * getConfig() const
const std::string & getInstanceName() const
virtual core::socket::stream::SocketContext * create(core::socket::stream::SocketConnection *socketConnection)=0
const std::string & getInstanceName() const