Ejemplo n.º 1
0
        SetTcpBufSize(Socket socket, int rcvSize, int sndSize, Communicator communicator)
        {
            if (rcvSize > 0)
            {
                //
                // Try to set the buffer size. The kernel will silently adjust
                // the size to an acceptable value. Then read the size back to
                // get the size that was actually set.
                //
                SetRecvBufferSize(socket, rcvSize);
                int size = GetRecvBufferSize(socket);
                if (size < rcvSize)
                {
                    // Warn if the size that was set is less than the requested size and
                    // we have not already warned.
                    BufSizeWarnInfo winfo = communicator.GetBufSizeWarn(Transport.TCP);
                    if (!winfo.RcvWarn || rcvSize != winfo.RcvSize)
                    {
                        communicator.Logger.Warning(
                            $"TCP receive buffer size: requested size of {rcvSize} adjusted to {size}");
                        communicator.SetRcvBufSizeWarn(Transport.TCP, rcvSize);
                    }
                }
            }

            if (sndSize > 0)
            {
                //
                // Try to set the buffer size. The kernel will silently adjust
                // the size to an acceptable value. Then read the size back to
                // get the size that was actually set.
                //
                SetSendBufferSize(socket, sndSize);
                int size = GetSendBufferSize(socket);
                if (size < sndSize) // Warn if the size that was set is less than the requested size.
                {
                    // Warn if the size that was set is less than the requested size and
                    // we have not already warned.
                    BufSizeWarnInfo winfo = communicator.GetBufSizeWarn(Transport.TCP);
                    if (!winfo.SndWarn || sndSize != winfo.SndSize)
                    {
                        communicator.Logger.Warning(
                            $"TCP send buffer size: requested size of {sndSize} adjusted to {size}");
                        communicator.SetSndBufSizeWarn(Transport.TCP, sndSize);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        internal static void SetBufSize(Socket socket, Communicator communicator, Transport transport)
        {
            int rcvSize = communicator.GetPropertyAsByteSize($"Ice.{transport}.RcvSize") ?? 0;

            if (rcvSize > 0)
            {
                // Try to set the buffer size. The kernel will silently adjust the size to an acceptable value. Then
                // read the size back to get the size that was actually set.
                socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer, rcvSize);
                int size = (int)socket.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer) !;
                if (size < rcvSize)
                {
                    // Warn if the size that was set is less than the requested size and we have not already warned.
                    BufSizeWarnInfo warningInfo = communicator.GetBufSizeWarn(Transport.TCP);
                    if (!warningInfo.RcvWarn || rcvSize != warningInfo.RcvSize)
                    {
                        communicator.Logger.Warning(
                            $"{transport} receive buffer size: requested size of {rcvSize} adjusted to {size}");
                        communicator.SetRcvBufSizeWarn(Transport.TCP, rcvSize);
                    }
                }
            }

            int sndSize = communicator.GetPropertyAsByteSize($"Ice.{transport}.SndSize") ?? 0;

            if (sndSize > 0)
            {
                // Try to set the buffer size. The kernel will silently adjust the size to an acceptable value. Then
                // read the size back to get the size that was actually set.
                socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendBuffer, sndSize);
                int size = (int)socket.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendBuffer) !;
                if (size < sndSize) // Warn if the size that was set is less than the requested size.
                {
                    // Warn if the size that was set is less than the requested size and we have not already warned.
                    BufSizeWarnInfo warningInfo = communicator.GetBufSizeWarn(Transport.TCP);
                    if (!warningInfo.SndWarn || sndSize != warningInfo.SndSize)
                    {
                        communicator.Logger.Warning(
                            $"{transport} send buffer size: requested size of {sndSize} adjusted to {size}");
                        communicator.SetSndBufSizeWarn(Transport.TCP, sndSize);
                    }
                }
            }
        }