Fixed Xbox implementation
This commit is contained in:
@@ -19,6 +19,14 @@
|
|||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !defined(SOCKET_ERROR)
|
||||||
|
#define SOCKET_ERROR -1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(INVALID_SOCKET)
|
||||||
|
#define INVALID_SOCKET -1
|
||||||
|
#endif
|
||||||
|
|
||||||
EzSockets::EzSockets()
|
EzSockets::EzSockets()
|
||||||
{
|
{
|
||||||
MAXCON = 5;
|
MAXCON = 5;
|
||||||
@@ -28,7 +36,7 @@ EzSockets::EzSockets()
|
|||||||
WSAStartup( MAKEWORD(1,1), &wsda );
|
WSAStartup( MAKEWORD(1,1), &wsda );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
sock = -1;
|
sock = INVALID_SOCKET;
|
||||||
blocking = true;
|
blocking = true;
|
||||||
scks = new fd_set;
|
scks = new fd_set;
|
||||||
times = new timeval;
|
times = new timeval;
|
||||||
@@ -47,7 +55,7 @@ EzSockets::~EzSockets()
|
|||||||
//Check to see if the socket has been created
|
//Check to see if the socket has been created
|
||||||
bool EzSockets::check()
|
bool EzSockets::check()
|
||||||
{
|
{
|
||||||
return sock > 0;
|
return sock != INVALID_SOCKET;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EzSockets::create()
|
bool EzSockets::create()
|
||||||
@@ -81,7 +89,7 @@ bool EzSockets::create(int Protocol, int Type)
|
|||||||
state = skDISCONNECTED;
|
state = skDISCONNECTED;
|
||||||
sock = socket(AF_INET, Type, Protocol);
|
sock = socket(AF_INET, Type, Protocol);
|
||||||
lastCode = sock;
|
lastCode = sock;
|
||||||
return sock > 0;
|
return sock != INVALID_SOCKET;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -100,7 +108,7 @@ bool EzSockets::bind(unsigned short port)
|
|||||||
bool EzSockets::listen()
|
bool EzSockets::listen()
|
||||||
{
|
{
|
||||||
lastCode = ::listen(sock, MAXCON);
|
lastCode = ::listen(sock, MAXCON);
|
||||||
if (lastCode)
|
if (lastCode == SOCKET_ERROR)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
state = skLISTENING;
|
state = skLISTENING;
|
||||||
@@ -134,7 +142,7 @@ bool EzSockets::accept(EzSockets& socket)
|
|||||||
|
|
||||||
lastCode = socket.sock;
|
lastCode = socket.sock;
|
||||||
|
|
||||||
if (socket.sock <= 0)
|
if (socket.sock == INVALID_SOCKET)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
socket.state = skCONNECTED;
|
socket.state = skCONNECTED;
|
||||||
@@ -166,9 +174,24 @@ bool EzSockets::connect(const std::string& host, unsigned short port)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
#if defined(_XBOX)
|
#if defined(_XBOX)
|
||||||
// FIXME: Xbox doesn't have gethostbyname or any way to get a hostent.
|
if(!isdigit(host[0])) // don't do a DNS lookup for an IP address
|
||||||
// Investigate the samples and figure out how this is supposed to work.
|
{
|
||||||
|
XNDNS *pxndns = NULL;
|
||||||
|
XNetDnsLookup(host.c_str(), NULL, &pxndns);
|
||||||
|
while (pxndns->iStatus == WSAEINPROGRESS)
|
||||||
|
{
|
||||||
|
// Do something else while lookup is in progress
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pxndns->iStatus == 0)
|
||||||
|
memcpy(&addr.sin_addr, &pxndns->aina[0], sizeof(struct in_addr));
|
||||||
|
else
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
XNetDnsRelease(pxndns);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
addr.sin_addr.s_addr = inet_addr(host.c_str());
|
||||||
#else
|
#else
|
||||||
struct hostent* phe;
|
struct hostent* phe;
|
||||||
phe = gethostbyname(host.c_str());
|
phe = gethostbyname(host.c_str());
|
||||||
@@ -179,7 +202,7 @@ bool EzSockets::connect(const std::string& host, unsigned short port)
|
|||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
addr.sin_port = htons(port);
|
addr.sin_port = htons(port);
|
||||||
|
|
||||||
if(::connect(sock, (struct sockaddr*)&addr, sizeof(addr)))
|
if(::connect(sock, (struct sockaddr*)&addr, sizeof(addr)) == SOCKET_ERROR)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
state = skCONNECTED;
|
state = skCONNECTED;
|
||||||
|
|||||||
Reference in New Issue
Block a user