//  Beta release only.
//
//  Copyright(c) Ivyware Pty Ltd 2006-9  (all rights reserved)
//               MELBOURNE, VICTORIA, AUSTRALIA, 3130
//
//  Implementation for the Microsoft Ws2_32.dll library extensions
//
#include "StdAfx.h"
#include "WSA_Ext.h"

///////////////////////////////////////////////////////////////////////
//  Safe SOCKET implementation
//  NOTES: SOCKET is managed within the life cycle of this object.
//
SafeSOCKET::SafeSOCKET ( )
{   
    m_oSocket = INVALID_SOCKET;
}
SafeSOCKET::SafeSOCKET ( SOCKET oSocket )
{
    m_oSocket = oSocket;
}
SafeSOCKET::~SafeSOCKET ( )
{   
    if ( m_oSocket != INVALID_SOCKET )
      closesocket ( m_oSocket );
}
SafeSOCKET&
SafeSOCKET::operator = ( SOCKET oSocket )
{
    if ( m_oSocket != oSocket        &&
         m_oSocket != INVALID_SOCKET    )
      closesocket ( m_oSocket );
    m_oSocket = oSocket;
    return *this;
}
SafeSOCKET::operator SOCKET ( )
{   
    return m_oSocket;
}
SOCKET
SafeSOCKET::Dereference()
{   
    SOCKET oSocket = m_oSocket;
    m_oSocket = INVALID_SOCKET;
    return oSocket;
}

///////////////////////////////////////////////////////////////////////
//  WSA extensions

CString
WSA_GetHostName ( )
{
    TCHAR szHostName[MAX_PATH];
    if ( gethostname(szHostName,sizeof(szHostName)) )
      return _T("Error");
    return szHostName;
}
