mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-08 20:16:27 +02:00
Merge pull request #13470 from ANR2ME/adhoc_socket
Adhoc Socket - An attempt to improve connection stability that was broken recently.
This commit is contained in:
2 files changed
+41
-22
No files matched your search
+1
-1
@@ -712,7 +712,7 @@ static void sceNetEtherStrton(u32 bufferPtr, u32 macPtr) {
|
||||
|
||||
// Write static data since we don't actually manage any memory for sceNet* yet.
|
||||
static int sceNetGetMallocStat(u32 statPtr) {
|
||||
DEBUG_LOG(SCENET, "UNTESTED sceNetGetMallocStat(%x)", statPtr);
|
||||
VERBOSE_LOG(SCENET, "UNTESTED sceNetGetMallocStat(%x)", statPtr);
|
||||
if(Memory::IsValidAddress(statPtr))
|
||||
Memory::WriteStruct(statPtr, &netMallocStat);
|
||||
else
|
||||
|
||||
+40
-21
@@ -1005,11 +1005,12 @@ int sceNetAdhocctlGetState(u32 ptrToStatus) {
|
||||
if (!Memory::IsValidAddress(ptrToStatus))
|
||||
return ERROR_NET_ADHOCCTL_INVALID_ARG;
|
||||
|
||||
// Return Thread Status
|
||||
Memory::Write_U32(NetAdhocctl_GetState(), ptrToStatus);
|
||||
// Return Success
|
||||
return hleLogSuccessVerboseI(SCENET, 0);
|
||||
int state = NetAdhocctl_GetState();
|
||||
// Output Adhocctl State
|
||||
Memory::Write_U32(state, ptrToStatus);
|
||||
|
||||
// Return Success
|
||||
return hleLogSuccessVerboseI(SCENET, 0, "state = %d", state);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1051,9 +1052,12 @@ static int sceNetAdhocPdpCreate(const char *mac, int port, int bufferSize, u32 u
|
||||
int usocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
// Valid Socket produced
|
||||
if (usocket != INVALID_SOCKET) {
|
||||
// Change socket buffer size, unlike TCP, UDP need to be Received in full size to prevent leftover data getting discarded/lost, so we need to use the exact buffer size the game want/expects.
|
||||
setSockBufferSize(usocket, SO_SNDBUF, bufferSize);
|
||||
setSockBufferSize(usocket, SO_RCVBUF, bufferSize);
|
||||
// Change socket buffer size.
|
||||
int pdpbufsize = std::max(bufferSize, PSP_ADHOC_PDP_MFS); //bufferSize*10;
|
||||
// Send Buffer should be smaller than Recv Buffer to prevent faster device from flooding slower device too much.
|
||||
setSockBufferSize(usocket, SO_SNDBUF, pdpbufsize);
|
||||
// Recv Buffer should be equal or larger than Send Buffer. Using larger Recv Buffer might helped reduces dropped packets during a slowdown, but too large may cause slow performance on Warriors Orochi 2.
|
||||
setSockBufferSize(usocket, SO_RCVBUF, pdpbufsize*10);
|
||||
|
||||
// Enable KeepAlive
|
||||
setSockKeepAlive(usocket, true);
|
||||
@@ -2114,11 +2118,14 @@ static u32 sceNetAdhocctlDisconnect() {
|
||||
}
|
||||
|
||||
static u32 sceNetAdhocctlDelHandler(u32 handlerID) {
|
||||
if (!netAdhocctlInited)
|
||||
return hleLogError(SCENET, ERROR_NET_ADHOCCTL_NOT_INITIALIZED, "adhocctl not initialized");
|
||||
|
||||
if (adhocctlHandlers.find(handlerID) != adhocctlHandlers.end()) {
|
||||
adhocctlHandlers.erase(handlerID);
|
||||
WARN_LOG(SCENET, "UNTESTED sceNetAdhocctlDelHandler(%d)", handlerID);
|
||||
INFO_LOG(SCENET, "sceNetAdhocctlDelHandler(%d)", handlerID);
|
||||
} else {
|
||||
ERROR_LOG(SCENET, "UNTESTED sceNetAdhocctlDelHandler(%d): Invalid Handler ID", handlerID);
|
||||
WARN_LOG(SCENET, "sceNetAdhocctlDelHandler(%d): Invalid Handler ID", handlerID);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -2263,7 +2270,7 @@ int sceNetAdhocctlGetPeerInfo(const char *mac, int size, u32 peerInfoAddr) {
|
||||
SceNetAdhocctlNickname nickname;
|
||||
|
||||
truncate_cpy((char*)&nickname.data, ADHOCCTL_NICKNAME_LEN, g_Config.sNickName.c_str());
|
||||
//buf->next = 0;
|
||||
buf->next = 0;
|
||||
buf->nickname = nickname;
|
||||
buf->nickname.data[ADHOCCTL_NICKNAME_LEN - 1] = 0; // last char need to be null-terminated char
|
||||
buf->mac_addr = *maddr;
|
||||
@@ -2603,7 +2610,7 @@ int sceNetAdhocTerm() {
|
||||
}
|
||||
|
||||
static int sceNetAdhocGetPdpStat(u32 structSize, u32 structAddr) {
|
||||
VERBOSE_LOG(SCENET, "UNTESTED sceNetAdhocGetPdpStat(%08x, %08x) at %08x", structSize, structAddr, currentMIPS->pc);
|
||||
VERBOSE_LOG(SCENET, "sceNetAdhocGetPdpStat(%08x, %08x) at %08x", structSize, structAddr, currentMIPS->pc);
|
||||
|
||||
// Library is initialized
|
||||
if (netAdhocInited)
|
||||
@@ -2621,6 +2628,7 @@ static int sceNetAdhocGetPdpStat(u32 structSize, u32 structAddr) {
|
||||
{
|
||||
// Return Required Size
|
||||
*buflen = sizeof(SceNetAdhocPdpStat) * socketcount;
|
||||
VERBOSE_LOG(SCENET, "PDP Socket Count: %d", socketcount);
|
||||
|
||||
// Success
|
||||
return 0;
|
||||
@@ -2648,8 +2656,12 @@ static int sceNetAdhocGetPdpStat(u32 structSize, u32 structAddr) {
|
||||
// Fix Client View Socket ID
|
||||
buf[i].id = j + 1;
|
||||
|
||||
// Set available bytes to be received
|
||||
buf[i].rcv_sb_cc = getAvailToRecv(sock->data.pdp.id);
|
||||
// Set available bytes to be received. With FIOREAD There might be lingering 1 byte in recv buffer when remote peer's socket got closed
|
||||
u32 avail = 0;
|
||||
if (IsSocketReady(sock->data.pdp.id, true, false) > 0) {
|
||||
avail = getAvailToRecv(sock->data.pdp.id);
|
||||
}
|
||||
buf[i].rcv_sb_cc = avail;
|
||||
|
||||
// Write End of List Reference
|
||||
buf[i].next = 0;
|
||||
@@ -2658,6 +2670,8 @@ static int sceNetAdhocGetPdpStat(u32 structSize, u32 structAddr) {
|
||||
if (i > 0)
|
||||
buf[i - 1].next = structAddr + (i * sizeof(SceNetAdhocPdpStat));
|
||||
|
||||
VERBOSE_LOG(SCENET, "PDP Socket Id: %d, LPort: %d, RecvSbCC: %d", buf[i].id, buf[i].lport, buf[i].rcv_sb_cc);
|
||||
|
||||
// Increment Counter
|
||||
i++;
|
||||
}
|
||||
@@ -2703,6 +2717,7 @@ static int sceNetAdhocGetPtpStat(u32 structSize, u32 structAddr) {
|
||||
if (buflen != NULL && buf == NULL) {
|
||||
// Return Required Size
|
||||
*buflen = sizeof(SceNetAdhocPtpStat) * socketcount;
|
||||
VERBOSE_LOG(SCENET, "PTP Socket Count: %d", socketcount);
|
||||
|
||||
// Success
|
||||
return 0;
|
||||
@@ -2737,6 +2752,8 @@ static int sceNetAdhocGetPtpStat(u32 structSize, u32 structAddr) {
|
||||
// Link previous Element to this one
|
||||
if (i > 0)
|
||||
buf[i - 1].next = structAddr + (i * sizeof(SceNetAdhocPtpStat));
|
||||
|
||||
VERBOSE_LOG(SCENET, "PTP Socket Id: %d, LPort: %d, RecvSbCC: %d", buf[i].id, buf[i].lport, buf[i].rcv_sb_cc);
|
||||
|
||||
// Increment Counter
|
||||
i++;
|
||||
@@ -2801,9 +2818,10 @@ static int sceNetAdhocPtpOpen(const char *srcmac, int sport, const char *dstmac,
|
||||
|
||||
// Valid Socket produced
|
||||
if (tcpsocket > 0) {
|
||||
// Change socket buffer size when necessary
|
||||
if (getSockBufferSize(tcpsocket, SO_SNDBUF) < bufsize) setSockBufferSize(tcpsocket, SO_SNDBUF, bufsize);
|
||||
if (getSockBufferSize(tcpsocket, SO_RCVBUF) < bufsize) setSockBufferSize(tcpsocket, SO_RCVBUF, bufsize);
|
||||
// Change socket buffer size to be consistent on all platforms.
|
||||
int ptpbufsize = std::max(bufsize, PSP_ADHOC_PTP_MSS);
|
||||
setSockBufferSize(tcpsocket, SO_SNDBUF, ptpbufsize);
|
||||
setSockBufferSize(tcpsocket, SO_RCVBUF, ptpbufsize*10);
|
||||
|
||||
// Enable KeepAlive
|
||||
setSockKeepAlive(tcpsocket, true, rexmt_int / 1000000L, rexmt_cnt);
|
||||
@@ -2962,8 +2980,8 @@ int AcceptPtpSocket(int ptpId, int newsocket, sockaddr_in& peeraddr, SceNetEther
|
||||
internal->data.ptp.id = newsocket;
|
||||
|
||||
// Set Default Buffer Size
|
||||
if (getSockBufferSize(newsocket, SO_RCVBUF) < PSP_ADHOC_PTP_MSS) setSockBufferSize(newsocket, SO_RCVBUF, PSP_ADHOC_PTP_MSS);
|
||||
if (getSockBufferSize(newsocket, SO_SNDBUF) < PSP_ADHOC_PTP_MSS) setSockBufferSize(newsocket, SO_SNDBUF, PSP_ADHOC_PTP_MSS);
|
||||
setSockBufferSize(newsocket, SO_SNDBUF, PSP_ADHOC_PTP_MSS);
|
||||
setSockBufferSize(newsocket, SO_RCVBUF, PSP_ADHOC_PTP_MSS*10);
|
||||
|
||||
// Copy Local Address Data to Structure
|
||||
getLocalMac(&internal->data.ptp.laddr);
|
||||
@@ -3306,9 +3324,10 @@ static int sceNetAdhocPtpListen(const char *srcmac, int sport, int bufsize, int
|
||||
|
||||
// Valid Socket produced
|
||||
if (tcpsocket > 0) {
|
||||
// Change socket buffer size when necessary
|
||||
if (getSockBufferSize(tcpsocket, SO_SNDBUF) < bufsize) setSockBufferSize(tcpsocket, SO_SNDBUF, bufsize);
|
||||
if (getSockBufferSize(tcpsocket, SO_RCVBUF) < bufsize) setSockBufferSize(tcpsocket, SO_RCVBUF, bufsize);
|
||||
// Change socket buffer size to be consistent on all platforms.
|
||||
int ptpbufsize = std::max(bufsize, PSP_ADHOC_PTP_MSS);
|
||||
setSockBufferSize(tcpsocket, SO_SNDBUF, ptpbufsize);
|
||||
setSockBufferSize(tcpsocket, SO_RCVBUF, ptpbufsize*10);
|
||||
|
||||
// Enable KeepAlive
|
||||
setSockKeepAlive(tcpsocket, true, rexmt_int / 1000000L, rexmt_cnt);
|
||||
|
||||
Reference in new issue
Block a user