Skip to content

Commit

Permalink
Merge pull request #1472 from dgelessus/dont_include_winsock_everywhere
Browse files Browse the repository at this point in the history
Include Winsock header only where it's actually used
  • Loading branch information
Hoikas authored Aug 19, 2023
2 parents 02d7a11 + 7b1bee4 commit d3092a1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
5 changes: 2 additions & 3 deletions Sources/Plasma/CoreLib/hsWindows.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ You can contact Cyan Worlds, Inc. by email [email protected]
/** \file hsWindows.h
* \brief Pulls in Windows core headers
*
* This file pulls in the core Windows headers and Winsock2. It is separate from
* HeadSpin.h to improve build times and to facillitate adding precompiled headers.
* This file pulls in the core Windows headers. It is separate from HeadSpin.h
* to improve build times and to facilitate adding precompiled headers.
* You should avoid including this header from other headers!
*/

Expand All @@ -75,7 +75,6 @@ You can contact Cyan Worlds, Inc. by email [email protected]

# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# include <ws2tcpip.h> // Pulls in WinSock 2 for us

// This needs to be after #include <windows.h>, since it also includes windows.h
# ifdef USE_VLD
Expand Down
9 changes: 2 additions & 7 deletions Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ You can contact Cyan Worlds, Inc. by email [email protected]
#include "plNetAddress.h"
#include "pnNetCommon.h"

#ifndef AF_INET
# define AF_INET 2
#endif

ST::string plNetAddress::GetHostString() const
{
return pnNetCommon::GetTextAddr(fHost);
Expand Down Expand Up @@ -95,7 +91,7 @@ void plNetAddress::Read(hsStream * s)
fHost = s->ReadLE32();
fPort = s->ReadLE16();

// Family is always AF_INET
// Family is always kInet
(void) s->ReadLE16();
}

Expand All @@ -104,6 +100,5 @@ void plNetAddress::Write(hsStream * s)
s->WriteLE32(fHost);
s->WriteLE16(fPort);

// Family is always AF_INET
s->WriteLE16((uint16_t)AF_INET);
s->WriteLE16(static_cast<uint16_t>(Family::kInet));
}
6 changes: 6 additions & 0 deletions Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ You can contact Cyan Worlds, Inc. by email [email protected]
*/
class plNetAddress
{
// This is used in the Read/Write format and so must not use the potentially OS-dependent AF_* constants.
enum class Family : uint16_t
{
kInet = 2, // matches AF_INET from Winsock <ws2def.h>
};

uint32_t fHost;
uint16_t fPort;

Expand Down
8 changes: 5 additions & 3 deletions Sources/Plasma/NucleusLib/pnNetCommon/pnNetCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@ You can contact Cyan Worlds, Inc. by email [email protected]
*==LICENSE==*/
#include <string>
#include "pnNetCommon.h"
#include "hsWindows.h"

#if HS_BUILD_FOR_UNIX
#if defined(HS_BUILD_FOR_UNIX)
# include <sys/socket.h>
# include <netinet/in.h>
# include <arpa/inet.h>
# include <netdb.h>
#elif !defined(HS_BUILD_FOR_WIN32)
#elif defined(HS_BUILD_FOR_WIN32)
#include "hsWindows.h"
#include <ws2tcpip.h>
#else
#error "Not implemented for this platform"
#endif

Expand Down

0 comments on commit d3092a1

Please sign in to comment.