/*! 
* 
* Copyright(c) 2009 Apogee Instruments, Inc. 
* \class UdpSocketWin 
* \brief Windows platform implemenation of the UdpSocketBase class for a upd socket that finds apogee devices on a subnet 
* 
*/ 

// removes warnings about vectors
#pragma warning(disable: 4786)

#include "UdpSocketWin.h" 
#include <sstream>
#include <string>

//////////////////////////// 
// CTOR 
UdpSocketWin::UdpSocketWin()
{ 
	// Try to start the Windows sockets library
    int result = WSAStartup(MAKEWORD(1, 0), &m_WinSockData);
	if( result )
	{
        std::stringstream ss;
        ss << result;
		
        std::string errMsg = "WSAStartup failed with error " + ss.str();
        throw std::runtime_error( errMsg );
	}

}

//////////////////////////// 
// DTOR 
UdpSocketWin::~UdpSocketWin() 
{ 
    WSACleanup();
} 


//////////////////////////// 
// CLOSE    SOCKET 
void UdpSocketWin::CloseSocket()
{
    closesocket( m_SocketDescriptor );
    m_SocketDescriptor = INVALID_SOCKET;
} 
