From 82d8f904faf6e21da86ee44aea55b254bafdd544 Mon Sep 17 00:00:00 2001 From: anulax1225 Date: Mon, 18 Mar 2024 18:17:27 +0100 Subject: [PATCH] Replaced log macro with offical baka logging system --- bakanet/src/bakanetpch.h | 1 + bakanet/src/platform/linux/linux_socket.cpp | 7 ++++--- bakanet/src/platform/linux/linux_socket.h | 1 + bakanet/src/platform/windows/windows_socket.cpp | 8 ++++---- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/bakanet/src/bakanetpch.h b/bakanet/src/bakanetpch.h index 0f34610..bb961f3 100755 --- a/bakanet/src/bakanetpch.h +++ b/bakanet/src/bakanetpch.h @@ -18,6 +18,7 @@ #include #pragma comment(lib,"WS2_32.lib") #elif defined(BK_PLATFORM_LINUX) + #include #include #include #include diff --git a/bakanet/src/platform/linux/linux_socket.cpp b/bakanet/src/platform/linux/linux_socket.cpp index 803a0f0..91de320 100755 --- a/bakanet/src/platform/linux/linux_socket.cpp +++ b/bakanet/src/platform/linux/linux_socket.cpp @@ -17,7 +17,7 @@ namespace Bk::Net { //LinuxSocket creation step if ((id = socket((int)ip_addr.version, (int)ip_proto, 0)) < 0) { - perror("socket failed"); + BK_CORE_TRACE("Socket failed : {0}", strerror(errno)); exit(EXIT_FAILURE); } addr.sin_addr = ip_addr.get_data(); @@ -36,7 +36,7 @@ namespace Bk::Net { int status; if ((status = bind(id, (struct sockaddr*)&addr, sizeof(addr)) < 0)) { - perror("bind failed"); + BK_CORE_TRACE("Binding failed : {0}", strerror(errno)); return false; } return true; @@ -47,6 +47,7 @@ namespace Bk::Net { //Listening step if (listen(id, cpt_conn) < 0) { + BK_CORE_TRACE("Listening failed : {0}", strerror(errno)); return false; } return true; @@ -54,7 +55,6 @@ namespace Bk::Net { std::unique_ptr LinuxSocket::ack() { - socklen_t addrlen = sizeof(addr); return std::unique_ptr(Socket::create(accept(id, (struct sockaddr*)&addr, &addrlen), ip_addr.version, ip_proto)); } @@ -63,6 +63,7 @@ namespace Bk::Net { { if (connect(id, (struct sockaddr*)&addr, sizeof(addr)) < 0) { + BK_CORE_TRACE("Connection failed : {0}", strerror(errno)); return false; } return true; diff --git a/bakanet/src/platform/linux/linux_socket.h b/bakanet/src/platform/linux/linux_socket.h index f8533c9..c20c1f4 100755 --- a/bakanet/src/platform/linux/linux_socket.h +++ b/bakanet/src/platform/linux/linux_socket.h @@ -1,5 +1,6 @@ #pragma once +#include #include namespace Bk::Net { diff --git a/bakanet/src/platform/windows/windows_socket.cpp b/bakanet/src/platform/windows/windows_socket.cpp index 5269db5..f454e11 100755 --- a/bakanet/src/platform/windows/windows_socket.cpp +++ b/bakanet/src/platform/windows/windows_socket.cpp @@ -24,7 +24,7 @@ namespace Bk::Net { err = WSAStartup(MAKEWORD(2, 2), &wsa_data); if (err != 0) { - log("WSA failed " << WSAGetLastError()); + BK_CORE_TRACE("WSA failed : {0}", WSAGetLastError()); WSACleanup(); exit(EXIT_FAILURE); } @@ -33,7 +33,7 @@ namespace Bk::Net { //WindowsSocket creation step if ((id = (int)socket((int)ip_addr.version, (int)ip_proto, 0)) < 0) { - log("socket failed " << WSAGetLastError()); + BK_CORE_TRACE("Socket failed : {0}", WSAGetLastError()); exit(EXIT_FAILURE); } addr.sin_addr = ip_addr.get_data(); @@ -53,7 +53,7 @@ namespace Bk::Net { int status; if ((status = bind((SOCKET)id, (struct sockaddr*)&addr, sizeof(addr)) < 0)) { - log("bind failed " << WSAGetLastError()); + BK_CORE_TRACE("Binding failed : {0}", WSAGetLastError()); return false; } return true; @@ -62,7 +62,7 @@ namespace Bk::Net { bool WindowsSocket::start(int cpt_conn = SOMAXCONN) { //Listening step - if (listen(id, cpt_conn) == SOCKET_ERROR) { return false; } + if (listen(id, cpt_conn) == SOCKET_ERROR) { BK_CORE_TRACE("Listening failed : {0}", WSAGetLastError()); return false; } return true; }