Change socket's MSS based on PSP_ADHOC_PTP_MSS

This commit is contained in:
ANR2ME 2020-11-16 18:59:32 +07:00
parent f30c61849b
commit 38d887ce88
3 changed files with 19 additions and 0 deletions

View File

@ -1918,6 +1918,11 @@ int setSockBufferSize(int sock, int opt, int size) { // opt = SO_RCVBUF/SO_SNDBU
return setsockopt(sock, SOL_SOCKET, opt, (char *)&n, sizeof(n));
}
int setSockMSS(int sock, int size) {
int mss = size; // 1460;
return setsockopt(sock, IPPROTO_TCP, TCP_MAXSEG, (char*)&mss, sizeof(mss));
}
int setSockTimeout(int sock, int opt, unsigned long timeout_usec) { // opt = SO_SNDTIMEO/SO_RCVTIMEO
if (timeout_usec > 0 && timeout_usec < minSocketTimeoutUS) timeout_usec = minSocketTimeoutUS; // Override timeout for high latency multiplayer
#if defined(_WIN32)

View File

@ -1287,6 +1287,11 @@ int getSockBufferSize(int sock, int opt);
*/
int setSockBufferSize(int sock, int opt, int size);
/*
* Set TCP Socket Maximum Segment Size (default is 1460 on 1500 MTU)
*/
int setSockMSS(int sock, int size);
/*
* Set Socket TimeOut (opt = SO_SNDTIMEO/SO_RCVTIMEO)
*/

View File

@ -3099,6 +3099,9 @@ static int sceNetAdhocPtpOpen(const char *srcmac, int sport, const char *dstmac,
// Valid Socket produced
if (tcpsocket > 0) {
// Change socket MSS
setSockMSS(tcpsocket, PSP_ADHOC_PTP_MSS);
// Change socket buffer size to be consistent on all platforms.
setSockBufferSize(tcpsocket, SO_SNDBUF, bufsize*2); //PSP_ADHOC_PTP_MFS
setSockBufferSize(tcpsocket, SO_RCVBUF, bufsize*10); //PSP_ADHOC_PTP_MFS*10
@ -3269,6 +3272,9 @@ int AcceptPtpSocket(int ptpId, int newsocket, sockaddr_in& peeraddr, SceNetEther
// Copy Socket Descriptor to Structure
internal->data.ptp.id = newsocket;
// Change socket MSS
setSockMSS(newsocket, PSP_ADHOC_PTP_MSS);
// Set Default Buffer Size or inherit the size?
internal->buffer_size = socket->buffer_size;
setSockBufferSize(newsocket, SO_SNDBUF, internal->buffer_size*2); //PSP_ADHOC_PTP_MSS
@ -3641,6 +3647,9 @@ static int sceNetAdhocPtpListen(const char *srcmac, int sport, int bufsize, int
// Valid Socket produced
if (tcpsocket > 0) {
// Change socket MSS
setSockMSS(tcpsocket, PSP_ADHOC_PTP_MSS);
// Change socket buffer size to be consistent on all platforms.
setSockBufferSize(tcpsocket, SO_SNDBUF, bufsize*2); //PSP_ADHOC_PTP_MFS
setSockBufferSize(tcpsocket, SO_RCVBUF, bufsize*10); //PSP_ADHOC_PTP_MFS*10