1
0
forked from 0ad/0ad

Updates for PCH Compat, and other misc. revisions

This was SVN commit r623.
This commit is contained in:
Simon Brenner 2004-07-04 15:41:17 +00:00
parent baa374ae13
commit 6559b5c8a6
9 changed files with 47 additions and 9 deletions

View File

@ -111,6 +111,11 @@ START_NMT_CLASS_(ServerHandshakeResponse)
NMT_FIELD(CStr, m_Message)
END_NMT_CLASS()
START_NMT_CLASS_(Result)
NMT_FIELD_INT(m_Code, u32, 4)
NMT_FIELD(CStr, m_Message)
END_NMT_CLASS()
START_NMT_CLASS_(Authenticate)
NMT_FIELD(CStr, m_Nick)
//NMT_FIELD(CPasswordHash, m_Password)
@ -129,7 +134,7 @@ START_NMT_CLASS_(PlayerConnect)
NMT_END_ARRAY()
END_NMT_CLASS()
#include "../EventTypes.h"
// #include "../EventTypes.h"
END_NMTS()

View File

@ -103,7 +103,7 @@ uint _nm::GetSerializedLength() const \
const _nm *thiz=this;
#define NMT_START_ARRAY(_nm) \
vector <ARRAY_STRUCT_PREFIX##_nm>::const_iterator it=_nm.begin(); \
std::vector <ARRAY_STRUCT_PREFIX##_nm>::const_iterator it=_nm.begin(); \
while (it != _nm.end()) \
{ \
const ARRAY_STRUCT_PREFIX##_nm *thiz=&*it;
@ -141,7 +141,7 @@ u8 *_nm::Serialize(u8 *buffer) const \
const _nm *thiz=this;
#define NMT_START_ARRAY(_nm) \
vector <ARRAY_STRUCT_PREFIX##_nm>::const_iterator it=_nm.begin(); \
std::vector <ARRAY_STRUCT_PREFIX##_nm>::const_iterator it=_nm.begin(); \
while (it != _nm.end()) \
{ \
const ARRAY_STRUCT_PREFIX##_nm *thiz=&*it;

View File

@ -1,6 +1,7 @@
#include "precompiled.h"
#include "posix.h"
#include "lib.h"
#include "misc.h"
#include <stdio.h>
#define ALLNETMSGS_IMPLEMENT

View File

@ -1,3 +1,5 @@
#include "precompiled.h"
#include "Network.h"
#include "Serialization.h"
#include <errno.h>

View File

@ -12,8 +12,6 @@
#define closesocket(_fd) close(_fd)
#else
#include "sysdep/win/win_internal.h"
#define Network_GetErrorString(_error, _buf, _buflen) \
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, _error+WSABASEERR, 0, _buf, _buflen, NULL)
#define Network_LastError (WSAGetLastError() - WSABASEERR)
@ -74,7 +72,7 @@ struct CSocketSetInternal
pthread_mutex_t m_Mutex;
pthread_t m_Thread;
std::map <socket_t, CSocketBase *> m_HandleMap;
std::map <socket_t, CSocketBase * > m_HandleMap;
#ifdef _WIN32
HWND m_hWnd;
#else

View File

@ -1,3 +1,5 @@
#include "precompiled.h"
#include "Network.h"
CServerSocket::~CServerSocket()

View File

@ -1,3 +1,6 @@
#include "precompiled.h"
#include "sysdep/win/win_internal.h"
#include "Network.h"
#include "NetworkInternal.h"
@ -57,6 +60,25 @@ CSocketAddress::CSocketAddress(int port, ESocketProtocol proto)
}
}
CSocketAddress CSocketAddress::Loopback(int port, ESocketProtocol proto)
{
CSocketAddress ret;
switch (proto)
{
case IPv4:
ret.m_Union.m_IPv4.sin_family=PF_INET;
ret.m_Union.m_IPv4.sin_addr.s_addr=htonl(INADDR_LOOPBACK);
ret.m_Union.m_IPv4.sin_port=htons(port);
break;
case IPv6:
ret.m_Union.m_IPv6.sin6_family=PF_INET6;
memcpy(&ret.m_Union.m_IPv6.sin6_addr, &in6addr_loopback, sizeof(in6addr_loopback));
ret.m_Union.m_IPv6.sin6_port=htons(port);
break;
}
return ret;
}
PS_RESULT CSocketAddress::Resolve(const char *name, int port, CSocketAddress &addr)
{
if ((getaddrinfo) != NULL)
@ -681,10 +703,10 @@ void WaitLoop_SocketUpdateProc(int fd, int error, uint event)
if (error)
{
PS_RESULT res=GetPS_RESULT(error);
if (res == PS_FAIL)
pSock->OnClose(CONNECTION_BROKEN);
pSock->m_Error=res;
pSock->m_State=SS_UNCONNECTED;
if (res == PS_FAIL)
pSock->OnClose(CONNECTION_BROKEN);
return;
}

View File

@ -126,6 +126,12 @@ struct CSocketAddress
* Returns the port number part of the address
*/
int GetPort() const;
/*
Create an address pointing to the loopback, with the specified port and
protocol. Use this with Bind to only listen on the loopback interface.
*/
static CSocketAddress Loopback(int port, ESocketProtocol proto=IPv4);
};
/**

View File

@ -1,3 +1,5 @@
#include "precompiled.h"
#include "Network.h"
#include "StreamSocket.h"