tweaks to make work
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
|
||||
#include "TcpClient.hpp"
|
||||
|
||||
#include <arpa/inet.h>
|
||||
|
||||
TcpClient::TcpClient(ConfigService* config, LoggerService* logger) : TcpBase(logger) {
|
||||
|
||||
if(!(config->getConfig<ClientConfig>("TcpClient", "main", &configuration_))) {
|
||||
@@ -33,7 +35,7 @@ ErrorCode TcpClient::init() {
|
||||
// parse the hostname string into uint8s
|
||||
host = gethostbyname(configuration_.hostname.c_str());
|
||||
if(host == NULL) {
|
||||
logger_->log("TcpClient", LogFlag::Debug, "Unable to parse hostname.");
|
||||
logger_->log("TcpClient", LogFlag::Error, "Unable to parse hostname.");
|
||||
close(socketFd_); // TODO: probably on a destructor
|
||||
return ErrorCode::Error;
|
||||
}
|
||||
@@ -41,7 +43,7 @@ ErrorCode TcpClient::init() {
|
||||
// create tcp socket
|
||||
socketFd_ = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if(socketFd_ < 0) {
|
||||
logger_->log("TcpClient", LogFlag::Debug, "Unable to open client socket.");
|
||||
logger_->log("TcpClient", LogFlag::Error, "Unable to open client socket.");
|
||||
close(socketFd_);
|
||||
return ErrorCode::Error;
|
||||
}
|
||||
@@ -52,9 +54,13 @@ ErrorCode TcpClient::init() {
|
||||
serverAddress.sin_port = htons(configuration_.port);
|
||||
serverAddress.sin_addr = *((struct in_addr*)host->h_addr);
|
||||
|
||||
char ip[INET_ADDRSTRLEN];
|
||||
inet_ntop(AF_INET, host->h_addr_list[0], ip, sizeof(ip));
|
||||
logger_->log("TcpClient", LogFlag::Error, "Connecting to {}:{}", ip, configuration_.port);
|
||||
|
||||
// connect to server
|
||||
if(connect(socketFd_, (struct sockaddr*)&serverAddress, sizeof(struct sockaddr)) < 0) {
|
||||
logger_->log("TcpClient", LogFlag::Debug, "Unable to connect to server.");
|
||||
logger_->log("TcpClient", LogFlag::Error, "Unable to connect to server.");
|
||||
close(socketFd_);
|
||||
return ErrorCode::Error;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include <filesystem>
|
||||
#include <algorithm>
|
||||
#include <cstdarg>
|
||||
#include <cerrno>
|
||||
#include <cstring>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
@@ -79,7 +81,7 @@ void LoggerService::write(std::string component, LogFlag flag, std::string messa
|
||||
|
||||
std::string componentTrace = "[" + configuration_.id + ": " + component + "] ";
|
||||
finalmessage += componentTrace; // component is the section of the program (For example Mesh or Engine) that is calling the logger
|
||||
|
||||
|
||||
std::string level = "";
|
||||
|
||||
level = LogFlagStrings[flag];
|
||||
@@ -87,6 +89,9 @@ void LoggerService::write(std::string component, LogFlag flag, std::string messa
|
||||
// level.append(7 - level.length(), ' ') pads out the level string with whitespace so every line is aligned the sam
|
||||
finalmessage = finalmessage + "[" + level + "] ";
|
||||
finalmessage = finalmessage + message + " ";
|
||||
if(flag == LogFlag::Error) {
|
||||
finalmessage += std::format("[errno = {} ({})]", errno, std::strerror(errno));
|
||||
}
|
||||
|
||||
/* Removed because didn't want to bother with variadics + default arguments
|
||||
if (configuration_.showSourceTrace) {
|
||||
|
||||
Reference in New Issue
Block a user