From 4055d85d9965aa25d1f71fe5b59bd7f3651dbaff Mon Sep 17 00:00:00 2001 From: mdiluzio Date: Sat, 3 Jan 2015 22:30:52 +0000 Subject: [PATCH] Use new fatal_error and fatal_perror functions for errors --- source/client/client.cpp | 18 +++++++++--------- source/client/net.cpp | 4 ++-- source/client/net.h | 9 ++++++++- source/client/server.cpp | 12 ++++++------ 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/source/client/client.cpp b/source/client/client.cpp index 2776971..1184678 100644 --- a/source/client/client.cpp +++ b/source/client/client.cpp @@ -48,14 +48,14 @@ int runClient(int argc, char* argv[]) // 0 is for default protocol sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd < 0) - error("ERROR opening socket"); + fatal_perror("ERROR opening socket"); std::cout<<"Opened socket on "< &myClients, const CTTRTSGame { // Write to the socket with the buffer if ( write( client.clientsockfd, gamestate_string.c_str(), gamestate_string.length() ) < 0 ) - error("ERROR sending to client"); + fatal_perror("ERROR sending to client"); } } diff --git a/source/client/net.h b/source/client/net.h index af8b64e..5ac3f55 100644 --- a/source/client/net.h +++ b/source/client/net.h @@ -14,6 +14,7 @@ #include #include +#include #define TTRTS_HANDSHAKE_FORMAT "player %u name %s" @@ -31,7 +32,13 @@ void GetOrdersFromClients(std::vector &myClients, CTTRTSGame &game, void SendGameInfoToClients(std::vector &myClients, const CTTRTSGame &game, std::mutex &gameMutex); -inline void error(const char *msg) +inline void fatal_error(const char *msg) +{ + std::cerr< 10) { - error("Binding failed after retries"); + fatal_error("Binding failed after retries"); } if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) >= 0) @@ -93,7 +93,7 @@ int runServer(int argc, char* argv[]) // client information will be stored in cli_addr clientsockfd = accept(sockfd, (sockaddr *) &cli_addr, &clilen); if (clientsockfd < 0) - error("ERROR on accept"); + fatal_perror("ERROR on accept"); std::cout<<"Client connected from "<