Revision 132
changed the Log class a little and made it conform to coding style slightly better
ColonetServer.cpp | ||
---|---|---|
74 | 74 |
*/ |
75 | 75 |
int ColonetServer::start_listening() { |
76 | 76 |
if (listen(listen_socket, LISTEN_BACKLOG) < 0) { |
77 |
log_error("\t\nThere was an error telling the socket to " |
|
77 |
logger.log_error("\t\nThere was an error telling the socket to "
|
|
78 | 78 |
"listen for connections from clients. Terminating Server...\n"); |
79 | 79 |
return -1; |
80 | 80 |
} |
81 | 81 |
return 0; |
82 | 82 |
} |
83 | 83 |
|
84 |
/** |
|
85 |
* @brief Logs an error message to the log file |
|
86 |
*/ |
|
87 |
int ColonetServer::log_error(char * error_message) { |
|
88 |
return logger.logMessage(LOG_TYPE_ERROR, error_message); |
|
89 |
} |
|
90 | 84 |
|
91 | 85 |
/** |
92 |
* @brief Logs a message to the log file |
|
93 |
*/ |
|
94 |
int ColonetServer::log_message(char * message) { |
|
95 |
return logger.logMessage(LOG_TYPE_MESSAGE, message); |
|
96 |
} |
|
97 |
|
|
98 |
/** |
|
99 | 86 |
* @brief Starts the server running (starts an infinite loop) |
100 | 87 |
*/ |
101 | 88 |
int ColonetServer::run_server() { |
... | ... | |
109 | 96 |
struct sockaddr_in client_addr; |
110 | 97 |
socklen_t client_addr_size = sizeof(client_addr); |
111 | 98 |
|
112 |
log_message("Server initialized. About to start listening for connections"); |
|
99 |
logger.log_message("Server initialized. About to start listening for connections");
|
|
113 | 100 |
|
114 | 101 |
while(1) { |
115 | 102 |
connection_pool.perform_select(listen_socket); |
... | ... | |
136 | 123 |
char log_buffer[LOG_BUFFER_LENGTH]; |
137 | 124 |
snprintf(log_buffer, LOG_BUFFER_LENGTH, "Client at address %s attempting to connect.", |
138 | 125 |
inet_ntoa(client_addr.sin_addr)); |
139 |
logger.logMessage(LOG_TYPE_CONNECT, log_buffer);
|
|
126 |
logger.log_string(LOG_TYPE_CONNECT, log_buffer);
|
|
140 | 127 |
|
141 | 128 |
if (connection_pool.add_client(accept_socket) < 0) { |
142 | 129 |
printf("\tThere was an error when trying to add a client to the connection pool."); |
... | ... | |
145 | 132 |
|
146 | 133 |
snprintf(log_buffer, LOG_BUFFER_LENGTH, "Client at address %s successfully added to connection pool.", |
147 | 134 |
inet_ntoa(client_addr.sin_addr)); |
148 |
logger.logMessage(LOG_TYPE_CONNECT, log_buffer);
|
|
135 |
logger.log_string(LOG_TYPE_CONNECT, log_buffer);
|
|
149 | 136 |
} |
150 | 137 |
|
151 | 138 |
if (connection_pool.check_clients() < 0) { |
... | ... | |
257 | 244 |
connection_pool = colonet_server.get_connection_pool_pointer(); |
258 | 245 |
|
259 | 246 |
if (colonet_server.initialize_server(argc, argv) < 0) { |
260 |
colonet_server.log_error("\t\nThere was an error initializing the server. "
|
|
247 |
printf("\t\nThere was an error initializing the server. "
|
|
261 | 248 |
"Terminating server...\n"); |
262 | 249 |
return -1; |
263 | 250 |
} |
Also available in: Unified diff