2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
20#include "core/socket/stream/SocketConnection.h"
22#include "core/socket/stream/SocketContext.h"
23#include "core/socket/stream/SocketContextFactory.h"
25#ifndef DOXYGEN_SHOULD_SKIP_THIS
27#include "log/Logger.h"
31namespace core::socket::
stream {
43 this->newSocketContext = newSocketContext;
47 if (socketContext !=
nullptr) {
48 LOG(DEBUG) << connectionName <<
": Connecting SocketContext";
49 this->socketContext = socketContext;
50 socketContext->onConnected();
52 LOG(ERROR) << connectionName <<
": Connecting SocketContext failed: no new SocketContext";
57 sendToPeer(data.data(), data.size());
61 sendToPeer(
reinterpret_cast<
const char*>(data.data()), data.size());
65 sendToPeer(data.data(), data.size());
73 return connectionName;
77 return configuredServer;
80 void SocketConnection::connectSocketContext(
const std::shared_ptr<SocketContextFactory>& socketContextFactory) {
81 SocketContext* socketContext = socketContextFactory->create(
this);
83 if (socketContext !=
nullptr) {
84 LOG(DEBUG) << connectionName <<
": Creating SocketContext successful";
85 setSocketContext(socketContext);
87 LOG(ERROR) << connectionName <<
": Failed creating SocketContext";
93 if (socketContext !=
nullptr) {
94 socketContext->onDisconnected();
97 LOG(DEBUG) << connectionName <<
": SocketContext disconnected";
const std::string & getConfiguredServer() const
virtual ~SocketConnection()
void disconnectCurrentSocketContext()
void sentToPeer(const std::vector< uint8_t > &data)
const std::string & getConnectionName() const
void sendToPeer(const std::string &data)
SocketConnection(const std::string &instanceName, int fd, const std::string &configuredServer)
const std::string & getInstanceName() const