Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions ClientContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "KeyboardReader.h" // for KeyboardReader

#include <functional> // for function
#include <log/Logger.h>
#include <SemanticLog.h>
#include <string>

ClientContext::ClientContext(core::socket::stream::SocketConnection* socketConnection)
Expand Down Expand Up @@ -37,7 +37,10 @@ std::size_t ClientContext::onReceivedFromPeer() {

std::size_t numBytesRead = readFromPeer(buffer, 1024);

VLOG(0) << "Buffer: " << std::string(buffer, numBytesRead);
auto log = snode::semantic::appLog();
if (log.enabled(logger::LogLevel::Trace)) {
log.trace() << "Buffer: " << std::string(buffer, numBytesRead);
}

return numBytesRead;
}
Expand Down
26 changes: 14 additions & 12 deletions client.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "ClientContext.h" // IWYU pragma: keep
#include "log/Logger.h"
#include <SemanticLog.h>

#include <core/SNodeC.h>
#include <net/in/stream/tls/SocketClient.h>
Expand All @@ -13,20 +13,21 @@ int main(int argc, char* argv[]) {

Client client(
[](SocketConnection* socketConnection) -> void {
VLOG(0) << "OnConnect from: " << socketConnection->getRemoteAddress().toString();
snode::semantic::appLog().debug() << "OnConnect from: " << socketConnection->getRemoteAddress().toString();
},
[](SocketConnection* socketConnection) -> void {
VLOG(0) << "OnConnected from: " << socketConnection->getRemoteAddress().toString();
snode::semantic::appLog().debug() << "OnConnected from: " << socketConnection->getRemoteAddress().toString();
},
[](SocketConnection* socketConnection) -> void {
VLOG(0) << "OnDisconnect from: " << socketConnection->getRemoteAddress().toString();
snode::semantic::appLog().debug() << "OnDisconnect from: " << socketConnection->getRemoteAddress().toString();
});

client.connect("/tmp/testsocket", [](const Client::SocketAddress& socketAddress, int errnum) -> void {
if (errnum == 0) {
VLOG(0) << "Client connected to " << socketAddress.toString();
snode::semantic::appLog().info() << "Client connected to " << socketAddress.toString();
} else {
VLOG(0) << "Error: Client trying to connect to " << socketAddress.toString() << " : errno = " << errnum;
snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errnum)
<< "Client failed to connect to " << socketAddress.toString();
}
});

Expand All @@ -35,13 +36,13 @@ int main(int argc, char* argv[]) {

ClientTLS clienttls(
[](SocketConnectionTLS* socketConnection) -> void {
VLOG(0) << "OnConnect from: " << socketConnection->getRemoteAddress().toString();
snode::semantic::appLog().debug() << "OnConnect from: " << socketConnection->getRemoteAddress().toString();
},
[](SocketConnectionTLS* socketConnection) -> void {
VLOG(0) << "OnConnected from: " << socketConnection->getRemoteAddress().toString();
snode::semantic::appLog().debug() << "OnConnected from: " << socketConnection->getRemoteAddress().toString();
},
[](SocketConnectionTLS* socketConnection) -> void {
VLOG(0) << "OnDisconnect from: " << socketConnection->getRemoteAddress().toString();
snode::semantic::appLog().debug() << "OnDisconnect from: " << socketConnection->getRemoteAddress().toString();
});

clienttls.getConfig()
Expand All @@ -52,11 +53,12 @@ int main(int argc, char* argv[]) {

clienttls.connect("localhost", 8082, [](const ClientTLS::SocketAddress& socketAddress, int errnum) -> void {
if (errnum < 0) {
PLOG(ERROR) << "OnError";
snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errnum) << "OnError";
} else if (errnum > 0) {
PLOG(ERROR) << "OnError: " << socketAddress.toString();
snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errnum)
<< "OnError: " << socketAddress.toString();
} else {
VLOG(0) << "snode.c connecting to " << socketAddress.toString();
snode::semantic::appLog().info() << "snode.c connecting to " << socketAddress.toString();
}
});

Expand Down
60 changes: 35 additions & 25 deletions server.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "ServerContext.h" // IWYU pragma: keep
#include "log/Logger.h"
#include <SemanticLog.h>

#include <core/SNodeC.h>
#include <net/in/stream/legacy/SocketServer.h>
Expand All @@ -15,22 +15,23 @@ int main(int argc, char* argv[]) {

Server server(
[](SocketConnection* socketConnection) -> void {
VLOG(0) << "OnConnect from: " << socketConnection->getRemoteAddress().toString();
snode::semantic::appLog().debug() << "OnConnect from: " << socketConnection->getRemoteAddress().toString();
},
[](SocketConnection* socketConnection) -> void {
VLOG(0) << "OnConnected from: " << socketConnection->getRemoteAddress().toString();
snode::semantic::appLog().debug() << "OnConnected from: " << socketConnection->getRemoteAddress().toString();
},
[](SocketConnection* socketConnection) -> void {
VLOG(0) << "OnDisconnect from: " << socketConnection->getRemoteAddress().toString();
snode::semantic::appLog().debug() << "OnDisconnect from: " << socketConnection->getRemoteAddress().toString();
});

server.listen(8080, 5, [](const Server::SocketAddress& socketAddress, int errnum) -> void {
if (errnum < 0) {
PLOG(ERROR) << "OnError";
snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errnum) << "OnError";
} else if (errnum > 0) {
PLOG(ERROR) << "OnError: " << socketAddress.toString();
snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errnum)
<< "OnError: " << socketAddress.toString();
} else {
VLOG(0) << "snode.c listening on " << socketAddress.toString();
snode::semantic::appLog().info() << "snode.c listening on " << socketAddress.toString();
}
});

