/* Blinker
   Copyright 2011-2019 Stefan Schuermans <stefan@blinkenarea.org>
   Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html
   a blinkenarea.org project */

#include <winsock2.h>

#include <iostream>
#include <stdlib.h>

#include "PlatformInit.h"

namespace Blinker {

/**
 * @brief constructor
 */
PlatformInit::PlatformInit()
{
  WORD wVersionRequested = MAKEWORD(2, 2);
  WSADATA wsaData;
  int err = WSAStartup(wVersionRequested, &wsaData);
  if (err != 0) {
    std::cerr << "WSAStartup((2, 2), ...) failed" << std::endl;
    exit(1);
  }
  if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2) {
    WSACleanup();
    std::cerr << "WSAStartup((2, 2), ...) returned ("
              << (WORD)LOBYTE(wsaData.wVersion) << ", "
              << (WORD)HIBYTE(wsaData.wVersion) << ")" << std::endl;
    exit(1);
  }
}

/**
 * @brief destructor
 */
PlatformInit::~PlatformInit()
{
  WSACleanup();
}

} // namespace Blinker

