#include "blitz/network/Network.h"

#include "blitz/misc/Log.h"
#include <signal.h>


namespace blitz {
namespace network {

/* Catch Signal Handler function */
void signal_callback_handler(int signum) {
	utils::LOGD("[Network] Caught a SIGPIPE !");
}

#ifdef _WIN32
NetworkInitializer::NetworkInitializer() {
	WSADATA wsaData;
	if (WSAStartup(MAKEWORD(2, 2), &wsaData) < 0) {
		utils::LOGE("[Network] Failed to initialize network !");
	} else {
		utils::LOG("[Network] Network initialized !");
	}
}
NetworkInitializer::~NetworkInitializer() {
	WSACleanup();
}
#else
NetworkInitializer::NetworkInitializer() {
	/* Prevents the game for crashing when socket closes on the other side */
	signal(SIGPIPE, signal_callback_handler);
}
NetworkInitializer::~NetworkInitializer() {}
#endif

}  // namespace network
}  // namespace blitz