Expand All @@ -39,13 +40,13 @@ int main(int argc, char* argv[]) {

ServerTLS servertls(
[](SocketConnectionTLS* socketConnection) -> void {
VLOG(0) << "OnConnect from: " << socketConnection->getRemoteAddress().toString();
snode::semantic::appLog().debug() << "OnConnect from: " << socketConnection->getRemoteAddress().toString();
},
[](SocketConnectionTLS* socketConnection) -> void {
VLOG(0) << "OnConnected from: " << socketConnection->getRemoteAddress().toString();
snode::semantic::appLog().debug() << "OnConnected from: " << socketConnection->getRemoteAddress().toString();
},
[](SocketConnectionTLS* socketConnection) -> void {
VLOG(0) << "OnDisconnect from: " << socketConnection->getRemoteAddress().toString();
snode::semantic::appLog().debug() << "OnDisconnect from: " << socketConnection->getRemoteAddress().toString();
});

servertls.getConfig()
Expand All @@ -56,11 +57,12 @@ int main(int argc, char* argv[]) {

servertls.listen(8082, 5, [](const ServerTLS::SocketAddress& socketAddress, int errnum) -> void {
if (errnum < 0) {
PLOG(ERROR) << "OnError";
snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errnum) << "OnError";
} else if (errnum > 0) {
PLOG(ERROR) << "OnError: " << socketAddress.toString();
snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errnum)
<< "OnError: " << socketAddress.toString();
} else {
VLOG(0) << "snode.c listening on " << socketAddress.toString();
snode::semantic::appLog().info() << "snode.c listening on " << socketAddress.toString();
}
});

Expand All @@ -69,22 +71,26 @@ int main(int argc, char* argv[]) {

Server6 server6(
[](SocketConnection6* socketConnection) -> void {
VLOG(0) << "OnConnect from: " << socketConnection->getRemoteAddress().toString();
snode::semantic::appLog().debug() << "OnConnect from: " << socketConnection->getRemoteAddress().toString();
},
[](SocketConnection6* socketConnection) -> void {
VLOG(0) << "OnConnected from: " << socketConnection->getRemoteAddress().toString();
snode::semantic::appLog().debug() << "OnConnected from: " << socketConnection->getRemoteAddress().toString();
},
[](SocketConnection6* socketConnection) -> void {
VLOG(0) << "OnDisconnect from: " << socketConnection->getRemoteAddress().toString();
snode::semantic::appLog().debug() << "OnDisconnect from: " << socketConnection->getRemoteAddress().toString();
});

server6.listen(8081, 5, [](const Server6::SocketAddress& socketAddress, core::socket::State errnum) -> void {
if (errnum < 0) {
PLOG(ERROR) << "OnError";
snode::semantic::sysError(
snode::semantic::appLog(), logger::LogLevel::Error, static_cast<int>(errnum))
<< "OnError";
} else if (errnum > 0) {
PLOG(ERROR) << "OnError: " << socketAddress.toString();
snode::semantic::sysError(
snode::semantic::appLog(), logger::LogLevel::Error, static_cast<int>(errnum))
<< "OnError: " << socketAddress.toString();
} else {
VLOG(0) << "snode.c listening on " << socketAddress.toString();
snode::semantic::appLog().info() << "snode.c listening on " << socketAddress.toString();
}
});

Expand All @@ -93,22 +99,26 @@ int main(int argc, char* argv[]) {

ServerUn serverUn(
[](SocketConnectionUn* socketConnection) -> void {
VLOG(0) << "OnConnect from: " << socketConnection->getRemoteAddress().toString();
snode::semantic::appLog().debug() << "OnConnect from: " << socketConnection->getRemoteAddress().toString();
},
[](SocketConnectionUn* socketConnection) -> void {
VLOG(0) << "OnConnected from: " << socketConnection->getRemoteAddress().toString();
snode::semantic::appLog().debug() << "OnConnected from: " << socketConnection->getRemoteAddress().toString();
},
[](SocketConnectionUn* socketConnection) -> void {
VLOG(0) << "OnDisconnect from: " << socketConnection->getRemoteAddress().toString();
snode::semantic::appLog().debug() << "OnDisconnect from: " << socketConnection->getRemoteAddress().toString();
});

serverUn.listen("/tmp/testsocket", 5, [](const ServerUn::SocketAddress& socketAddress, core::socket::State errnum) -> void {
if (errnum < 0) {
PLOG(ERROR) << "OnError";
snode::semantic::sysError(
snode::semantic::appLog(), logger::LogLevel::Error, static_cast<int>(errnum))
<< "OnError";
} else if (errnum > 0) {
PLOG(ERROR) << "OnError: " << socketAddress.toString();
snode::semantic::sysError(
snode::semantic::appLog(), logger::LogLevel::Error, static_cast<int>(errnum))
<< "OnError: " << socketAddress.toString();
} else {
VLOG(0) << "snode.c listening on " << socketAddress.toString();
snode::semantic::appLog().info() << "snode.c listening on " << socketAddress.toString();
}
});

Expand Down