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
18 changes: 9 additions & 9 deletions src/Socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int Socket::GetLastError()
#endif
}

// inits socket
// inits socket(windows)
Socket::Socket()
{
#ifdef WIN32
Expand Down Expand Up @@ -84,7 +84,7 @@ void Socket::Bind(const char* iNode, const char* iPort)
m_Sockfd = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
if (m_Sockfd == INVALID_SOCKET)
{
spdlog::error("socket failed");
spdlog::error("socket failed. Error: {}", GetLastError());
freeaddrinfo(result);
WSACleanup_();
exit(1);
Expand All @@ -94,7 +94,7 @@ void Socket::Bind(const char* iNode, const char* iPort)
iResult = bind(m_Sockfd, result->ai_addr, (int)result->ai_addrlen);
if (iResult == SOCKET_ERROR)
{
spdlog::error("bind failed");
spdlog::error("bind failed. Error: {}", GetLastError());
freeaddrinfo(result);
WSACleanup_();
exit(1);
Expand All @@ -112,7 +112,7 @@ void Socket::Listen(int backlog)
iResult = listen(m_Sockfd, backlog);
if (iResult != 0)
{
spdlog::error("listen failed");
spdlog::error("listen failed. Error: {}", GetLastError());
closesocket_(m_Sockfd);
WSACleanup_();
exit(1);
Expand All @@ -125,7 +125,7 @@ Socket Socket::Accept()
clientSocket = accept(m_Sockfd, NULL, NULL);
if (clientSocket == INVALID_SOCKET)
{
spdlog::error("accept failed: {}, {}");
spdlog::error("accept failed. Error: {}", GetLastError());
closesocket_(m_Sockfd);
WSACleanup_();
exit(1);
Expand All @@ -151,7 +151,7 @@ std::string Socket::Recv(int bytesToRecv)
else
{
// failed
spdlog::error("recv failed");
spdlog::error("recv failed. Error: {}", GetLastError());
closesocket_(m_Sockfd);
WSACleanup_();
exit(1);
Expand All @@ -165,10 +165,10 @@ void Socket::Send(const std::string& sendString)
int iResult;

iResult = send(m_Sockfd, sendString.c_str(), sendString.length(), 0);
spdlog::info("Bytes send: {}", iResult);
spdlog::info("Bytes sent: {}", iResult);
if (iResult == SOCKET_ERROR)
{
spdlog::error("send failed");
spdlog::error("send failed. Error: {}", GetLastError());
closesocket_(m_Sockfd);
WSACleanup_();
exit(1);
Expand All @@ -187,7 +187,7 @@ void Socket::Shutdown()
iResult = shutdown(m_Sockfd, 1);
if (iResult == SOCKET_ERROR)
{
spdlog::error("shutdown failed");
spdlog::error("shutdown failed. Error: {}", GetLastError());
closesocket_(m_Sockfd);
WSACleanup_();
exit(1);
Expand Down
1 change: 1 addition & 0 deletions src/Socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ using socket_t = SOCKET;
#include <netdb.h>
#include <cstring>
#include <unistd.h>
#include <errno.h>

using socket_t = int;
constexpr int INVALID_SOCKET = -1;
Expand Down