add ps4 support
This commit is contained in:
@@ -9,15 +9,22 @@ SOCKET WinsockNetLayer::s_listenSocket = INVALID_SOCKET;
|
||||
SOCKET WinsockNetLayer::s_hostConnectionSocket = INVALID_SOCKET;
|
||||
SOCKET WinsockNetLayer::s_advertiseSock = INVALID_SOCKET;
|
||||
SOCKET WinsockNetLayer::s_discoverySock = INVALID_SOCKET;
|
||||
#elif defined __PS3__
|
||||
#elif defined __PS3__ || defined __ORBIS__
|
||||
SOCKET WinsockNetLayer::s_listenSocket = -1;
|
||||
SOCKET WinsockNetLayer::s_hostConnectionSocket = -1;
|
||||
SOCKET WinsockNetLayer::s_advertiseSock = -1;
|
||||
SOCKET WinsockNetLayer::s_discoverySock = -1;
|
||||
|
||||
#if defined __PS3__
|
||||
int closesocket(int s) { return socketclose(s); };
|
||||
void terminate_networking() { cellNetCtlTerm(); sys_net_finalize_network(); };
|
||||
#elif defined __ORBIS__
|
||||
int closesocket(int s) { return sceNetSocketClose(s); };
|
||||
int socketclose(int s) { return sceNetSocketClose(s); };
|
||||
void terminate_networking() {};
|
||||
void WSACleanup() {};
|
||||
#endif
|
||||
#endif
|
||||
|
||||
C4JThread* WinsockNetLayer::s_acceptThread = NULL;
|
||||
C4JThread* WinsockNetLayer::s_clientRecvThread = NULL;
|
||||
@@ -118,7 +125,7 @@ void WinsockNetLayer::Shutdown()
|
||||
closesocket(s_hostConnectionSocket);
|
||||
s_hostConnectionSocket = INVALID_SOCKET;
|
||||
}
|
||||
#elif defined __PS3__
|
||||
#elif defined __PS3__ || defined __ORBIS__
|
||||
if (s_listenSocket >= 0)
|
||||
{
|
||||
socketclose(s_listenSocket);
|
||||
@@ -139,7 +146,7 @@ void WinsockNetLayer::Shutdown()
|
||||
s_connections[i].active = false;
|
||||
#if defined _WINDOWS64 || defined _XBOX
|
||||
if (s_connections[i].tcpSocket != INVALID_SOCKET)
|
||||
#elif defined __PS3__
|
||||
#elif defined __PS3__ || defined __ORBIS__
|
||||
if (s_connections[i].tcpSocket >= 0)
|
||||
#endif
|
||||
{
|
||||
@@ -231,7 +238,7 @@ bool WinsockNetLayer::HostGame(int port)
|
||||
app.DebugPrintf("socket() failed: %d\n", WSAGetLastError());
|
||||
return false;
|
||||
}
|
||||
#elif defined __PS3__
|
||||
#elif defined __PS3__ || defined __ORBIS__
|
||||
struct sockaddr_in addr = {};
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
@@ -285,7 +292,7 @@ bool WinsockNetLayer::HostGame(int port)
|
||||
s_listenSocket = INVALID_SOCKET;
|
||||
return false;
|
||||
}
|
||||
#elif defined __PS3__
|
||||
#elif defined __PS3__ || defined __ORBIS__
|
||||
iResult = ::bind(s_listenSocket, (struct sockaddr*)&addr, sizeof(addr));
|
||||
if (iResult < 0)
|
||||
{
|
||||
@@ -539,7 +546,7 @@ bool WinsockNetLayer::JoinGame(const char *ip, int port)
|
||||
connected = true;
|
||||
break;
|
||||
}
|
||||
#elif defined __PS3__
|
||||
#elif defined __PS3__ || defined __ORBIS__
|
||||
if (s_hostConnectionSocket != -1)
|
||||
{
|
||||
socketclose(s_hostConnectionSocket);
|
||||
@@ -551,12 +558,20 @@ bool WinsockNetLayer::JoinGame(const char *ip, int port)
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons((uint16_t)port);
|
||||
|
||||
#if defined(__PS3__)
|
||||
addr.sin_addr.s_addr = inet_addr(ip);
|
||||
if (addr.sin_addr.s_addr == INADDR_NONE)
|
||||
{
|
||||
app.DebugPrintf("inet_addr failed for %s:%d\n", ip, port);
|
||||
return false;
|
||||
}
|
||||
#elif defined(__ORBIS__)
|
||||
if (sceNetInetPton(SCE_NET_AF_INET, ip, &addr.sin_addr.s_addr) <= 0)
|
||||
{
|
||||
app.DebugPrintf("inet_addr failed for %s:%d\n", ip, port);
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool connected = false;
|
||||
BYTE assignedSmallId = 0;
|
||||
@@ -575,14 +590,24 @@ bool WinsockNetLayer::JoinGame(const char *ip, int port)
|
||||
setsockopt(s_hostConnectionSocket, IPPROTO_TCP, TCP_NODELAY, (const char *)&noDelay, sizeof(noDelay));
|
||||
|
||||
int nonBlocking = 1;
|
||||
#ifdef __PS3__
|
||||
setsockopt(s_hostConnectionSocket, SOL_SOCKET, SO_NBIO, &nonBlocking, sizeof(nonBlocking));
|
||||
#elif defined(__ORBIS__)
|
||||
setsockopt(s_hostConnectionSocket, SOL_SOCKET, SCE_NET_SO_NBIO, &nonBlocking, sizeof(nonBlocking));
|
||||
#endif
|
||||
|
||||
iResult = connect(s_hostConnectionSocket, (struct sockaddr*)&addr, sizeof(addr));
|
||||
if (iResult < 0)
|
||||
{
|
||||
#if defined(__PS3__)
|
||||
int err = sys_net_errno;
|
||||
if (err == SYS_NET_EINPROGRESS)
|
||||
{
|
||||
#elif defined(__ORBIS__)
|
||||
int err = sce_net_errno;
|
||||
if (err == SCE_NET_EINPROGRESS)
|
||||
{
|
||||
#endif
|
||||
fd_set writeFds, exceptFds;
|
||||
FD_ZERO(&writeFds);
|
||||
FD_ZERO(&exceptFds);
|
||||
@@ -593,7 +618,11 @@ bool WinsockNetLayer::JoinGame(const char *ip, int port)
|
||||
tv.tv_sec = connectTimeoutMs / 1000;
|
||||
tv.tv_usec = (connectTimeoutMs % 1000) * 1000;
|
||||
|
||||
#if defined(__PS3__)
|
||||
int selectResult = socketselect(s_hostConnectionSocket + 1, NULL, &writeFds, &exceptFds, &tv);
|
||||
#elif defined(__ORBIS__)
|
||||
int selectResult = select(s_hostConnectionSocket + 1, NULL, &writeFds, &exceptFds, &tv);
|
||||
#endif
|
||||
if (selectResult <= 0 || FD_ISSET(s_hostConnectionSocket, &exceptFds))
|
||||
{
|
||||
app.DebugPrintf("connect() to %s:%d timed out or failed (attempt %d/%d)\n", ip, port, attempt + 1, maxAttempts);
|
||||
@@ -623,7 +652,11 @@ bool WinsockNetLayer::JoinGame(const char *ip, int port)
|
||||
}
|
||||
|
||||
int blocking = 0;
|
||||
#ifdef __PS3__
|
||||
setsockopt(s_hostConnectionSocket, SOL_SOCKET, SO_NBIO, &blocking, sizeof(blocking));
|
||||
#elif defined(__ORBIS__)
|
||||
setsockopt(s_hostConnectionSocket, SOL_SOCKET, SCE_NET_SO_NBIO, &blocking, sizeof(blocking));
|
||||
#endif
|
||||
|
||||
DWORD recvTimeout = 3000;
|
||||
setsockopt(s_hostConnectionSocket, SOL_SOCKET, SO_RCVTIMEO, (const char *)&recvTimeout, sizeof(recvTimeout));
|
||||
@@ -675,7 +708,7 @@ bool WinsockNetLayer::SendOnSocket(SOCKET sock, const void *data, int dataSize)
|
||||
{
|
||||
#if defined _WINDOWS64 || defined _XBOX
|
||||
if (sock == INVALID_SOCKET || dataSize <= 0) return false;
|
||||
#elif defined __PS3__
|
||||
#elif defined __PS3__ || defined __ORBIS__
|
||||
if (sock < 0 || dataSize <= 0) return false;
|
||||
#endif
|
||||
|
||||
@@ -694,7 +727,7 @@ bool WinsockNetLayer::SendOnSocket(SOCKET sock, const void *data, int dataSize)
|
||||
int sent = send(sock, (const char *)header + totalSent, toSend - totalSent, 0);
|
||||
#if defined _WINDOWS64 || defined _XBOX
|
||||
if (sent == SOCKET_ERROR || sent == 0)
|
||||
#elif defined __PS3__
|
||||
#elif defined __PS3__ || defined __ORBIS__
|
||||
if (sent < 0 || sent == 0)
|
||||
#endif
|
||||
{
|
||||
@@ -711,7 +744,7 @@ bool WinsockNetLayer::SendOnSocket(SOCKET sock, const void *data, int dataSize)
|
||||
|
||||
#if defined _WINDOWS64 || defined _XBOX
|
||||
if (sent == SOCKET_ERROR || sent == 0)
|
||||
#elif defined __PS3__
|
||||
#elif defined __PS3__ || defined __ORBIS__
|
||||
if (sent < 0 || sent == 0)
|
||||
#endif
|
||||
{
|
||||
@@ -734,7 +767,7 @@ bool WinsockNetLayer::SendToSmallId(BYTE targetSmallId, const void *data, int da
|
||||
SOCKET sock = GetSocketForSmallId(targetSmallId);
|
||||
#if defined _WINDOWS64 || defined _XBOX
|
||||
if (sock == INVALID_SOCKET) return false;
|
||||
#elif defined __PS3__
|
||||
#elif defined __PS3__ || defined __ORBIS__
|
||||
if (sock < 0) return false;
|
||||
#endif
|
||||
return SendOnSocket(sock, data, dataSize);
|
||||
@@ -760,7 +793,7 @@ SOCKET WinsockNetLayer::GetSocketForSmallId(BYTE smallId)
|
||||
LeaveCriticalSection(&s_connectionsLock);
|
||||
#if defined _WINDOWS64 || defined _XBOX
|
||||
return INVALID_SOCKET;
|
||||
#elif defined __PS3__
|
||||
#elif defined __PS3__ || defined __ORBIS__
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
@@ -810,7 +843,7 @@ int WinsockNetLayer::AcceptThreadProc(LPVOID param)
|
||||
app.DebugPrintf("accept() failed: %d\n", WSAGetLastError());
|
||||
break;
|
||||
}
|
||||
#elif __PS3__
|
||||
#elif __PS3__ || defined __ORBIS__
|
||||
if (clientSocket < 0)
|
||||
{
|
||||
if (s_active)
|
||||
@@ -1017,7 +1050,7 @@ int WinsockNetLayer::ClientRecvThreadProc(LPVOID param)
|
||||
|
||||
#if defined _WINDOWS64 || defined _XBOX
|
||||
while (s_active && s_hostConnectionSocket != INVALID_SOCKET)
|
||||
#elif defined __PS3__
|
||||
#elif defined __PS3__ || defined __ORBIS__
|
||||
while (s_active && s_hostConnectionSocket >= 0)
|
||||
#endif
|
||||
{
|
||||
@@ -1082,7 +1115,7 @@ bool WinsockNetLayer::StartAdvertising(int gamePort, const wchar_t *hostName, un
|
||||
app.DebugPrintf("Win64 LAN: Failed to create advertise socket: %d\n", WSAGetLastError());
|
||||
return false;
|
||||
}
|
||||
#elif defined __PS3__
|
||||
#elif defined __PS3__ || defined __ORBIS__
|
||||
if (s_advertiseSock < 0)
|
||||
{
|
||||
app.DebugPrintf("PS3 LAN: Failed to create advertise socket: %d\n", s_advertiseSock);
|
||||
@@ -1110,7 +1143,7 @@ void WinsockNetLayer::StopAdvertising()
|
||||
closesocket(s_advertiseSock);
|
||||
s_advertiseSock = INVALID_SOCKET;
|
||||
}
|
||||
#elif defined __PS3__
|
||||
#elif defined __PS3__ || defined __ORBIS__
|
||||
if (s_advertiseSock >= 0)
|
||||
{
|
||||
closesocket(s_advertiseSock);
|
||||
@@ -1180,7 +1213,7 @@ int WinsockNetLayer::AdvertiseThreadProc(LPVOID param)
|
||||
{
|
||||
app.DebugPrintf("Win64 LAN: Broadcast sendto failed: %d\n", WSAGetLastError());
|
||||
}
|
||||
#elif defined __PS3__
|
||||
#elif defined __PS3__ || defined __ORBIS__
|
||||
if (sent < 0 && s_advertising)
|
||||
{
|
||||
app.DebugPrintf("PS3 LAN: Broadcast sendto failed: %d\n", sent);
|
||||
@@ -1205,13 +1238,12 @@ bool WinsockNetLayer::StartDiscovery()
|
||||
app.DebugPrintf("Win64 LAN: Failed to create discovery socket: %d\n", WSAGetLastError());
|
||||
return false;
|
||||
}
|
||||
#elif defined __PS3__
|
||||
#elif defined __PS3__ || defined __ORBIS__
|
||||
app.DebugPrintf("Discovery socket: %d\n", s_discoverySock);
|
||||
if (s_discoverySock < 0)
|
||||
{
|
||||
app.DebugPrintf("PS3 LAN: Failed to create discovery socket: %d\n", s_discoverySock);
|
||||
cellNetCtlTerm();
|
||||
sys_net_finalize_network();
|
||||
terminate_networking();
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
@@ -1233,10 +1265,14 @@ bool WinsockNetLayer::StartDiscovery()
|
||||
s_discoverySock = INVALID_SOCKET;
|
||||
return false;
|
||||
}
|
||||
#elif defined __PS3__
|
||||
#elif defined __PS3__ || defined __ORBIS__
|
||||
if (::bind(s_discoverySock, (struct sockaddr *)&bindAddr, sizeof(bindAddr)) < 0)
|
||||
{
|
||||
#if defined(__PS3__)
|
||||
app.DebugPrintf("PS3 LAN: Discovery bind failed: %d\n", sys_net_errno);
|
||||
#elif defined(__ORBIS__)
|
||||
app.DebugPrintf("PS3 LAN: Discovery bind failed: %d\n", sce_net_errno);
|
||||
#endif
|
||||
socketclose(s_discoverySock);
|
||||
s_discoverySock = -1;
|
||||
return false;
|
||||
@@ -1263,7 +1299,7 @@ void WinsockNetLayer::StopDiscovery()
|
||||
closesocket(s_discoverySock);
|
||||
s_discoverySock = INVALID_SOCKET;
|
||||
}
|
||||
#elif defined __PS3__
|
||||
#elif defined __PS3__ || defined __ORBIS__
|
||||
if (s_discoverySock >= 0)
|
||||
{
|
||||
socketclose(s_discoverySock);
|
||||
@@ -1304,7 +1340,7 @@ int WinsockNetLayer::DiscoveryThreadProc(LPVOID param)
|
||||
struct sockaddr_in senderAddr;
|
||||
#if defined _WINDOWS64 || defined _XBOX
|
||||
int senderLen = sizeof(senderAddr);
|
||||
#elif defined __PS3__
|
||||
#elif defined __PS3__ || defined __ORBIS__
|
||||
socklen_t senderLen = sizeof(senderAddr);
|
||||
#endif
|
||||
|
||||
@@ -1316,7 +1352,7 @@ int WinsockNetLayer::DiscoveryThreadProc(LPVOID param)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
#elif defined __PS3__
|
||||
#elif defined __PS3__ || defined __ORBIS__
|
||||
if (recvLen < 0)
|
||||
{
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user