mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-07-11 01:25:07 +02:00
Centralize socket-related includes, introduce socket_errno
This resolves some weird inconsistentes and include order problems related to errno. Needed for the next steps.
This commit is contained in:
@@ -12,7 +12,6 @@
|
||||
#include <strings.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
#include <cstring>
|
||||
|
||||
@@ -3,21 +3,9 @@
|
||||
#include <errno.h>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#ifndef _WIN32
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/select.h>
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include <io.h>
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#endif
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/Net/SocketCompat.h"
|
||||
#include "Common/Data/Encoding/Utf8.h"
|
||||
#include "Common/File/FileDescriptor.h"
|
||||
#include "Common/Log.h"
|
||||
|
||||
@@ -1,31 +1,14 @@
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "Common/Net/HTTPClient.h"
|
||||
|
||||
#include "Common/TimeUtil.h"
|
||||
#include "Common/StringUtils.h"
|
||||
#include "Common/System/OSD.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <netdb.h>
|
||||
#include <unistd.h>
|
||||
#define closesocket close
|
||||
#else
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <io.h>
|
||||
#endif
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "Common/Net/SocketCompat.h"
|
||||
#include "Common/Net/Resolve.h"
|
||||
#include "Common/Net/URL.h"
|
||||
|
||||
@@ -137,17 +120,10 @@ bool Connection::Connect(int maxTries, double timeout, bool *cancelConnect) {
|
||||
// Start trying to connect (async with timeout.)
|
||||
errno = 0;
|
||||
if (connect(sock, possible->ai_addr, (int)possible->ai_addrlen) < 0) {
|
||||
#if PPSSPP_PLATFORM(WINDOWS)
|
||||
int errorCode = WSAGetLastError();
|
||||
int errorCode = socket_errno;
|
||||
std::string errorString = GetStringErrorMsg(errorCode);
|
||||
bool unreachable = errorCode == WSAENETUNREACH;
|
||||
bool inProgress = errorCode == WSAEINPROGRESS || errorCode == WSAEWOULDBLOCK;
|
||||
#else
|
||||
int errorCode = errno;
|
||||
std::string errorString = strerror(errno);
|
||||
bool unreachable = errorCode == ENETUNREACH;
|
||||
bool inProgress = errorCode == EINPROGRESS || errorCode == EWOULDBLOCK;
|
||||
#endif
|
||||
if (!inProgress) {
|
||||
char addrStr[128]{};
|
||||
FormatAddr(addrStr, sizeof(addrStr), possible);
|
||||
|
||||
@@ -1,19 +1,8 @@
|
||||
#include "ppsspp_config.h"
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
#undef min
|
||||
#undef max
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
#ifndef MSG_NOSIGNAL
|
||||
// Default value to 0x00 (do nothing) in systems where it's not supported.
|
||||
#define MSG_NOSIGNAL 0x00
|
||||
#endif
|
||||
#include "Common/Net/SocketCompat.h"
|
||||
|
||||
#if _MSC_VER
|
||||
#pragma warning(disable:4267)
|
||||
@@ -98,11 +87,7 @@ bool Buffer::ReadAllWithProgress(int fd, int knownSize, RequestProgress *progres
|
||||
if (retval == 0) {
|
||||
return true;
|
||||
} else if (retval < 0) {
|
||||
#if PPSSPP_PLATFORM(WINDOWS)
|
||||
if (WSAGetLastError() != WSAEWOULDBLOCK) {
|
||||
#else
|
||||
if (errno != EWOULDBLOCK) {
|
||||
#endif
|
||||
if (socket_errno != EWOULDBLOCK) {
|
||||
ERROR_LOG(Log::IO, "Error reading from buffer: %i", retval);
|
||||
return false;
|
||||
}
|
||||
|
||||
+7
-26
@@ -7,29 +7,10 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <WinSock2.h>
|
||||
#include <Ws2tcpip.h>
|
||||
#ifndef AI_ADDRCONFIG
|
||||
#define AI_ADDRCONFIG 0x0400
|
||||
#endif
|
||||
#undef min
|
||||
#undef max
|
||||
#else
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "Common/Log.h"
|
||||
#include "Common/TimeUtil.h"
|
||||
#include "Common/Data/Encoding/Utf8.h"
|
||||
#include "Common/Net/SocketCompat.h"
|
||||
|
||||
#ifndef HTTPS_NOT_AVAILABLE
|
||||
#include "ext/naett/naett.h"
|
||||
@@ -157,7 +138,7 @@ bool GetIPList(std::vector<std::string> &IP4s) {
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
freeifaddrs(ifAddrStruct);
|
||||
return true;
|
||||
}
|
||||
@@ -170,13 +151,13 @@ bool GetIPList(std::vector<std::string> &IP4s) {
|
||||
|
||||
int sd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (sd < 0) {
|
||||
ERROR_LOG(Log::sceNet, "GetIPList failed to create socket (result = %i, errno = %i)", sd, errno);
|
||||
ERROR_LOG(Log::sceNet, "GetIPList failed to create socket (result = %i, errno = %i)", sd, socket_errno);
|
||||
return false;
|
||||
}
|
||||
|
||||
int r = ioctl(sd, SIOCGIFCONF, (char*)&ifc);
|
||||
if (r != 0) {
|
||||
ERROR_LOG(Log::sceNet, "GetIPList failed ioctl/SIOCGIFCONF (result = %i, errno = %i)", r, errno);
|
||||
ERROR_LOG(Log::sceNet, "GetIPList failed ioctl/SIOCGIFCONF (result = %i, errno = %i)", r, socket_errno);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -192,7 +173,7 @@ bool GetIPList(std::vector<std::string> &IP4s) {
|
||||
r = ioctl(sd, SIOCGIFADDR, item);
|
||||
if (r != 0)
|
||||
{
|
||||
ERROR_LOG(Log::sceNet, "GetIPList failed ioctl/SIOCGIFADDR (i = %i, result = %i, errno = %i)", i, r, errno);
|
||||
ERROR_LOG(Log::sceNet, "GetIPList failed ioctl/SIOCGIFADDR (i = %i, result = %i, errno = %i)", i, r, socket_errno);
|
||||
}
|
||||
|
||||
if (ifreqs[i].ifr_addr.sa_family == AF_INET) {
|
||||
@@ -221,7 +202,7 @@ bool GetIPList(std::vector<std::string> &IP4s) {
|
||||
// Get local host name
|
||||
char szHostName[256] = "";
|
||||
if (::gethostname(szHostName, sizeof(szHostName))) {
|
||||
// Error handling
|
||||
// Error handling
|
||||
}
|
||||
|
||||
int status;
|
||||
@@ -322,4 +303,4 @@ int inet_pton(int af, const char* src, void* dst)
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace net
|
||||
|
||||
+8
-36
@@ -1,29 +1,11 @@
|
||||
#include "ppsspp_config.h"
|
||||
|
||||
#if PPSSPP_PLATFORM(WINDOWS)
|
||||
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <io.h>
|
||||
|
||||
#else
|
||||
|
||||
#include <sys/socket.h> /* socket definitions */
|
||||
#include <sys/types.h> /* socket types */
|
||||
#include <sys/wait.h> /* for waitpid() */
|
||||
#include <netinet/in.h> /* struct sockaddr_in */
|
||||
#include <arpa/inet.h> /* inet (3) funtions */
|
||||
#include <unistd.h> /* misc. UNIX functions */
|
||||
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include <cerrno>
|
||||
#include <cstdarg>
|
||||
|
||||
#include "Common/Net/SocketCompat.h"
|
||||
#include "Common/Net/Sinks.h"
|
||||
|
||||
#include "Common/Log.h"
|
||||
@@ -192,14 +174,9 @@ bool InputSink::Block() {
|
||||
|
||||
void InputSink::AccountFill(int bytes) {
|
||||
if (bytes < 0) {
|
||||
#if PPSSPP_PLATFORM(WINDOWS)
|
||||
int err = WSAGetLastError();
|
||||
if (err == WSAEWOULDBLOCK)
|
||||
int err = socket_errno;
|
||||
if (err == EWOULDBLOCK || err == EAGAIN)
|
||||
return;
|
||||
#else
|
||||
if (errno == EWOULDBLOCK || errno == EAGAIN)
|
||||
return;
|
||||
#endif
|
||||
ERROR_LOG(Log::IO, "Error reading from socket");
|
||||
return;
|
||||
}
|
||||
@@ -349,7 +326,7 @@ bool OutputSink::Flush(bool allowBlock) {
|
||||
|
||||
int bytes = send(fd_, buf_ + read_, avail, MSG_NOSIGNAL);
|
||||
#if !PPSSPP_PLATFORM(WINDOWS)
|
||||
if (bytes == -1 && (errno == EAGAIN || errno == EWOULDBLOCK))
|
||||
if (bytes == -1 && (socket_errno == EAGAIN || socket_errno == EWOULDBLOCK))
|
||||
bytes = 0;
|
||||
#endif
|
||||
AccountDrain(bytes);
|
||||
@@ -381,7 +358,7 @@ void OutputSink::Drain() {
|
||||
|
||||
int bytes = send(fd_, buf_ + read_, avail, MSG_NOSIGNAL);
|
||||
#if !PPSSPP_PLATFORM(WINDOWS)
|
||||
if (bytes == -1 && (errno == EAGAIN || errno == EWOULDBLOCK))
|
||||
if (bytes == -1 && (socket_errno == EAGAIN || socket_errno == EWOULDBLOCK))
|
||||
bytes = 0;
|
||||
#endif
|
||||
AccountDrain(bytes);
|
||||
@@ -398,15 +375,10 @@ void OutputSink::AccountPush(size_t bytes) {
|
||||
|
||||
void OutputSink::AccountDrain(int bytes) {
|
||||
if (bytes < 0) {
|
||||
#if PPSSPP_PLATFORM(WINDOWS)
|
||||
int err = WSAGetLastError();
|
||||
if (err == WSAEWOULDBLOCK)
|
||||
int err = socket_errno;
|
||||
if (err == EWOULDBLOCK || err == EAGAIN)
|
||||
return;
|
||||
#else
|
||||
if (errno == EWOULDBLOCK || errno == EAGAIN)
|
||||
return;
|
||||
#endif
|
||||
ERROR_LOG(Log::IO, "Error writing to socket");
|
||||
ERROR_LOG(Log::IO, "Error writing to socket: %d", err);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,22 +4,40 @@
|
||||
|
||||
#if PPSSPP_PLATFORM(WINDOWS)
|
||||
#include "Common/CommonWindows.h"
|
||||
#include <io.h>
|
||||
#include <winsock2.h>
|
||||
#include <WS2tcpip.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/mman.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#if !PPSSPP_PLATFORM(SWITCH)
|
||||
#include <ifaddrs.h>
|
||||
#endif
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_LIBNX) || PPSSPP_PLATFORM(SWITCH)
|
||||
#undef __BSD_VISIBLE
|
||||
#define __BSD_VISIBLE 1
|
||||
#define TCP_MAXSEG 2
|
||||
#include <netdb.h>
|
||||
#include <switch.h>
|
||||
// Missing include, *shrugs*
|
||||
extern "C" struct hostent *gethostbyname(const char *name);
|
||||
#endif // defined(HAVE_LIBNX) || PPSSPP_PLATFORM(SWITCH)
|
||||
|
||||
// TODO: move this to some common set
|
||||
#ifdef _WIN32
|
||||
#undef errno
|
||||
#if PPSSPP_PLATFORM(WINDOWS)
|
||||
#undef ESHUTDOWN
|
||||
#undef ECONNABORTED
|
||||
#undef ECONNRESET
|
||||
@@ -49,7 +67,7 @@
|
||||
#undef ENETUNREACH
|
||||
#undef EHOSTUNREACH
|
||||
#undef ENETDOWN
|
||||
#define errno WSAGetLastError()
|
||||
#define socket_errno WSAGetLastError()
|
||||
#define ESHUTDOWN WSAESHUTDOWN
|
||||
#define ECONNABORTED WSAECONNABORTED
|
||||
#define ECONNRESET WSAECONNRESET
|
||||
@@ -79,9 +97,10 @@
|
||||
#define ENETUNREACH WSAENETUNREACH
|
||||
#define EHOSTUNREACH WSAEHOSTUNREACH
|
||||
#define ENETDOWN WSAENETDOWN
|
||||
inline bool connectInProgress(int errcode) { return (errcode == WSAEWOULDBLOCK || errcode == WSAEINPROGRESS || errcode == WSAEALREADY || errcode == WSAEINVAL); } // WSAEINVAL should be treated as WSAEALREADY during connect for backward-compatibility with Winsock 1.1
|
||||
inline bool connectInProgress(int errcode) { return (errcode == WSAEWOULDBLOCK || errcode == WSAEINPROGRESS || errcode == WSAEALREADY || errcode == WSAEINVAL); } // WSAEINVAL should be treated as WSAEALREADY during connect for backward-compatibility with Winsock 1.1
|
||||
inline bool isDisconnected(int errcode) { return (errcode == WSAECONNRESET || errcode == WSAECONNABORTED || errcode == WSAESHUTDOWN); }
|
||||
#else
|
||||
#define socket_errno errno
|
||||
#define SOCKET int
|
||||
#define INVALID_SOCKET -1
|
||||
#define SOCKET_ERROR -1
|
||||
@@ -114,3 +133,8 @@ inline bool isDisconnected(int errcode) { return (errcode == EPIPE || errcode ==
|
||||
#ifndef SD_BOTH
|
||||
#define SD_BOTH SHUT_RDWR //0x02
|
||||
#endif
|
||||
|
||||
#ifndef MSG_NOSIGNAL
|
||||
// Default value to 0x00 (do nothing) in systems where it's not supported.
|
||||
#define MSG_NOSIGNAL 0x00
|
||||
#endif
|
||||
|
||||
@@ -2,19 +2,8 @@
|
||||
#include <cctype>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#ifndef _WIN32
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/select.h>
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include <io.h>
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#endif
|
||||
|
||||
#include "Common/Net/SocketCompat.h"
|
||||
#include "Common/Data/Encoding/Base64.h"
|
||||
#include "Common/Net/HTTPServer.h"
|
||||
#include "Common/Net/Sinks.h"
|
||||
|
||||
@@ -1,22 +1,8 @@
|
||||
#include "ppsspp_config.h"
|
||||
|
||||
#if PPSSPP_PLATFORM(WINDOWS)
|
||||
#include "Common/CommonWindows.h"
|
||||
#include <WS2tcpip.h>
|
||||
#endif
|
||||
|
||||
#if __linux__ || __APPLE__ || defined(__OpenBSD__)
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/mman.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include "Common/Log.h"
|
||||
#include "Common/StringUtils.h"
|
||||
#include "Common/Net/SocketCompat.h"
|
||||
#include "Common/StringUtils.h"
|
||||
#include "Core/HLE/NetInetConstants.h"
|
||||
#include "Core/HLE/sceKernel.h"
|
||||
#include "Core/HLE/HLE.h"
|
||||
|
||||
+6
-32
@@ -23,38 +23,12 @@
|
||||
|
||||
#include "ppsspp_config.h"
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <WinSock2.h>
|
||||
#include "Common/CommonWindows.h"
|
||||
#endif
|
||||
|
||||
#if !defined(_WIN32)
|
||||
#include <unistd.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#if !PPSSPP_PLATFORM(SWITCH)
|
||||
#include <ifaddrs.h>
|
||||
#endif // !PPSSPP_PLATFORM(SWITCH)
|
||||
#endif
|
||||
|
||||
#ifndef MSG_NOSIGNAL
|
||||
// Default value to 0x00 (do nothing) in systems where it's not supported.
|
||||
#define MSG_NOSIGNAL 0x00
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_LIBNX) || PPSSPP_PLATFORM(SWITCH)
|
||||
#undef __BSD_VISIBLE
|
||||
#define __BSD_VISIBLE 1
|
||||
#include <switch.h>
|
||||
#define TCP_MAXSEG 2
|
||||
#endif // defined(HAVE_LIBNX) || PPSSPP_PLATFORM(SWITCH)
|
||||
|
||||
#include <algorithm>
|
||||
#include <mutex>
|
||||
#include <cstring>
|
||||
|
||||
#include "Common/Net/SocketCompat.h"
|
||||
|
||||
#include "Common/Data/Text/I18n.h"
|
||||
#include "Common/Data/Text/Parsers.h"
|
||||
#include "Common/System/OSD.h"
|
||||
@@ -339,7 +313,7 @@ int IsSocketReady(int fd, bool readfd, bool writefd, int* errorcode, int timeout
|
||||
// Note: select will flags an unconnected TCP socket (ie. a freshly created socket without connecting first, or when connect failed with ECONNREFUSED on linux) as writeable/readable, thus can't be used to tell whether the connection has established or not.
|
||||
int ret = select(fd + 1, readfd? &readfds: nullptr, writefd? &writefds: nullptr, nullptr, &tval);
|
||||
if (errorcode != nullptr)
|
||||
*errorcode = (ret < 0? errno: 0);
|
||||
*errorcode = (ret < 0 ? socket_errno : 0);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -1425,7 +1399,7 @@ int friendFinder(){
|
||||
// Send Ping to Server, may failed with socket error 10054/10053 if someone else with the same IP already connected to AdHoc Server (the server might need to be modified to differentiate MAC instead of IP)
|
||||
if (IsSocketReady((int)metasocket, false, true) > 0) {
|
||||
int iResult = (int)send((int)metasocket, (const char*)&opcode, 1, MSG_NOSIGNAL);
|
||||
int error = errno;
|
||||
int error = socket_errno;
|
||||
// KHBBS seems to be getting error 10053 often
|
||||
if (iResult == SOCKET_ERROR) {
|
||||
ERROR_LOG(Log::sceNet, "FriendFinder: Socket Error (%i) when sending OPCODE_PING", error);
|
||||
@@ -2011,7 +1985,7 @@ int getSockError(int sock) {
|
||||
int result = 0;
|
||||
socklen_t result_len = sizeof(result);
|
||||
if (getsockopt(sock, SOL_SOCKET, SO_ERROR, (char*)&result, &result_len) < 0) {
|
||||
result = errno;
|
||||
result = socket_errno;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -2224,7 +2198,7 @@ int initNetwork(SceNetAdhocctlAdhocId *adhoc_id){
|
||||
int cnt = 0;
|
||||
DEBUG_LOG(Log::sceNet, "InitNetwork: Connecting to AdhocServer");
|
||||
iResult = connect((int)metasocket, &g_adhocServerIP.addr, sizeof(g_adhocServerIP));
|
||||
errorcode = errno;
|
||||
errorcode = socket_errno;
|
||||
|
||||
if (iResult == SOCKET_ERROR && errorcode != EISCONN) {
|
||||
u64 startTime = (u64)(time_now_d() * 1000000.0);
|
||||
|
||||
+1
-17
@@ -17,22 +17,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
// Net stuff
|
||||
#if defined(_WIN32)
|
||||
#include "Common/CommonWindows.h"
|
||||
|
||||
#include <WS2tcpip.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/select.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netdb.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#endif
|
||||
#include "Common/Net/SocketCompat.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define PACK // on MSVC we use #pragma pack() instead so let's kill this.
|
||||
@@ -46,7 +31,6 @@
|
||||
#include <climits>
|
||||
|
||||
#include "Common/Net/Resolve.h"
|
||||
#include "Common/Net/SocketCompat.h"
|
||||
#include "Common/Serialize/Serializer.h"
|
||||
#include "Core/MemMap.h"
|
||||
#include "Core/HLE/sceKernelThread.h"
|
||||
|
||||
+14
-39
@@ -28,33 +28,8 @@
|
||||
#include <cstring>
|
||||
#include <signal.h>
|
||||
|
||||
#if defined(HAVE_LIBNX) || PPSSPP_PLATFORM(SWITCH)
|
||||
#include <netdb.h>
|
||||
#include <switch.h>
|
||||
// Missing include, *shrugs*
|
||||
extern "C" struct hostent *gethostbyname(const char *name);
|
||||
#endif // defined(HAVE_LIBNX) || PPSSPP_PLATFORM(SWITCH)
|
||||
|
||||
#include <sys/types.h>
|
||||
// Net stuff
|
||||
#if defined(_WIN32)
|
||||
#include <WinSock2.h>
|
||||
#include <WS2tcpip.h>
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
#endif
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
//#include <sqlite3.h>
|
||||
|
||||
#ifndef MSG_NOSIGNAL
|
||||
// Default value to 0x00 (do nothing) in systems where it's not supported.
|
||||
#define MSG_NOSIGNAL 0x00
|
||||
#endif
|
||||
|
||||
#include "Common/Net/SocketCompat.h"
|
||||
#include "Common/Data/Text/I18n.h"
|
||||
#include "Common/Thread/ThreadUtil.h"
|
||||
#include "Common/System/OSD.h"
|
||||
@@ -860,7 +835,7 @@ void connect_user(SceNetAdhocctlUserNode * user, SceNetAdhocctlGroupName * group
|
||||
|
||||
// Send Data
|
||||
int iResult = (int)send(peer->stream, (const char*)&packet, sizeof(packet), MSG_NOSIGNAL);
|
||||
if (iResult < 0) ERROR_LOG(Log::sceNet, "AdhocServer: connect_user[send peer] (Socket error %d)", errno);
|
||||
if (iResult < 0) ERROR_LOG(Log::sceNet, "AdhocServer: connect_user[send peer] (Socket error %d)", socket_errno);
|
||||
|
||||
// Set Player Name
|
||||
packet.name = peer->resolver.name;
|
||||
@@ -873,7 +848,7 @@ void connect_user(SceNetAdhocctlUserNode * user, SceNetAdhocctlGroupName * group
|
||||
|
||||
// Send Data
|
||||
iResult = (int)send(user->stream, (const char*)&packet, sizeof(packet), MSG_NOSIGNAL);
|
||||
if (iResult < 0) ERROR_LOG(Log::sceNet, "AdhocServer: connect_user[send user] (Socket error %d)", errno);
|
||||
if (iResult < 0) ERROR_LOG(Log::sceNet, "AdhocServer: connect_user[send user] (Socket error %d)", socket_errno);
|
||||
|
||||
// Set BSSID
|
||||
if(peer->group_next == NULL) bssid.mac = peer->resolver.mac;
|
||||
@@ -895,7 +870,7 @@ void connect_user(SceNetAdhocctlUserNode * user, SceNetAdhocctlGroupName * group
|
||||
|
||||
// Send Network BSSID to User
|
||||
int iResult = (int)send(user->stream, (const char*)&bssid, sizeof(bssid), MSG_NOSIGNAL);
|
||||
if (iResult < 0) ERROR_LOG(Log::sceNet, "AdhocServer: connect_user[send user bssid] (Socket error %d)", errno);
|
||||
if (iResult < 0) ERROR_LOG(Log::sceNet, "AdhocServer: connect_user[send user bssid] (Socket error %d)", socket_errno);
|
||||
|
||||
// Notify User
|
||||
char safegamestr[10];
|
||||
@@ -987,7 +962,7 @@ void disconnect_user(SceNetAdhocctlUserNode * user)
|
||||
|
||||
// Send Data
|
||||
int iResult = (int)send(peer->stream, (const char*)&packet, sizeof(packet), MSG_NOSIGNAL);
|
||||
if (iResult < 0) ERROR_LOG(Log::sceNet, "AdhocServer: disconnect_user[send peer] (Socket error %d)", errno);
|
||||
if (iResult < 0) ERROR_LOG(Log::sceNet, "AdhocServer: disconnect_user[send peer] (Socket error %d)", socket_errno);
|
||||
|
||||
// Move Pointer
|
||||
peer = peer->group_next;
|
||||
@@ -1086,13 +1061,13 @@ void send_scan_results(SceNetAdhocctlUserNode * user)
|
||||
|
||||
// Send Group Packet
|
||||
int iResult = (int)send(user->stream, (const char*)&packet, sizeof(packet), MSG_NOSIGNAL);
|
||||
if (iResult < 0) ERROR_LOG(Log::sceNet, "AdhocServer: send_scan_result[send user] (Socket error %d)", errno);
|
||||
if (iResult < 0) ERROR_LOG(Log::sceNet, "AdhocServer: send_scan_result[send user] (Socket error %d)", socket_errno);
|
||||
}
|
||||
|
||||
// Notify Player of End of Scan
|
||||
uint8_t opcode = OPCODE_SCAN_COMPLETE;
|
||||
int iResult = (int)send(user->stream, (const char*)&opcode, 1, MSG_NOSIGNAL);
|
||||
if (iResult < 0) ERROR_LOG(Log::sceNet, "AdhocServer: send_scan_result[send peer complete] (Socket error %d)", errno);
|
||||
if (iResult < 0) ERROR_LOG(Log::sceNet, "AdhocServer: send_scan_result[send peer complete] (Socket error %d)", socket_errno);
|
||||
|
||||
// Notify User
|
||||
char safegamestr[10];
|
||||
@@ -1151,7 +1126,7 @@ void spread_message(SceNetAdhocctlUserNode *user, const char *message)
|
||||
|
||||
// Send Data
|
||||
int iResult = (int)send(user->stream, (const char*)&packet, sizeof(packet), MSG_NOSIGNAL);
|
||||
if (iResult < 0) ERROR_LOG(Log::sceNet, "AdhocServer: spread_message[send user chat] (Socket error %d)", errno);
|
||||
if (iResult < 0) ERROR_LOG(Log::sceNet, "AdhocServer: spread_message[send user chat] (Socket error %d)", socket_errno);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1193,7 +1168,7 @@ void spread_message(SceNetAdhocctlUserNode *user, const char *message)
|
||||
|
||||
// Send Data
|
||||
int iResult = (int)send(peer->stream, (const char*)&packet, sizeof(packet), MSG_NOSIGNAL);
|
||||
if (iResult < 0) ERROR_LOG(Log::sceNet, "AdhocServer: spread_message[send peer chat] (Socket error %d)", errno);
|
||||
if (iResult < 0) ERROR_LOG(Log::sceNet, "AdhocServer: spread_message[send peer chat] (Socket error %d)", socket_errno);
|
||||
|
||||
// Move Pointer
|
||||
peer = peer->group_next;
|
||||
@@ -1856,18 +1831,18 @@ int create_listen_socket(uint16_t port)
|
||||
|
||||
// Notify User
|
||||
else {
|
||||
ERROR_LOG(Log::sceNet, "AdhocServer: Bind returned %i (Socket error %d)", bindresult, errno);
|
||||
ERROR_LOG(Log::sceNet, "AdhocServer: Bind returned %i (Socket error %d)", bindresult, socket_errno);
|
||||
auto n = GetI18NCategory(I18NCat::NETWORKING);
|
||||
g_OSD.Show(OSDType::MESSAGE_ERROR, std::string(n->T("AdhocServer Failed to Bind Port")) + " " + std::to_string(port));
|
||||
}
|
||||
|
||||
// Close Socket
|
||||
closesocket(fd);
|
||||
} else {
|
||||
// Notify User
|
||||
ERROR_LOG(Log::sceNet, "AdhocServer: Socket returned %i (Socket error %d)", fd, socket_errno);
|
||||
}
|
||||
|
||||
// Notify User
|
||||
else ERROR_LOG(Log::sceNet, "AdhocServer: Socket returned %i (Socket error %d)", fd, errno);
|
||||
|
||||
// Return Error
|
||||
return -1;
|
||||
}
|
||||
@@ -1942,7 +1917,7 @@ int server_loop(int server)
|
||||
int recvresult = (int)recv(user->stream, (char*)user->rx + user->rxpos, sizeof(user->rx) - user->rxpos, MSG_NOSIGNAL);
|
||||
|
||||
// Connection Closed or Timed Out
|
||||
if(recvresult == 0 || (recvresult == -1 && errno != EAGAIN && errno != EWOULDBLOCK) || get_user_state(user) == USER_STATE_TIMED_OUT)
|
||||
if(recvresult == 0 || (recvresult == -1 && socket_errno != EAGAIN && socket_errno != EWOULDBLOCK) || get_user_state(user) == USER_STATE_TIMED_OUT)
|
||||
{
|
||||
// Logout User
|
||||
logout_user(user);
|
||||
|
||||
+4
-14
@@ -15,21 +15,11 @@
|
||||
// Official git repository and contact information can be found at
|
||||
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
||||
|
||||
#if __linux__ || __APPLE__ || defined(__OpenBSD__)
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
#elif _WIN32
|
||||
#include <winsock2.h>
|
||||
#pragma comment(lib, "ws2_32.lib")
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <shared_mutex>
|
||||
|
||||
// TODO: fixme move Core/Net to Common/Net
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include "Common/Net/Resolve.h"
|
||||
#include "Common/Net/SocketCompat.h"
|
||||
#include "Core/Net/InetCommon.h"
|
||||
#include "Common/Data/Text/Parsers.h"
|
||||
|
||||
|
||||
+24
-24
@@ -359,7 +359,7 @@ static void __AdhocctlNotify(u64 userdata, int cyclesLate) {
|
||||
// Don't send anything yet if connection to Adhoc Server is still in progress
|
||||
if (!isAdhocctlNeedLogin && IsSocketReady((int)metasocket, false, true) > 0) {
|
||||
ret = send((int)metasocket, (const char*)&packet, len, MSG_NOSIGNAL);
|
||||
sockerr = errno;
|
||||
sockerr = socket_errno;
|
||||
// Successfully Sent or Connection has been closed or Connection failure occurred
|
||||
if (ret >= 0 || (ret == SOCKET_ERROR && sockerr != EAGAIN && sockerr != EWOULDBLOCK)) {
|
||||
// Prevent from sending again
|
||||
@@ -487,7 +487,7 @@ int DoBlockingPdpRecv(AdhocSocketRequest& req, s64& result) {
|
||||
|
||||
// On Windows: MSG_TRUNC are not supported on recvfrom (socket error WSAEOPNOTSUPP), so we use dummy buffer as an alternative
|
||||
ret = recvfrom(pdpsocket.id, dummyPeekBuf64k, dummyPeekBuf64kSize, MSG_PEEK | MSG_NOSIGNAL, (struct sockaddr*)&sin, &sinlen);
|
||||
sockerr = errno;
|
||||
sockerr = socket_errno;
|
||||
|
||||
// Discard packets from IP that can't be translated into MAC address to prevent confusing the game, since the sender MAC won't be updated and may contains invalid/undefined value.
|
||||
// TODO: In order to discard packets from unresolvable IP (can't be translated into player's MAC) properly, we'll need to manage the socket buffer ourself,
|
||||
@@ -611,7 +611,7 @@ int DoBlockingPdpSend(AdhocSocketRequest& req, s64& result, AdhocSendTargets& ta
|
||||
target.sin_port = htons(peer->port + peer->portOffset);
|
||||
|
||||
int ret = sendto(pdpsocket.id, (const char*)req.buffer, targetPeers.length, MSG_NOSIGNAL, (struct sockaddr*)&target, sizeof(target));
|
||||
int sockerr = errno;
|
||||
int sockerr = socket_errno;
|
||||
|
||||
if (ret >= 0) {
|
||||
DEBUG_LOG(Log::sceNet, "sceNetAdhocPdpSend[%i:%u](B): Sent %u bytes to %s:%u\n", req.id, getLocalPort(pdpsocket.id), ret, ip2str(target.sin_addr).c_str(), ntohs(target.sin_port));
|
||||
@@ -656,7 +656,7 @@ int DoBlockingPtpSend(AdhocSocketRequest& req, s64& result) {
|
||||
|
||||
// Send Data
|
||||
int ret = send(ptpsocket.id, (const char*)req.buffer, *req.length, MSG_NOSIGNAL);
|
||||
int sockerr = errno;
|
||||
int sockerr = socket_errno;
|
||||
|
||||
// Success
|
||||
if (ret > 0) {
|
||||
@@ -708,7 +708,7 @@ int DoBlockingPtpRecv(AdhocSocketRequest& req, s64& result) {
|
||||
}
|
||||
|
||||
int ret = recv(ptpsocket.id, (char*)req.buffer, std::max(0, *req.length), MSG_NOSIGNAL);
|
||||
int sockerr = errno;
|
||||
int sockerr = socket_errno;
|
||||
|
||||
// Received Data. POSIX: May received 0 bytes when the remote peer already closed the connection.
|
||||
if (ret > 0) {
|
||||
@@ -773,7 +773,7 @@ int DoBlockingPtpAccept(AdhocSocketRequest& req, s64& result) {
|
||||
if (ret > 0) {
|
||||
// Accept Connection
|
||||
ret = accept(ptpsocket.id, (struct sockaddr*)&sin, &sinlen);
|
||||
sockerr = errno;
|
||||
sockerr = socket_errno;
|
||||
}
|
||||
|
||||
// Accepted New Connection
|
||||
@@ -823,7 +823,7 @@ int DoBlockingPtpConnect(AdhocSocketRequest& req, s64& result, AdhocSendTargets&
|
||||
sin.sin_port = htons(ptpsocket.pport + targetPeer.peers[0].portOffset);
|
||||
|
||||
ret = connect(ptpsocket.id, (struct sockaddr*)&sin, sizeof(sin));
|
||||
sockerr = errno;
|
||||
sockerr = socket_errno;
|
||||
if (sockerr != 0)
|
||||
DEBUG_LOG(Log::sceNet, "sceNetAdhocPtpConnect[%i:%u]: connect(%i) error = %i", req.id, ptpsocket.lport, ptpsocket.id, sockerr);
|
||||
else
|
||||
@@ -853,7 +853,7 @@ int DoBlockingPtpConnect(AdhocSocketRequest& req, s64& result, AdhocSendTargets&
|
||||
// Note: "getpeername" shouldn't failed if the connection has been established, but on Windows it may succeed even when "connect" is still in-progress and not accepted yet (ie. "Tales of VS" on Windows)
|
||||
ret = getpeername(ptpsocket.id, (struct sockaddr*)&sin, &sinlen);
|
||||
if (ret == SOCKET_ERROR) {
|
||||
int err = errno;
|
||||
int err = socket_errno;
|
||||
VERBOSE_LOG(Log::sceNet, "sceNetAdhocPtpConnect[%i:%u]: getpeername(%i) error %i, sockerr = %i", req.id, ptpsocket.lport, ptpsocket.id, err, sockerr);
|
||||
sockerr = err;
|
||||
}
|
||||
@@ -876,7 +876,7 @@ int DoBlockingPtpConnect(AdhocSocketRequest& req, s64& result, AdhocSendTargets&
|
||||
if (/*sockerr == ECONNREFUSED ||*/ static_cast<s64>(CoreTiming::GetGlobalTimeUsScaled() - sock->internalLastAttempt) > 16666) {
|
||||
DEBUG_LOG(Log::sceNet, "sceNetAdhocPtpConnect[%i:%u]: Recreating Socket %i, errno = %i, state = %i, attempt = %i", req.id, ptpsocket.lport, ptpsocket.id, sockerr, ptpsocket.state, sock->attemptCount);
|
||||
if (RecreatePtpSocket(req.id) < 0) {
|
||||
WARN_LOG(Log::sceNet, "sceNetAdhocPtpConnect[%i:%u]: RecreatePtpSocket error %i", req.id, ptpsocket.lport, errno);
|
||||
WARN_LOG(Log::sceNet, "sceNetAdhocPtpConnect[%i:%u]: RecreatePtpSocket error %i", req.id, ptpsocket.lport, socket_errno);
|
||||
}
|
||||
ptpsocket.state = ADHOC_PTP_STATE_CLOSED;
|
||||
sock->internalLastAttempt = CoreTiming::GetGlobalTimeUsScaled();
|
||||
@@ -1485,7 +1485,7 @@ int sceNetAdhocPdpCreate(const char *mac, int port, int bufferSize, u32 flag) {
|
||||
|
||||
// Port not available (exclusively in use?)
|
||||
if (iResult == SOCKET_ERROR) {
|
||||
ERROR_LOG(Log::sceNet, "Socket error (%i) when binding port %u", errno, ntohs(addr.sin_port));
|
||||
ERROR_LOG(Log::sceNet, "Socket error (%i) when binding port %u", socket_errno, ntohs(addr.sin_port));
|
||||
auto n = GetI18NCategory(I18NCat::NETWORKING);
|
||||
g_OSD.Show(OSDType::MESSAGE_ERROR, std::string(n->T("Failed to Bind Port")) + " " + std::to_string(port + portOffset) + "\n" + std::string(n->T("Please change your Port Offset")), 0.0f, "portbindfail");
|
||||
|
||||
@@ -1612,7 +1612,7 @@ int sceNetAdhocPdpSend(int id, const char *mac, u32 port, void *data, int len, i
|
||||
|
||||
// Send Data. UDP are guaranteed to be sent as a whole or nothing(failed if len > SO_MAX_MSG_SIZE), and never be partially sent/recv
|
||||
int sent = sendto(pdpsocket.id, (const char *)data, len, MSG_NOSIGNAL, (struct sockaddr*)&target, sizeof(target));
|
||||
int error = errno;
|
||||
int error = socket_errno;
|
||||
|
||||
if (sent == SOCKET_ERROR) {
|
||||
// Simulate blocking behaviour with non-blocking socket
|
||||
@@ -1713,7 +1713,7 @@ int sceNetAdhocPdpSend(int id, const char *mac, u32 port, void *data, int len, i
|
||||
target.sin_port = htons(dport + peer.portOffset);
|
||||
|
||||
int sent = sendto(pdpsocket.id, (const char*)data, len, MSG_NOSIGNAL, (struct sockaddr*)&target, sizeof(target));
|
||||
int error = errno;
|
||||
int error = socket_errno;
|
||||
if (sent == SOCKET_ERROR) {
|
||||
DEBUG_LOG(Log::sceNet, "Socket Error (%i) on sceNetAdhocPdpSend[%i:%u->%u](BC) [size=%i]", error, id, getLocalPort(pdpsocket.id), ntohs(target.sin_port), len);
|
||||
}
|
||||
@@ -1847,7 +1847,7 @@ int sceNetAdhocPdpRecv(int id, void *addr, void * port, void *buf, void *dataLen
|
||||
sinlen = sizeof(sin);
|
||||
memset(&sin, 0, sinlen);
|
||||
received = recvfrom(pdpsocket.id, dummyPeekBuf64k, dummyPeekBuf64kSize, MSG_PEEK | MSG_NOSIGNAL, (struct sockaddr*)&sin, &sinlen);
|
||||
error = errno;
|
||||
error = socket_errno;
|
||||
// Discard packets from IP that can't be translated into MAC address to prevent confusing the game, since the sender MAC won't be updated and may contains invalid/undefined value.
|
||||
// TODO: In order to discard packets from unresolvable IP (can't be translated into player's MAC) properly, we'll need to manage the socket buffer ourself,
|
||||
// by reading the whole available data, separates each datagram and discard unresolvable one, so we can calculate the correct number of available data to recv on GetPdpStat too.
|
||||
@@ -1900,7 +1900,7 @@ int sceNetAdhocPdpRecv(int id, void *addr, void * port, void *buf, void *dataLen
|
||||
memset(&sin, 0, sinlen);
|
||||
// On Windows: Socket Error 10014 may happen when buffer size is less than the minimum allowed/required (ie. negative number on Vulcanus Seek and Destroy), the address is not a valid part of the user address space (ie. on the stack or when buffer overflow occurred), or the address is not properly aligned (ie. multiple of 4 on 32bit and multiple of 8 on 64bit) https://stackoverflow.com/questions/861154/winsock-error-code-10014
|
||||
received = recvfrom(pdpsocket.id, (char*)buf, std::max(0, *len), MSG_NOSIGNAL, (struct sockaddr*)&sin, &sinlen);
|
||||
error = errno;
|
||||
error = socket_errno;
|
||||
|
||||
// On Windows: recvfrom on UDP can get error WSAECONNRESET when previous sendto's destination is unreachable (or destination port is not bound), may need to disable SIO_UDP_CONNRESET
|
||||
if (received == SOCKET_ERROR && (error == EAGAIN || error == EWOULDBLOCK || error == ECONNRESET)) {
|
||||
@@ -2476,7 +2476,7 @@ u32 NetAdhocctl_Disconnect() {
|
||||
|
||||
// Send Disconnect Request Packet
|
||||
iResult = send((int)metasocket, (const char*)&opcode, 1, MSG_NOSIGNAL);
|
||||
error = errno;
|
||||
error = socket_errno;
|
||||
|
||||
// Sending may get socket error 10053 if the AdhocServer is already shutted down
|
||||
if (iResult == SOCKET_ERROR) {
|
||||
@@ -3307,7 +3307,7 @@ int RecreatePtpSocket(int ptpId) {
|
||||
|
||||
// Bound Socket to local Port
|
||||
if (bind(tcpsocket, (struct sockaddr*)&addr, sizeof(addr)) == SOCKET_ERROR) {
|
||||
ERROR_LOG(Log::sceNet, "RecreatePtpSocket(%i) - Socket error (%i) when binding port %u", ptpId, errno, ntohs(addr.sin_port));
|
||||
ERROR_LOG(Log::sceNet, "RecreatePtpSocket(%i) - Socket error (%i) when binding port %u", ptpId, socket_errno, ntohs(addr.sin_port));
|
||||
}
|
||||
else {
|
||||
// Update sport with the port assigned internal->lport = ntohs(local.sin_port)
|
||||
@@ -3325,7 +3325,7 @@ int RecreatePtpSocket(int ptpId) {
|
||||
sock->data.ptp.lport = newlport;
|
||||
}
|
||||
else {
|
||||
WARN_LOG(Log::sceNet, "RecreatePtpSocket(%i): getsockname error %i", ptpId, errno);
|
||||
WARN_LOG(Log::sceNet, "RecreatePtpSocket(%i): getsockname error %i", ptpId, socket_errno);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3495,7 +3495,7 @@ static int sceNetAdhocPtpOpen(const char *srcmac, int sport, const char *dstmac,
|
||||
}
|
||||
}
|
||||
else {
|
||||
ERROR_LOG(Log::sceNet, "Socket error (%i) when binding port %u", errno, ntohs(addr.sin_port));
|
||||
ERROR_LOG(Log::sceNet, "Socket error (%i) when binding port %u", socket_errno, ntohs(addr.sin_port));
|
||||
auto n = GetI18NCategory(I18NCat::NETWORKING);
|
||||
g_OSD.Show(OSDType::MESSAGE_ERROR,
|
||||
std::string(n->T("Failed to Bind Port")) + " " + std::to_string(sport + portOffset) + "\n" + std::string(n->T("Please change your Port Offset")), 0.0f, "portbindfail");
|
||||
@@ -3691,7 +3691,7 @@ static int sceNetAdhocPtpAccept(int id, u32 peerMacAddrPtr, u32 peerPortPtr, int
|
||||
if (newsocket > 0) {
|
||||
// Accept Connection
|
||||
newsocket = accept(ptpsocket.id, (struct sockaddr*)&peeraddr, &peeraddrlen);
|
||||
error = errno;
|
||||
error = socket_errno;
|
||||
}
|
||||
|
||||
if (newsocket == 0 || (newsocket == SOCKET_ERROR && (error == EAGAIN || error == EWOULDBLOCK))) {
|
||||
@@ -3781,7 +3781,7 @@ int NetAdhocPtp_Connect(int id, int timeout, int flag, bool allowForcedConnect)
|
||||
int connectresult = connect(ptpsocket.id, (struct sockaddr*)&sin, sizeof(sin));
|
||||
|
||||
// Grab Error Code
|
||||
int errorcode = errno;
|
||||
int errorcode = socket_errno;
|
||||
|
||||
if (connectresult == SOCKET_ERROR) {
|
||||
if (errorcode == EAGAIN || errorcode == EWOULDBLOCK || errorcode == EALREADY || errorcode == EISCONN)
|
||||
@@ -4096,7 +4096,7 @@ static int sceNetAdhocPtpListen(const char *srcmac, int sport, int bufsize, int
|
||||
}
|
||||
|
||||
if (iResult == SOCKET_ERROR) {
|
||||
int error = errno;
|
||||
int error = socket_errno;
|
||||
ERROR_LOG(Log::sceNet, "sceNetAdhocPtpListen[%i]: Socket Error (%i)", sport, error);
|
||||
}
|
||||
|
||||
@@ -4168,7 +4168,7 @@ static int sceNetAdhocPtpSend(int id, u32 dataAddr, u32 dataSizeAddr, int timeou
|
||||
|
||||
// Send Data
|
||||
int sent = send(ptpsocket.id, data, *len, MSG_NOSIGNAL);
|
||||
int error = errno;
|
||||
int error = socket_errno;
|
||||
|
||||
// Free Network Lock
|
||||
// _freeNetworkLock();
|
||||
@@ -4273,7 +4273,7 @@ static int sceNetAdhocPtpRecv(int id, u32 dataAddr, u32 dataSizeAddr, int timeou
|
||||
|
||||
// Receive Data. POSIX: May received 0 bytes when the remote peer already closed the connection.
|
||||
received = recv(ptpsocket.id, (char*)buf, std::max(0, *len), MSG_NOSIGNAL);
|
||||
error = errno;
|
||||
error = socket_errno;
|
||||
|
||||
if (received == SOCKET_ERROR && (error == EAGAIN || error == EWOULDBLOCK || (ptpsocket.state == ADHOC_PTP_STATE_SYN_SENT && (error == ENOTCONN || connectInProgress(error))))) {
|
||||
if (flag == 0) {
|
||||
@@ -4349,7 +4349,7 @@ int FlushPtpSocket(int socketId) {
|
||||
// Send Empty Data just to trigger Nagle on/off effect to flush the send buffer, Do we need to trigger this at all or is it automatically flushed?
|
||||
//changeBlockingMode(socket->id, nonblock);
|
||||
int ret = send(socketId, nullptr, 0, MSG_NOSIGNAL);
|
||||
if (ret == SOCKET_ERROR) ret = errno;
|
||||
if (ret == SOCKET_ERROR) ret = socket_errno;
|
||||
//changeBlockingMode(socket->id, 1);
|
||||
|
||||
// Restore/Enable Nagle Algo
|
||||
|
||||
+21
-24
@@ -1,4 +1,6 @@
|
||||
#include <algorithm>
|
||||
#include "Common/StringUtils.h"
|
||||
#include "Common/Net/SocketCompat.h"
|
||||
#include "Common/Data/Text/Parsers.h"
|
||||
#include "Common/Serialize/Serializer.h"
|
||||
#include "Common/Serialize/SerializeFuncs.h"
|
||||
@@ -20,11 +22,6 @@
|
||||
#include "Core/Util/PortManager.h"
|
||||
#include "Core/Instance.h"
|
||||
|
||||
#ifndef MSG_NOSIGNAL
|
||||
// Default value to 0x00 (do nothing) in systems where it's not supported.
|
||||
#define MSG_NOSIGNAL 0x00
|
||||
#endif
|
||||
|
||||
int inetLastErrno = 0; // TODO: since errno can only be read once, we should keep track the value to be used on sceNetInetGetErrno
|
||||
int inetLastSocket = -1; // A workaround to keep the most recent socket id for sceNetInetSelect, until we have a socket class wrapper
|
||||
|
||||
@@ -55,7 +52,7 @@ static int sceNetInetTerm() {
|
||||
|
||||
static int sceNetInetGetErrno() {
|
||||
if (inetLastErrno == 0)
|
||||
inetLastErrno = errno;
|
||||
inetLastErrno = socket_errno;
|
||||
int error = convertInetErrnoHost2PSP(inetLastErrno);
|
||||
inetLastErrno = 0;
|
||||
return hleLogSuccessI(Log::sceNet, error, " at %08x", currentMIPS->pc);
|
||||
@@ -63,7 +60,7 @@ static int sceNetInetGetErrno() {
|
||||
|
||||
static int sceNetInetGetPspError() {
|
||||
if (inetLastErrno == 0)
|
||||
inetLastErrno = errno;
|
||||
inetLastErrno = socket_errno;
|
||||
int error = convertInetErrno2PSPError(convertInetErrnoHost2PSP(inetLastErrno));
|
||||
inetLastErrno = 0;
|
||||
return hleLogSuccessX(Log::sceNet, error, " at %08x", currentMIPS->pc);
|
||||
@@ -136,7 +133,7 @@ static int sceNetInetGetpeername(int sock, u32 namePtr, u32 namelenPtr) {
|
||||
DEBUG_LOG(Log::sceNet, "Getpeername: Family = %s, Address = %s, Port = %d", inetSocketDomain2str(saddr.addr.sa_family).c_str(), ip2str(saddr.in.sin_addr).c_str(), ntohs(saddr.in.sin_port));
|
||||
*namelen = len;
|
||||
if (retval < 0) {
|
||||
inetLastErrno = errno;
|
||||
inetLastErrno = socket_errno;
|
||||
return hleLogError(Log::sceNet, retval, "errno = %d", inetLastErrno);
|
||||
} else {
|
||||
memcpy(name->sa_data, saddr.addr.sa_data, len - (sizeof(name->sa_len) + sizeof(name->sa_family)));
|
||||
@@ -163,7 +160,7 @@ static int sceNetInetGetsockname(int sock, u32 namePtr, u32 namelenPtr) {
|
||||
DEBUG_LOG(Log::sceNet, "Getsockname: Family = %s, Address = %s, Port = %d", inetSocketDomain2str(saddr.addr.sa_family).c_str(), ip2str(saddr.in.sin_addr).c_str(), ntohs(saddr.in.sin_port));
|
||||
*namelen = len;
|
||||
if (retval < 0) {
|
||||
inetLastErrno = errno;
|
||||
inetLastErrno = socket_errno;
|
||||
return hleLogError(Log::sceNet, retval, "errno = %d", inetLastErrno);
|
||||
} else {
|
||||
memcpy(name->sa_data, saddr.addr.sa_data, len - (sizeof(name->sa_len) + sizeof(name->sa_family)));
|
||||
@@ -259,7 +256,7 @@ int sceNetInetSelect(int nfds, u32 readfdsPtr, u32 writefdsPtr, u32 exceptfdsPtr
|
||||
}
|
||||
|
||||
if (retval < 0) {
|
||||
inetLastErrno = errno;
|
||||
inetLastErrno = socket_errno;
|
||||
if (inetLastErrno == 0)
|
||||
hleLogDebug(Log::sceNet, retval, "errno = %d", inetLastErrno);
|
||||
else if (inetLastErrno < 0)
|
||||
@@ -326,7 +323,7 @@ static int sceNetInetRecv(int socket, u32 bufPtr, u32 bufLen, u32 flags) {
|
||||
flgs = convertMSGFlagsPSP2Host(flgs);
|
||||
int retval = recv(socket, (char*)Memory::GetPointer(bufPtr), bufLen, flgs | MSG_NOSIGNAL);
|
||||
if (retval < 0) {
|
||||
inetLastErrno = errno;
|
||||
inetLastErrno = socket_errno;
|
||||
if (inetLastErrno == EAGAIN)
|
||||
hleLogDebug(Log::sceNet, retval, "errno = %d", inetLastErrno);
|
||||
else
|
||||
@@ -353,7 +350,7 @@ static int sceNetInetSend(int socket, u32 bufPtr, u32 bufLen, u32 flags) {
|
||||
int retval = send(socket, (char*)Memory::GetPointer(bufPtr), bufLen, flgs | MSG_NOSIGNAL);
|
||||
|
||||
if (retval < 0) {
|
||||
inetLastErrno = errno;
|
||||
inetLastErrno = socket_errno;
|
||||
if (inetLastErrno == EAGAIN)
|
||||
hleLogDebug(Log::sceNet, retval, "errno = %d", inetLastErrno);
|
||||
else
|
||||
@@ -369,7 +366,7 @@ static int sceNetInetSocket(int domain, int type, int protocol) {
|
||||
DEBUG_LOG(Log::sceNet, "Socket: Domain = %s, Type = %s, Protocol = %s", inetSocketDomain2str(domain).c_str(), inetSocketType2str(type).c_str(), inetSocketProto2str(protocol).c_str());
|
||||
int retval = socket(convertSocketDomainPSP2Host(domain), convertSocketTypePSP2Host(type), convertSocketProtoPSP2Host(protocol));
|
||||
if (retval < 0) {
|
||||
inetLastErrno = errno;
|
||||
inetLastErrno = socket_errno;
|
||||
return hleLogError(Log::sceNet, retval, "errno = %d", inetLastErrno);
|
||||
}
|
||||
|
||||
@@ -439,7 +436,7 @@ static int sceNetInetSetsockopt(int socket, int level, int optname, u32 optvalPt
|
||||
retval = setsockopt(socket, convertSockoptLevelPSP2Host(level), convertSockoptNamePSP2Host(optname, level), (char*)optval, optlen);
|
||||
}
|
||||
if (retval < 0) {
|
||||
inetLastErrno = errno;
|
||||
inetLastErrno = socket_errno;
|
||||
hleLogError(Log::sceNet, retval, "errno = %d", inetLastErrno);
|
||||
}
|
||||
return hleLogSuccessI(Log::sceNet, retval);
|
||||
@@ -498,7 +495,7 @@ static int sceNetInetGetsockopt(int socket, int level, int optname, u32 optvalPt
|
||||
retval = getsockopt(socket, convertSockoptLevelPSP2Host(level), convertSockoptNamePSP2Host(optname, level), (char*)optval, optlen);
|
||||
}
|
||||
if (retval < 0) {
|
||||
inetLastErrno = errno;
|
||||
inetLastErrno = socket_errno;
|
||||
hleLogError(Log::sceNet, retval, "errno = %d", inetLastErrno);
|
||||
}
|
||||
DEBUG_LOG(Log::sceNet, "SockOpt: OptValue = %d", *optval);
|
||||
@@ -532,7 +529,7 @@ static int sceNetInetBind(int socket, u32 namePtr, int namelen) {
|
||||
changeBlockingMode(socket, 0);
|
||||
int retval = bind(socket, (struct sockaddr*)&saddr, len);
|
||||
if (retval < 0) {
|
||||
inetLastErrno = errno;
|
||||
inetLastErrno = socket_errno;
|
||||
changeBlockingMode(socket, 1);
|
||||
return hleLogError(Log::sceNet, retval, "errno = %d", inetLastErrno);
|
||||
}
|
||||
@@ -571,7 +568,7 @@ static int sceNetInetConnect(int socket, u32 sockAddrPtr, int sockAddrLen) {
|
||||
changeBlockingMode(socket, 0); // Use blocking mode as temporary fix for UNO, since we don't simulate blocking-mode yet
|
||||
int retval = connect(socket, (struct sockaddr*)&saddr.addr, dstlen);
|
||||
if (retval < 0) {
|
||||
inetLastErrno = errno;
|
||||
inetLastErrno = socket_errno;
|
||||
if (connectInProgress(inetLastErrno))
|
||||
hleLogDebug(Log::sceNet, retval, "errno = %d", inetLastErrno);
|
||||
else
|
||||
@@ -593,7 +590,7 @@ static int sceNetInetListen(int socket, int backlog) {
|
||||
|
||||
int retval = listen(socket, (backlog == PSP_NET_INET_SOMAXCONN ? SOMAXCONN : backlog));
|
||||
if (retval < 0) {
|
||||
inetLastErrno = errno;
|
||||
inetLastErrno = socket_errno;
|
||||
return hleLogError(Log::sceNet, retval, "errno = %d", inetLastErrno);
|
||||
}
|
||||
|
||||
@@ -609,7 +606,7 @@ static int sceNetInetAccept(int socket, u32 addrPtr, u32 addrLenPtr) {
|
||||
*srclen = std::min((*srclen) > 0 ? *srclen : 0, static_cast<socklen_t>(sizeof(saddr)));
|
||||
int retval = accept(socket, (struct sockaddr*)&saddr.addr, srclen);
|
||||
if (retval < 0) {
|
||||
inetLastErrno = errno;
|
||||
inetLastErrno = socket_errno;
|
||||
if (inetLastErrno == EAGAIN)
|
||||
hleLogDebug(Log::sceNet, retval, "errno = %d", inetLastErrno);
|
||||
else
|
||||
@@ -671,7 +668,7 @@ static int sceNetInetRecvfrom(int socket, u32 bufferPtr, int len, int flags, u32
|
||||
flgs = convertMSGFlagsPSP2Host(flgs);
|
||||
int retval = recvfrom(socket, (char*)Memory::GetPointer(bufferPtr), len, flgs | MSG_NOSIGNAL, (struct sockaddr*)&saddr.addr, srclen);
|
||||
if (retval < 0) {
|
||||
inetLastErrno = errno;
|
||||
inetLastErrno = socket_errno;
|
||||
if (inetLastErrno == EAGAIN)
|
||||
hleLogDebug(Log::sceNet, retval, "errno = %d", inetLastErrno);
|
||||
else
|
||||
@@ -734,7 +731,7 @@ static int sceNetInetSendto(int socket, u32 bufferPtr, int len, int flags, u32 t
|
||||
saddr.in.sin_addr.s_addr = peer->ip_addr;
|
||||
retval = sendto(socket, (char*)Memory::GetPointer(bufferPtr), len, flgs | MSG_NOSIGNAL, (struct sockaddr*)&saddr.addr, dstlen);
|
||||
if (retval < 0) {
|
||||
DEBUG_LOG(Log::sceNet, "SendTo(BC): Socket error %d", errno);
|
||||
DEBUG_LOG(Log::sceNet, "SendTo(BC): Socket error %d", socket_errno);
|
||||
} else {
|
||||
DEBUG_LOG(Log::sceNet, "SendTo(BC): Address = %s, Port = %d", ip2str(saddr.in.sin_addr).c_str(), ntohs(saddr.in.sin_port));
|
||||
}
|
||||
@@ -761,7 +758,7 @@ static int sceNetInetSendto(int socket, u32 bufferPtr, int len, int flags, u32 t
|
||||
retval = sendto(socket, (char*)Memory::GetPointer(bufferPtr), len, flgs | MSG_NOSIGNAL, (struct sockaddr*)&saddr.addr, dstlen);
|
||||
}
|
||||
if (retval < 0) {
|
||||
inetLastErrno = errno;
|
||||
inetLastErrno = socket_errno;
|
||||
if (inetLastErrno == EAGAIN)
|
||||
hleLogDebug(Log::sceNet, retval, "errno = %d", inetLastErrno);
|
||||
else
|
||||
@@ -907,7 +904,7 @@ static int sceNetInetSendmsg(int socket, u32 msghdrPtr, int flags) {
|
||||
if (retval != SOCKET_ERROR) {
|
||||
DEBUG_LOG(Log::sceNet, "SendMsg(BC): Address = %s, Port = %d", ip2str(saddr.in.sin_addr).c_str(), ntohs(saddr.in.sin_port));
|
||||
} else {
|
||||
DEBUG_LOG(Log::sceNet, "SendMsg(BC): Socket error %d", errno);
|
||||
DEBUG_LOG(Log::sceNet, "SendMsg(BC): Socket error %d", socket_errno);
|
||||
}
|
||||
}
|
||||
// Free Peer Lock
|
||||
@@ -956,7 +953,7 @@ static int sceNetInetSendmsg(int socket, u32 msghdrPtr, int flags) {
|
||||
free(buf);
|
||||
*/
|
||||
if (retval < 0) {
|
||||
inetLastErrno = errno;
|
||||
inetLastErrno = socket_errno;
|
||||
if (inetLastErrno == EAGAIN)
|
||||
hleLogDebug(Log::sceNet, retval, "errno = %d", inetLastErrno);
|
||||
else
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
#include "Common/Net/SocketCompat.h"
|
||||
|
||||
#include <memory>
|
||||
#include <shared_mutex>
|
||||
#include <unordered_map>
|
||||
|
||||
// Using constants instead of numbers for readability reason, since PSP_THREAD_ATTR_KERNEL/USER is located in sceKernelThread.cpp instead of sceKernelThread.h
|
||||
#ifndef PSP_THREAD_ATTR_KERNEL
|
||||
|
||||
+4
-18
@@ -1,27 +1,13 @@
|
||||
// TODO: license
|
||||
|
||||
#if __linux__ || __APPLE__ || defined(__OpenBSD__)
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
// TODO: fixme move Core/Net to Common/Net
|
||||
#include "Common/Net/Resolve.h"
|
||||
#include "Common/Net/SocketCompat.h"
|
||||
#include "Core/Net/InetCommon.h"
|
||||
#include "Common/Data/Text/Parsers.h"
|
||||
|
||||
#include "Common/Serialize/Serializer.h"
|
||||
#include "Core/Config.h"
|
||||
#include "Core/HLE/HLE.h"
|
||||
#include "Core/MemMapHelpers.h"
|
||||
|
||||
#include "Core/HLE/proAdhoc.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <shared_mutex>
|
||||
|
||||
#include "Core/HLE/sceNp.h"
|
||||
|
||||
#if PPSSPP_PLATFORM(WINDOWS)
|
||||
@@ -31,7 +17,7 @@
|
||||
bool getDefaultOutboundSockaddr(sockaddr_in& destSockaddrIn, socklen_t& destSocklen) {
|
||||
auto fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (fd < 0) {
|
||||
ERROR_LOG(Log::sceNet, "getSockAddrFromDefaultSocket: Failed to open socket (%s)", strerror(errno));
|
||||
ERROR_LOG(Log::sceNet, "getSockAddrFromDefaultSocket: Failed to open socket (%s)", strerror(socket_errno));
|
||||
return false;
|
||||
}
|
||||
sockaddr_in connectingTo;
|
||||
@@ -40,12 +26,12 @@ bool getDefaultOutboundSockaddr(sockaddr_in& destSockaddrIn, socklen_t& destSock
|
||||
connectingTo.sin_port = htons(53);
|
||||
connectingTo.sin_addr.s_addr = 0x08080808;
|
||||
if (connect(fd, (sockaddr*) &connectingTo, sizeof(connectingTo)) < 0) {
|
||||
ERROR_LOG(Log::sceNet, "getSockAddrFromDefaultSocket: Failed to connect to Google (%s)", strerror(errno));
|
||||
ERROR_LOG(Log::sceNet, "getSockAddrFromDefaultSocket: Failed to connect to Google (%s)", strerror(socket_errno));
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
if (getsockname(fd, (sockaddr*) &destSockaddrIn, &destSocklen) < 0) {
|
||||
ERROR_LOG(Log::sceNet, "getSockAddrFromDefaultSocket: Failed to execute getsockname (%s)", strerror(errno));
|
||||
ERROR_LOG(Log::sceNet, "getSockAddrFromDefaultSocket: Failed to execute getsockname (%s)", strerror(socket_errno));
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user