MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / nw_SetSocketOptions

Function nw_SetSocketOptions

networking/networking.cpp:672–730  ·  view source on GitHub ↗

Sets the size of buffers

Source from the content-addressed store, hash-verified

670
671// Sets the size of buffers
672void nw_SetSocketOptions(SOCKET sock) {
673 int broadcast;
674 int ret, cursize, bufsize, trysize;
675 socklen_t cursizesize;
676
677 // Set the mode of the socket to allow broadcasting. We need to be able to broadcast
678 // when a game is searched for in IPX mode.
679 broadcast = 1;
680 setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (LPSTR)&broadcast, sizeof(broadcast));
681 setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (LPSTR)&broadcast, sizeof(broadcast));
682
683 int error = make_nonblocking(sock);
684 if (error == SOCKET_ERROR) {
685 mprintf(0, "Unable to make socket non-blocking -- %d", WSAGetLastError());
686 }
687
688 // try and increase the size of my receive buffer
689 bufsize = iMaxReceiveBufsize;
690
691 // set the current size of the receive buffer
692 cursizesize = sizeof(int);
693 getsockopt(sock, SOL_SOCKET, SO_RCVBUF, (LPSTR)&cursize, &cursizesize);
694 for (trysize = bufsize; trysize >= cursize; trysize >>= 1) {
695 ret = setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (LPSTR)&trysize, sizeof(trysize));
696 if (ret == SOCKET_ERROR) {
697 int wserr;
698
699 wserr = WSAGetLastError();
700 if ((wserr == WSAENOPROTOOPT) || (wserr == WSAEINVAL))
701 break;
702
703 } else
704 break;
705 }
706 getsockopt(sock, SOL_SOCKET, SO_RCVBUF, (LPSTR)&cursize, &cursizesize);
707 mprintf(0, "Receive buffer set to %d\n", cursize);
708 /*
709 // set the current size of the send buffer
710 bufsize = MAX_RECEIVE_BUFSIZE/4;
711 cursizesize = sizeof(int);
712 getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (LPSTR)&cursize, &cursizesize);
713 for ( trysize = bufsize; trysize >= cursize; trysize >>= 1 )
714 {
715 ret = setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (LPSTR)&trysize, sizeof(trysize));
716 if ( ret == SOCKET_ERROR )
717 {
718 int wserr;
719
720 wserr = WSAGetLastError();
721 if ( (wserr == WSAENOPROTOOPT) || (wserr == WSAEINVAL) )
722 break;
723 }
724 else
725 break;
726 }
727 getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (LPSTR)&cursize, &cursizesize);
728 mprintf(0, "Send buffer set to %d\n", cursize);
729 */

Callers 1

nw_InitSocketsFunction · 0.85

Calls 1

make_nonblockingFunction · 0.85

Tested by

no test coverage detected